views:

647

answers:

2

I need to set various variables depending on what a user clicks. Those variables then need to be accessed by other movieclips.

The problem is that at the time of clicking, those "other movieclips" don't exist on the timeline yet.

What I have done is assign the variable to the parent movieclip, although I guess I could just as easily set them to the root. Then I would grab that value when the relevant clip is initiated.

// set - works
MovieClip(parent).aMovieClip.someVariable = myVal;

// get? - doesn't work
getVar = MovieClip(parent).aMovieClip.someVariable;

the above doesn't work - what is the correct way to get that value whenever I need it. I guess it's a case of getting and setting global variables

A: 

Answer copied from:

http://www.experts-exchange.com/Software/Photos%5FGraphics/Web%5FGraphics/Macromedia%5FFlash/Q%5F22997849.html

with AS3.0, concept of _global variables have been removed completely. although, an external class can be used to act as exactly AS2.0 _global

if you implement it properly, you should get desired results. here are the details:

1. create a AS3.0 class with name "glo.as", and save it in the same folder where FLA resides.

2. Just copy paste the following actionscript in "glo.as" class file.

////////////
package
{
      //Class will act as _global object of AS2
      // Static variable "bal" of this class is going to store "varibales, instance's/object's referece to be used by any other class or displayObject/movieClip
      // sample code to store a reference of a movieClip
      //
      // glo.bal.myMovie = this.new_mc;
      //
      //
      public class glo
      {
            public static  var bal:Object = new Object();
      }
}
//////

3. Now just create any global variable anywhere by just using "glo.bal" instead of "_global"

for example:

glo.bal.myGlobalVariable = 22;

it will be accessible everywhere in the scope of your FLA and other classes.


Credit Aneesh Chopra http://www.experts-exchange.com/M%5F3631521.html

ed209
A: 

You could use proxies to take care of the values while the objects are still inexistent. These would only need get notified when the MovieClips get accessible in order to amend them with the pending values.

Theo.T