请考虑以下代码:为什么我无法跟踪点击事件?
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.display.*;
[SWF(width="1000",height="600")]
public class vanCopperTes extends Sprite
{
public function vanCopperTes()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
//黄色矩形
graphics.beginFill(0xFFCC00,.5);
graphics.drawRect(0,0,200,200);
graphics.endFill();
addEventListener(MouseEvent.CLICK,onClick);
trace("this.numChilder",numChildren);// output: 0
}
private function onClick(e:MouseEvent):void
{
trace("Click");
}
}
}
答案 0 :(得分:0)
尝试将eventlistener更改为:
stage.addEventListener(MouseEvent.CLICK,onClick);
这适用于整个.swf。如果你想让它只是黄色方块,你需要将它作为一个单独的精灵添加并将监听器附加到它。