Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sounds like the states in your Application are not connected to the states in your components. Just giving them the same name doesn't connect them in any way. Anyway, if you're just trying to hide/switch components in your main Application you really only need the states in there.</p> <p>One option would be to just access the Application's <code>currentState</code> property directly from within the components:</p> <pre><code>&lt;s:Button id="btn1" label="Button1" click="FlexGlobals.topLevelApplication.currentState = 'State2'"/&gt; </code></pre> <p>That works, but it's not recommended because it strongly couples the component with the parent Application and in a large project will lead to a mess if you have to refactor (or work with other people).</p> <p>Another option, is to have each component dispatch an event to let the parent know it should change:</p> <pre><code>&lt;fx:Metadata&gt; [Event(name="changeParentState", type="flash.events.Event")] &lt;/fx:Metadata&gt; &lt;s:Button id="btn1" label="Button1" click="dispatchEvent(new Event('changeParentState'));"/&gt; </code></pre> <p>Then, the parent would decide which state it should switch to:</p> <pre><code>&lt;local:Test1 includeIn="State1" changeParentState="currentState='State2'" /&gt; &lt;local:Test2 includeIn="State2" changeParentState="currentState='State1'" /&gt; </code></pre> <p>This way is more generic and just better OOP. However, if you'd want your components to be able to trigger more than just a single state, you might have to do something more complex. This should give you a sense of where to go at least.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload