public class MyClass extends MovieClip {
public function MyClass():void {
my_mc.addEventListener(MouseEvent.CLICK, action);
}
If my_mc
is a MovieClip on the stage of MyClass, you may be trying to access it too early. Constructor code generally executes before the first frame is drawn, so you need to wait for that drawing to take place by listening for Event.ADDED_TO_STAGE
:
public class MyClass extends MovieClip {
public function MyClass():void {
if(stage) {
init();
} else {
addEventListener(Event.ADDED_TO_STAGE,init);
}
}
private function init(e:Event = null):void {
if(e) removeEventListener(Event.ADDED_TO_STAGE,init);
stage.my_mc.addEventListener(MouseEvent.CLICK, action);
}
private function action(e:MouseEvent):void {
trace("cliked");
}
}