5 Replies Latest reply on May 8, 2012 2:34 PM by JDeLuca9198

    How do I abbreviate FlexGlobals.topLevelApplication.componentInstance.componentInstance?

    JDeLuca9198

      I've created a Flex 4.6 web application that has many instances that need information from each other. Originally, I used a singleton to store the reference to the instance which was real convienent and works fine.

       

      I am refactoring it to use FlexGlobals.topLevelApplication to access the instance instead of an extra singleton class.

       

      Example 1:Singleton code that i am refactoring looks something like this and does work:(this works just fine but uses an extra class for storing the reference)


      //ViewHDDComp.mxml

      import HDD.Classes.HDDGlobals;

      private var hdd:HDDGlobals= HDDGlobals.getInstance();

       

      hdd.ViewHDD.menuButtons.visible=false; //the reference to the menuButtons component is stored in the HDD Globals

      hdd.ViewHDD.menuInput.visible=false; //the reference to the menuInput component is stored in the HDD Globals

       

      //HDDGlobals.as

      private var _viewHDD:ViewHDDComp;

      public function get ViewHDD():ViewHDDComp { return _viewHDD; }

      public function set ViewHDD(viewHDD:ViewHDDComp):void{_viewHDD=viewHDD;}

       

      Example 2: This is what I am trying to do which does not work:(don't understand why it doesn't)


      //ViewHDDComp.mxml

      import HDD.Components.ViewHDDComp;

      private var h:ViewHDDComp=FlexGlobals.topLevelApplication.viewHDD;

       

      h.menuButtons.visible=false; //menuButtons is a component in the instance viewHDD component

      h.menuInput.visible=false; //menuInput is a component in the instance viewHDD component

       

      This is what does work:(but is too verbose)

      //ViewHDDComp.mxml

      FlexGlobals.topLevelApplication.viewHDD.menuButtons.visible=false; //menuButtons is a component in the instance viewHDD component

      FlexGlobals.topLevelApplication.viewHDD.menuInput.visible=false; //menuInput is a component in the instance viewHDD component

       

      How do I abbreviate or type cast FlexGlobals.topLevelApplication.componentInstance.componentInstance.componentInstance?

       

      Thanks in advance,

      Joe