However sometimes it is just convenient to have a variable that you can access from anywhere in your flash movie, and this is how you do it.
First of all make a folder called testGlobals for your project, all your files will go in this folder.
Now we are going to produce a package that holds our variables
Then, open up notepad and paste the following code in:
package
{
public class globals
{
public static var data:Object = {};
public static var varHello:String = "World!";
}
}
Save this code in the folder as globals.asCreate a new flash file (as 3.0) create a layer called 'actions' and another one called 'content'
In the first frame we want to import the package and produce some variables, so under actions put this code:
import globals; globals.data.var1 = "I am variable one"; globals.data.var2 = "variable one sucks eggs"; globals.data.var3 = "variable two is my mother"; gotoAndPlay(2);
In the next frame under the content layer put four buttons with the instance names 'btn_var1', 'btn_var2', 'btn_var3' & 'btn_varhello' respectively, along with a textbox called 'txt_main.'
Under actions put this code:
btn_var1.addEventListener(MouseEvent.MOUSE_OVER, f1);
btn_var2.addEventListener(MouseEvent.MOUSE_OVER, f2);
btn_var3.addEventListener(MouseEvent.MOUSE_OVER, f3);
btn_hello.addEventListener(MouseEvent.MOUSE_OVER, f4);
function f1(e:MouseEvent):void {txt_main.text = globals.data.var1;}
function f2(e:MouseEvent):void {txt_main.text = globals.data.var2;}
function f3(e:MouseEvent):void {txt_main.text = globals.data.var3;}
function f4(e:MouseEvent):void {txt_main.text = globals.varHello;}
stop();
Now when you press ctrl+enter your movie should run and the text should change to the variables from frame 1 when you move your mouse over each button.
Remember these variables can come from anywhere and run as long as the movie does, the latest version I have loads data from an XML file and passes the variables between movieclips on the stage.
Hope someone finds this as useful to know as I did














