adobe flex static function reference control

593 Views Asked by At

Is it possible to reference a control in an application from a static function?

What I have is a Viewstack containing VBoxes stored in separate controls. Ex:

<mx:ViewStack id="content" width="100%" height="100%" resizeToContent="true">
    <controls:Login/>
    <controls:Dash/>            
    <controls:Input/>   
    <controls:Review/>
    <controls:Search/>  
</mx:ViewStack>     

Once I get logged in on my login control, I would like to change the selected index of my ViewStack. From my outside controls, I cannot reference my ViewStack by name. I can reference a public static function from an outside control however I cannot refer to the ViewStack from within that function. Any help is greatly appreciated.

JH

3

There are 3 best solutions below

1
Triode On BEST ANSWER

Normally you can have a singleton class where you can save the instance of the main application and if you view stack is resides inside your main application then you can do some thing like this

public static function changeIndex(index:int):void
{
    FlexGlobals.topLevelApplication.content.selectedIndex = index;
    //urappinstance.content.selectedIndex = index;
}
1
Eduardo On

You could reach it starting from FlexGlobals.topLevelApplication (if it is visible from there). Although, the design of such a thing may be questionable.

0
JeffryHouser On

Is it possible to reference a control in an application from a static function?

Generally no. A static function (or property) exists on the class itself. Whereas MXML Children--such as in a view stack--exist on a specific instance of the class. A class level function will know nothing about any specific instances of the class and will not be able to access properties on a specific instance.

However, you can pass an instance of a class into a static function and access the properties that way. something like this:

public static function doStuff(myViewStack:ViewStack):void{
 trace(myViewStack.id)
 // do other stuff
}

And call it like this:

MyClass.doStuff(content)