我在课堂上很新。下面是创建一个 StageObject 类的尝试,我可以设置宽度、高度、xy 和背景颜色。
package
{
import flash.display.MovieClip;
public class StageObjects extends MovieClip
{
public function StageObjects()
{
// constructor code
}
public function setUpStageObject(w:int, h:int, X:int, Y:int, color:Number):void
{
this.width = w;
this.height = h;
this.x = X;
this.y = Y;
this.cacheAsBitmap = true;
this.graphics.beginFill(color,1);
this.graphics.drawRect(0,0,w,h);
this.graphics.endFill();
this.opaqueBackground = color;
trace("parameters: " + w + " - " + h + " - " + X + " - " + Y + " - " + color);
}
/*~~~ adjust position and scale functions ~~~*/
public function adjustXY(ch:Object, par:Object):void
{
var w = par.width;
var h = par.height;
ch.x = par.x + (w - ch.width) / 2;
ch.y = par.y + (h - ch.height) / 2;
}
public function adjustWH(ch:Object, par:Object):void
{
var w = par.width;
var h = par.height;
}
}
}
在主时间线(Flash)中,我这样做:
var titleBkg:StageObjects = new StageObjects();
titleBkg.setUpStageObject(imageBoxWidth, titleBkgHeight, -1, imageBoxHeight +1, 0x589199);
this.addChild(titleBkg);
但它没有出现。我有没有提到“这个”。错误的?