Question

I'm initializing symbols in my timeline, and trying to access the variables within those symbols, but they return 0 or undefined even though I set the variables in the symbol's timeline. For some reason the variables haven't been set yet, though the main timeline can see that they exist. How do I make the program wait until the variables have been set?

No correct solution

OTHER TIPS

Best practice to work with classes, not coding in timeline and frames of MovieClip. I assume you have MovieClip from designer and you want inject some logic to the specific frame. There are many options.

Events

You can trigger event in the specific frame, and you work in normal way (with classes and class members).

//Frame code
import flash.events.Event;

this.dispatchEvent(new Event("IntroDidFinish", true, true));
stop();

//Somewhere in class
myContainer.addEventListener("IntroDidFinish", onIntroFinish, false, 0, true);

function onIntroFinish(e: Event):void{
    //Do your stuff
}

Events help you decouple logic from the design(predefined complex MovieClip, etc.)

Waiting for initialisation

As MovieClip reaches some frame, you should wait extra time for initialisation. Thats why 99.9% of AS3 developers don't like MovieClip as holder for any critical data or logic. It means if you call myMovieClip.goToAndStop(8); you can't get myMovieClip.someValue declared in 8 frame after goTo operation. If you still want to go with such approach, easiest solution for you will be Event.ENTER_FRAME, after goTo subscribe for ENTER_FRAME event, for only one update, and do your work ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top