PDA

View Full Version : Control the parent's current state from a mxml component.


zuke
11-07-2009, 03:44 AM
I have a button to change the current state. This button is in a external file as a MXML component. And that's probably why when the button is clicked, the current state doesn't change. How do I refer to the parent window from an component? pls help!

----main page----

<mx:states>
<mx:State name="state1">
<mx:AddChild position="lastChild">....
</mx:AddChild>
</mx:State>
</mx:states>
<local:menu1 id="external_mxml_component"/>

----menu1.mxml---
<mx:Canvas xmlns:mx......
<mx:Button click="currentState='state1';"/>
....

Because the button is reffering to the parent, I simply thought it would be
"parent.currentstate='state1';" but there was no such syntax. How do i do this??

mattb
11-09-2009, 05:40 PM
Generally you should use an event here. When the button is clicked, fire a custom event. Then, in your main page add an event listener for that event and change the state accordingly.