Search code examples
actionscript-3flashif-statementaddchild

Why does this not work? Flash As3, if added child is at frame something?


This is my code help me please its really frustrating! I have a movieclip in my library and added it with AS3 to the stage. That part was easy. But now i want to control that movieclip. If introScene "introClass" Reaches frame 120 then i want to remove that movieclip and replace it with another one. The problem is the if statement doesn't work. I also tried getChildByName but that didn't work either.

var introClass = new introScene;
addChild(introClass);
introClass.x = 640;
introClass.y = 387;

/*******INTRO-SCENE*******/

introClass.addEventListener(Event, introLoaded);

function introLoaded(event):void{

    if(introClass == 120 ){
        trace("Frame Reached")
    }
}

i tried this and this also doesn't work :(

introClass.addEventListener(Event, introLoaded);

function introLoaded (e:Event):void{

    if(MovieClip(introClass).currentFrame == 120){
        trace("120 complete")
    }
}

Solution

  • This is wrong statement:

    introClass.addEventListener(Event, introLoaded);
    

    You need to pass a string to addEventListener. Event type name is converted to a string at runtime which adds a event listener to "flash.events.Event" or something. And your object obviously doesn't have this event. You need to use Event.ENTER_FRAME for example.