How I can change a value of from a variable that is in the main timeline from other timeline?

How I can change a value of from a variable that is in the main timeline from other timeline?

In AS2 was easy to change a value from a variable that was in other timelines. Now I can't do it the old way!

Basically what I need is to change a value from a variable that is in the main timeline, from another timeline.


Main timeline:

var totalA:int = 0; 

Other timeline, after adding the eventListener to the function:


So it doesn't work. Can anybody explain why? Thanks

Flash Player 10 real-time audio playback


Inherited Classes and Dynamic Views in PureMVC (AS3)
Well...i solved it..
Flash Player deep linking problem
Created a MovieClip with the path:.
AS3 DAE Augmented Reality PaperVision 3D
var A_mc:MovieClip = MovieClip(this.parent.parent); 
Then i referenced it:.
How do I animate a sprite?

Why check boxes do not stayed checked as you scroll using flex?

Adobe AIR detect if Running in ADL?


A better solution would be to use a globals class.

you reference it from all your classes and can set variables in it that are accessible everywhere.. take a look at . Global Object is a Singleton that lets you store dynamic variables in a globally accessible location within your AS3 application.

This enables developers to accomplish things like self registering visual components, global events and event listeners.


I would also add that if you're interested in OO practices I would not access that variable directly.. You can setup a function in the Singleton mentioned by Josh above.

It helps to encapsulate that variable inside the function.

You should name your function something meaningful, for example:.
function addToTotal (int amount) :void 
This way all the function for figuring out the total is encapulated within the Singleton and the function.

If somehow the way you need to total changes later or if you need to change the varialbe, the change is limited to the function..


It all depends on how you would like to do things, but a Singleton class for any global variables you may want to maintain is probably the best course.

If you are not familiar with the singleton design pattern, merely stick to casting it as .
//Example - Would move the parent movie clip 5 pixels to the right. 

//You must cast it because there is no way for the compiler to know what the asset.

MovieClip(parent).x = 5;

82 out of 100 based on 42 user ratings 1342 reviews