States are so much more fun in Flex 4 and 4.5

I'm loving the new Flash Builder and 4.5 SDK. I don't know if everyone came to the same realization that I did... but "states" are awesome now with the 4+ SDK! You can change ANY property on the fly. Take for example a two stage button:

<s:Button icon.viewing="{Icons.PENCIL}" 
	      icon.editing="{Icons.DRIVE}"
	      label.viewing="Edit"
	      label.editing="Save"
	      click.viewing="{currentState='editing'}" 
	      click.editing="{currentState='viewing'}"
	      />

One button, two actions, two states. Note: the Icons class is just a static class with some icons embedded in it. Makes for quickly iconing stuff. Now I'm not saying you CAN or SHOULD do your buttons this way... you might simply make two buttons:

<s:Button icon="{Icons.DRIVE}"
	      label="Save" 
	      click="{currentState='viewing'}"
          includeIn="editing"
	    />
<s:Button icon="{Icons.PENCIL}" 
	      label="Edit"
	      click="{currentState='editing'}" 
          includeIn="viewing"
	    />

In theory, the former should take less memory but I haven't actually gone to look at what the states management is doing behind the scenes.

Of course, all the previous code assumes you've got the states defined:

<s:states>
   <s:State name="viewing"/>
   <s:State name="editing"/>
</s:states>

Social


profile for Jonathan Rowny at Stack Overflow, Q&A for professional and enthusiast programmers