嘿,窥视!我有这个页脚图像,我想与舞台底部对齐,但是我遇到了错误。
如您所见,我在构造函数中有一个 ADDED_TO_STAGE 侦听器。
package src.display{
import flash.text.*;
import flash.display.*;
import flash.geom.Matrix;
import flash.events.Event;
public class Frame extends Sprite {
private var footer:Sprite = new Sprite();
// ☼ ------ Constructor
public function Frame():void {
this.addEventListener(Event.ADDED_TO_STAGE, tracer);
}
public function tracer(event:Event) {
trace("Frame added to stage --- √"+"\r");
this.removeEventListener(Event.ADDED_TO_STAGE, tracer);
}
// ☼ ------ Init
public function init():void {
footer.graphics.beginFill(0x000);
footer.graphics.drawRect(0,0,800,56);
footer.graphics.endFill();
footer.y = (stage.height - footer.height); // <-- This Line
addChild(footer);
}
}
}
如果我注释掉第 26 行,这部电影将正常工作(但我当然不希望 Y 为 0):
footer.y = (stage.height - footer.height);
这是我得到的输出窗口中的错误:
TypeError:错误 #1009:无法访问空对象引用的属性或方法。在 src.display::Frame/init()[/Users/lgaban/Projects/Player/src/display/Frame.as:26]
更新
回答了我自己的问题,在这里修复