Skip navigation
Currently Being Moderated

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

May 8, 2012 9:26 AM

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.c omponentInstance?

 

Thanks in advance,

Joe

 
Replies
  • Currently Being Moderated
    May 8, 2012 1:40 PM   in reply to JDeLuca9198

    My first question would be why do you want to remove the singleton and its references?

     

     

     

    I think your original method is much better than the new one you are trying to do

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2012 2:29 PM   in reply to JDeLuca9198

    I have to say im not exactly sure

     

     

     

    It’s interesting actually, Ive never really thought of doing it your way.

     

     

     

    As it happens Im just about to go to bed, the perfect place to ponder on the question. J

     

     

     

    I’ll have a look in the morning and try accessing some stuff the FlexGlobals way, and see how it works out.

     

     

     

    I think Ive only ever referenced FlexGlobals.tLA when using it to position a pop up window.

     

     

     

    Off the top of my head im not sure why your code isn’t working. It looks like it should

     

     

     

    Anyway, I’ll have a look in the morning

     

     

     

    Good luck and nice to speak to you

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points