Search code examples
apache-flexflex3mxmlstates

Use certain component depending of state in flex 3


Depending of some flag I want to use certain component in my mxml.

There is not a default value. So it's probably incorrect to put one in mxml and then with states remove it and add the other.

Both also share the same interface, and I call methods in Actionscript using id. That means that if I put them in different states in mxml, the compiler will complain about same id used 2 times.

Is there any conditional statement or state management like: if x use this component, else use other one (preferably with mxml not actionscript) ? And in a way they are mutually exclusive (can have same id)?


Solution

  • Make ie. both components properties visible and includeInLayout listen (bound) to the flag. You can also use states. Always react on events that the components should dispatch. In the listener you can use the currentTarget to get the sending component. The other way arround if you like to set a behaviour from somwhere without having access to the component id, define bindable properties and let both components listen to changes through bindings like I said with ie. the visible attribute.

    This normaly should work for all requirements. If you can give me some sample code I could write you a short sample and moreover we could add it to your question.