tags:

views:

175

answers:

1

I am having a little difficulty working with states in Flex (or Flash) 4. Lets say that my application has three states; the default (base) state, state 1, and state 2.

State 1 should always be based on the base state, that's easy enough to accomplish. However, I would like state 2 to be based on the current state (either base or state 1). I can't for the life of me figure it out. I tried setting the basedOn property of state 1 to "this.currentState", but that just crashes my browser.

 <s:states>
  <s:State name="default"/>
  <s:State name="state1"/>
  <s:State name="state2" basedOn="{this.currentState}"/>
 </s:states>

 <s:TitleWindow id="configWindow" includeIn="state1" width="250" height="100%" close="configWindow_closeHandler(event)"/>
 <s:Panel id="settings" includeIn="state2" width="200" height="200"/>
+1  A: 

basedOn is not a Bindable property, which is why the value isn't changing in your code.

In theory, it is a read/write property so you can change it at runtime; but you'll have to do so manually, probably in ActionScript.

Based on your code snippet; I don't understand why you want to do this. As soon as you change the state to 'state2' wouldn't you enter into a weird loop?

www.Flextras.com
The code snippet above doesn't work - because of how I have incorrectly set the basedOn property.For state2, I want to add to the elements created for state1. Right now, when I switch to state2 from state1, the elements of state1 are removed, since state2 is by default based on the base state.
Add the TitleWindow to both states, then using a comma separated list:includeIn="state1, state2"
www.Flextras.com
Thanks, the includeIn and state groups did the trick.