Here is a short way to change the currentState of components from an external component, Note that this is based from my coding experience and somewhere out the net a better solution might exists.

Change state of Main from a customized component:

1) add this import script
import mx.core.FlexGlobals;

2) Access the main app by this:
FlexGlobals.topLevelApplication.currentState = 'NewStateName';

Change state of component that is displayed from Main:

NOTE: This might be also used to access variables and other public objects of that component.

1) add this import script:
import mx.core.FlexGlobals;

2) make sure that the component has an ID value
<component:ComponentName id="comp1" {..other variables} />

3) access the component from the main app
FlexGlobals.topLevelApplication.comp1.currentState = 'NewStateName';

Again these line of codes are based from my experience, if there is a better way of doing this, I would be glad to hear it via your comment.

No comments :

Post a Comment