stage.addEventListener包里面? [英] stage.addEventListener inside a package?
本文介绍了stage.addEventListener包里面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图做这样的事情:
package com.clicker{
import flash.display.*;
import flash.events.MouseEvent;
public class Stager extends MovieClip {
public function clicker():void {
stage.addEventListener(MouseEvent.CLICK, do_stage);
}
function do_stage(e:MouseEvent):void {
trace("stage clicked");
}
}
}
不过,我得到了1009的错误。
But, I get the 1009 error.
当我这样做:
import com.clicker.*;
var test:Stager = new Stager();
test.clicker();
addChild(test);
请帮助我。非常感谢你提前和节日快乐。
Please help me. Thank you very much in advance, and Happy Holidays.
推荐答案
阶段访问只有当你的组件添加到舞台上。如果你想知道的话,你可以使用ADDED_TO_STAGE事件。
stage is accessible only when your component is added to the stage. If you want to know it, you can use the ADDED_TO_STAGE event.
所以,你可以这样做:
package com.clicker{
import flash.display.*;
import flash.events.*;
public class Stager extends MovieClip {
public function clicker():void {
addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
stage.addEventListener(MouseEvent.CLICK, do_stage);
}
function do_stage(e:MouseEvent):void {
trace("stage clicked");
}
}
}
这篇关于stage.addEventListener包里面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文