Please note that ExpatTech is close for the Christmas and New Year holidays. We will re-open on 2nd January 2024.

ExpatTech Techblog

Peter Todd 2010.08.03. 14:09

Flash Cookbook - Tricks - Global variables

Sometimes it's useful to use global variables. In AS3 it's quite easy: you create a class and add static variables to it.

package
{
    public class Vars
    {
        public static var value:int = 0;
    }
}

To reach it from anywhere import the class (import Vars;) if needed and done.

trace(Vars.value);
Vars.value= 10;
trace(Vars.value);

Output:

0

10

(reference tag: singleton)