Ste*_*eve 2 actionscript actionscript-3
我是ActionScript的新手,请原谅我,如果这是一个愚蠢的问题.
所以,我创建了一个类,扩展了sprite类,现在在构造函数中,我试图设置从DisplayObject继承的Sprite的width和height属性.但是,在我设置this.width和this.height并打印值后,我得到0.
到底他妈发生了什么?当我查看livedocs时,我看到DisplayObject的宽度和高度被列为公共属性.我已经能够直接实例化一个Sprite,并在实例化之后设置宽度和高度,所以我不明白.
package {
import flash.display.*;
public class ScrollBar extends Sprite {
public function ScrollBar(width:Number, height:Number) {
trace(width + "x" + height);
this.width = width;
this.height = height;
trace(this.width + "x" + this.height);
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
20x400
0x0
Run Code Online (Sandbox Code Playgroud)