I have three dynamically created MCs on stage and when I press on first one I want to initialize ENTER_FRAME function , but Im getting this error:
TypeError: Error #2007: Parameter listener must be non-null.
at flash.events::EventDispatcher/addEventListener()
at dynamic_buttons_fla::MainTimeline/onUp()
Here is my code:
[LEFT]
var button:Array = new Array();
for (var i:int = 0; i < 3; i++)
{
var btn:MovieClip = new Btn();
btn.y = i*(btn.height + 2);
btn.x = 0;
button* = btn;
addChild(btn);
btn.addEventListener(MouseEvent.MOUSE_UP, onUp);
}
function onUp(e:MouseEvent):void{
switch (e.currentTarget){
case button[0] :
addEventListener(Event.ENTER_FRAME, onLoop); // THIS IS CAUSING ERROR
function onLoop(e:Event):void{
trace("loop");
}
break;
case button[1] :
trace("b2");
break;
case button[2] :
trace("b3");
break;
}
}
Why i’m getting this Parameter listener must be non-null. I don’t understand which listener could be null. Buttons? But they can’t be null coz they are listening to other events apart from ENTER_FRAME.
How can I trigger ENTER_FRAME function in this case?
Thank you
[/LEFT]