3 Replies Latest reply on Mar 1, 2007 6:38 AM by webjoseph

    GLOBAL variables ?

    ashar2005 Level 1
      We're looking at porting a large Flash 8 application to Flex 2. Some of FlexBuilder's features make some things that took a long time very easy, but on the other hand, some simple things are turning into a pain in Flex,

      We have an actionscript file that sets default values for several _global variables that are accessed throughout the application.
      We have a login function that changes the value of some of these global variables when a person logs in.
      What used to be a simple assignment of _global.userName = userData[0].Firstname; is no longer possible
      because _global no longer exists and we can't figure out how to make it work, and if its going to require
      a lot of recoding to replace what was previously a 1 line assignment.

      In trying to accomplish what should be an easy task, we made a start.mxml which has 2 states,
      "notloggedin" which is the default state, and a "loggedIn" state.
      The notloggedin state displays a login.mxml component which contains a processLogin function which should
      change a couple of global variables and then it changes the state to "loggedIn" which displays the main.mxml
      component which should display some of the global variables that were changed in the login.mxml component.
      We cannot seem to set any variables as global.
      We've tried the class thing...
      public class myClass
      {
      static public var sGlobals:Object = new Object();
      }
      }
      We import myClass in the main applicaiton
      In the login function we set a value... myClass.sGlobals["userName"] = "testing";
      but when myClass.sGlobals.userName or myClass.sGlobals["userName'] is called, it shows nothing.

      If you know how to do this, can you actually post some example code.
      1. start.mxml
      2. login.mxml with a function that changes global variable values
      3. main.mxml displaying global variables
      4. if another file is necessary to accomplish this

      Thanks in advance.