Reputation: 3254
Ok, I want to be able to access certain variables from anywhere within a Flash file or Flash files loaded by that Flash file. How do I do it? I don't know what classes are, I don't want to learn what classes are, I don't want to import anything, I just want to be able to initialize and access certain variables from anywhere.
Thanks :)
Upvotes: 1
Views: 20600
Reputation: 10235
Well, there is no more _global like there was in as2 - and since you don't want to use classes you can't use static variables (I can explain these if you're interested). So you're left with using variables on the root. For example, you can define a variable on the main timeline like this:
var myGlobal:Number = 100;
If you want to access it elsewhere ... that is, on the timeline of other movieClips you need to say:
MovieClip(root).myGlobal;
Which if you've never seen before probably looks absurd. Basically we are casting the root to a movieClip to give us access to its dynamic properties. Luckily, you can set it up so you don't have to keep writing MovieClip(root) all the time:
// do this on any movieClip where you want to access globals
var global:MovieClip = MovieClip(root);
trace(global.myGlobal);
So in the end its just one extra line of code to get the functionality back to the way it was in AS2.
Edit
go into the new movieClip and add this to your actions :
var global:MovieClip = MovieClip(root); trace(global.myGlobal);
test your movie
Upvotes: 8