0

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")
    }
}
sohel khalifa
  • 5,602
  • 3
  • 34
  • 46
  • 1
    You need more detail. What is the error you're receiving? One thing I spot right away is you're missing `()` after instantiating `introScene`. Should be `introClass = new introScene();` – BadFeelingAboutThis Oct 23 '12 at 03:47
  • 1
    Also, your passing a display object to your `introLoaded` function, which is expecting an `Event` object presumably – BadFeelingAboutThis Oct 23 '12 at 03:48
  • There is no error it does nothing. I added introScene to the stage from library. And my goal was if the movieclip symbol introScene reached frame 120. Than another listener will be activated. – user1492440 Oct 23 '12 at 03:54
  • if i do introClass.addEventListener(Event.ENTER_FRAME, introLoaded); instead of introClass.addEventListener(Event, introLoaded); than it works but thats not the right way. – user1492440 Oct 23 '12 at 04:16

1 Answers1

0

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.

Valentin Simonov
  • 1,768
  • 10
  • 14
  • is there another way? or something different than ENTER_FRAME because its only good for things that got loaders and stuff so you can see progress. – user1492440 Oct 23 '12 at 15:20
  • With ENTER_FRAME the code does exactly what you want. Otherwise you can dispatch a custom event at frame 120 `dispatchEvent(new Event("bla"));` and listen for that `introClass.addEventListener("bla", introLoaded);`. – Valentin Simonov Oct 23 '12 at 15:40