3 Replies Latest reply on Feb 15, 2012 10:38 AM by nfallon55

    global variable

    nfallon55 Level 1



      Is there such a thing as a global variable that is available to all parts of the application?



        • 1. Re: global variable
          drkstr_1 Level 4

          You can create a global function, or create a public static property on a class (Singleton Pattern for example).

          • 2. Re: global variable
            David_F57 Level 5

            All you need is a simple file in the default folder of your project and from that point on you have globals, these can be variables and functions.


            for instance if you have a file called gv.as in your default project path you would declare its content like below




                      public class gv


                                public static var CGIUrl:String = "";  //not bindable just sharable

                                public static var LanguageCode:String="ENG";

                                public static var LanguageId:int =125;

                                public static var sessionID:String;


                                //============================================================================= ====================

                                // user interface configuration values

                                //============================================================================= ====================


                                [Bindable] static public var hiColor:uint = 0xD2D3D5;  // works when binding to properties..

                                [Bindable] static public var loColor:uint = 0x0056A5;

                                [Bindable] static public var gapSize:int = 20;



                                public static function testObjects(): void


                                          trace("pause to view objects in this module");







            at this point you reverence variables as so


            myloColor = gv.loColor;


            to set the global variable

            gv.loColor = 0x00FFFF;


            its also very handy for things like skins where you can bind values to skins (hence the hiColor, loColor above), so rather than the complexities of CSS which sometimes just isn't available you can have xml files you load at runtime that are used to set global variables.

            • 3. Re: global variable
              nfallon55 Level 1

              Got it.