<rss version="2.0">
<channel>
<title>Learn Flex 4 from Scratch</title>
<link>http://onflash.org/learn/fx4/index.php</link>
<description>RSS feed from Learn Flex 4 from Scratch</description>
<language>en-us</language>

	<item>
	  <title>stateGroups, includeIn, excludeFrom</title>
	  <pubDate>Tue, 08 Dec 2009 12:10:12 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups%2C+includeIn%2C+excludeFrom</link>
	  <description><pre id="diff">When managing many states, you can group states into stateGroups to simplify things. In each container of an application you can have only 1 state value at a time, &quot;currentState&quot;, using stateGroups lets you utilize &quot;N&quot; states at the same time. In the demo below, look at the state for &quot;addCheckBoxandButton&quot;, this state includes 2 states.

{syntax mxml}&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
			   xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; 
			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt; 
	&lt;s:layout&gt;
		&lt;s:VerticalLayout/&gt;
	&lt;/s:layout&gt;
	
	&lt;s:states&gt; 
		&lt;s:State name=&quot;default&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBox&quot; stateGroups=&quot;Group1&quot;/&gt; 
		&lt;s:State name=&quot;addTextInput&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBoxandButton&quot; stateGroups=&quot;Group1&quot;/&gt; 
	&lt;/s:states&gt;
	
	&lt;s:HGroup&gt;
		&lt;!-- Included in the addCheckBox and addCheckBoxandButton view states. --&gt; 
		&lt;s:CheckBox id=&quot;myCB&quot; label=&quot;Checkbox&quot; 
					includeIn=&quot;Group1&quot;/&gt;
		
		&lt;!-- Included in the addTextInput view state. --&gt; 
		&lt;s:TextInput id=&quot;myTI&quot; 
					 includeIn=&quot;addTextInput&quot;/&gt;    
		
		&lt;!-- Included in the addCheckBoxandButton view state. --&gt; 
		&lt;s:Button id=&quot;myB&quot; 
				  includeIn=&quot;addCheckBoxandButton&quot;/&gt;
		
		&lt;!-- Exclude from addTextInput view state. --&gt; 
		&lt;s:TextArea text=&quot;Exclude from addTextInput&quot; 
					excludeFrom=&quot;addTextInput&quot;/&gt;             
	&lt;/s:HGroup&gt;
	
	&lt;s:HGroup&gt;
		&lt;s:Button label=&quot;Add CheckBox&quot; 
				  click=&quot;currentState='addCheckBox'&quot;/&gt; 
		&lt;s:Button label=&quot;Add Textinput&quot; 
				  click=&quot;currentState='addTextInput'&quot;/&gt;    
		&lt;s:Button label=&quot;Add Group 1&quot; 
				  click=&quot;currentState='addCheckBoxandButton'&quot;/&gt; 
		&lt;s:Button label=&quot;Default&quot; 
				  click=&quot;currentState='default'&quot;/&gt;
	&lt;/s:HGroup&gt; 
&lt;/s:Application&gt;{/syntax}
  
The other thing to notice here is the use of the attribute &quot;excludeFrom&quot; and &quot;includeIn&quot;. These attributes make it easy to add and remove components from any part of an application. These add a real depth to Flex as very little code is required.

All told these State features really shine when Flash Catalyst is applied. These features of the framework make code generated by Catalyst very easy to understand and change from a developer perspective. Truth be told, I was very concerned about the readability of Catalyst output but the framework additions to Flex really make this seamless.
<ins>
{COMMENTS}</ins>
</pre></description>
	</item>

	<item>
	  <title>stateGroups, includeIn, excludeFrom</title>
	  <pubDate>Mon, 07 Dec 2009 15:37:27 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups%2C+includeIn%2C+excludeFrom</link>
	  <description><pre id="diff">When managing many states, you can group states into stateGroups to simplify things. In each container of an application you can have only 1 state value at a time, &quot;currentState&quot;, using stateGroups lets you utilize &quot;N&quot; states at the same time. In the demo below, look at the state for &quot;addCheckBoxandButton&quot;, this state includes 2 states.

{syntax mxml}&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
			   xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; 
			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt; 
	&lt;s:layout&gt;
		&lt;s:VerticalLayout/&gt;
	&lt;/s:layout&gt;
	
	&lt;s:states&gt; 
		&lt;s:State name=&quot;default&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBox&quot; stateGroups=&quot;Group1&quot;/&gt; 
		&lt;s:State name=&quot;addTextInput&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBoxandButton&quot; stateGroups=&quot;Group1&quot;/&gt; 
	&lt;/s:states&gt;
	
	&lt;s:HGroup&gt;
		&lt;!-- Included in the addCheckBox and addCheckBoxandButton view states. --&gt; 
		&lt;s:CheckBox id=&quot;myCB&quot; label=&quot;Checkbox&quot; 
					includeIn=&quot;Group1&quot;/&gt;
		
		&lt;!-- Included in the addTextInput view state. --&gt; 
		&lt;s:TextInput id=&quot;myTI&quot; 
					 includeIn=&quot;addTextInput&quot;/&gt;    
		
		&lt;!-- Included in the addCheckBoxandButton view state. --&gt; 
		&lt;s:Button id=&quot;myB&quot; 
				  includeIn=&quot;addCheckBoxandButton&quot;/&gt;
		
		&lt;!-- Exclude from addTextInput view state. --&gt; 
		&lt;s:TextArea text=&quot;Exclude from addTextInput&quot; 
					excludeFrom=&quot;addTextInput&quot;/&gt;             
	&lt;/s:HGroup&gt;
	
	&lt;s:HGroup&gt;
		&lt;s:Button label=&quot;Add CheckBox&quot; 
				  click=&quot;currentState='addCheckBox'&quot;/&gt; 
		&lt;s:Button label=&quot;Add Textinput&quot; 
				  click=&quot;currentState='addTextInput'&quot;/&gt;    
		&lt;s:Button label=&quot;Add Group 1&quot; 
				  click=&quot;currentState='addCheckBoxandButton'&quot;/&gt; 
		&lt;s:Button label=&quot;Default&quot; 
				  click=&quot;currentState='default'&quot;/&gt;
	&lt;/s:HGroup&gt; 
&lt;/s:Application&gt;{/syntax}
  
The other thing to notice here is the use of the attribute &quot;excludeFrom&quot; and &quot;includeIn&quot;. These attributes make it easy to add and remove components from any part of an application. These add a real depth to Flex as very little code is required.

All told these State features really shine when Flash Catalyst is applied. These features of the framework make code generated by Catalyst very easy to understand and change from a developer perspective. Truth be <del>told</del><ins>told,</ins> I was very concerned about the readability of Catalyst output but the framework additions to Flex really<del> smooth</del> make this seamless.
</pre></description>
	</item>

	<item>
	  <title>stateGroups, includeIn, excludeFrom</title>
	  <pubDate>Mon, 07 Dec 2009 14:54:51 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups%2C+includeIn%2C+excludeFrom</link>
	  <description><pre id="diff">When managing many states, you can group states into stateGroups to simplify things. <del>Since at</del><ins>In</ins> each container of an application you can have only 1 state value at a time, &quot;currentState&quot;, using stateGroups lets you <del>use 2</del><ins>utilize &quot;N&quot;</ins> states at the same time. In the demo below, look at the state for &quot;addCheckBoxandButton&quot;, this state includes 2 states.

{syntax mxml}&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
			   xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; 
			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt; 
	&lt;s:layout&gt;
		&lt;s:VerticalLayout/&gt;
	&lt;/s:layout&gt;
	
	&lt;s:states&gt; 
		&lt;s:State name=&quot;default&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBox&quot; stateGroups=&quot;Group1&quot;/&gt; 
		&lt;s:State name=&quot;addTextInput&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBoxandButton&quot; stateGroups=&quot;Group1&quot;/&gt; 
	&lt;/s:states&gt;
	
	&lt;s:HGroup&gt;
		&lt;!-- Included in the addCheckBox and addCheckBoxandButton view states. --&gt; 
		&lt;s:CheckBox id=&quot;myCB&quot; label=&quot;Checkbox&quot; 
					includeIn=&quot;Group1&quot;/&gt;
		
		&lt;!-- Included in the addTextInput view state. --&gt; 
		&lt;s:TextInput id=&quot;myTI&quot; 
					 includeIn=&quot;addTextInput&quot;/&gt;    
		
		&lt;!-- Included in the addCheckBoxandButton view state. --&gt; 
		&lt;s:Button id=&quot;myB&quot; 
				  includeIn=&quot;addCheckBoxandButton&quot;/&gt;
		
		&lt;!-- Exclude from addTextInput view state. --&gt; 
		&lt;s:TextArea text=&quot;Exclude from addTextInput&quot; 
					excludeFrom=&quot;addTextInput&quot;/&gt;             
	&lt;/s:HGroup&gt;
	
	&lt;s:HGroup&gt;
		&lt;s:Button label=&quot;Add CheckBox&quot; 
				  click=&quot;currentState='addCheckBox'&quot;/&gt; 
		&lt;s:Button label=&quot;Add Textinput&quot; 
				  click=&quot;currentState='addTextInput'&quot;/&gt;    
		&lt;s:Button label=&quot;Add Group 1&quot; 
				  click=&quot;currentState='addCheckBoxandButton'&quot;/&gt; 
		&lt;s:Button label=&quot;Default&quot; 
				  click=&quot;currentState='default'&quot;/&gt;
	&lt;/s:HGroup&gt; 
&lt;/s:Application&gt;{/syntax}
  
The other thing to notice here is the use of the attribute &quot;excludeFrom&quot; and &quot;includeIn&quot;. These attributes make it easy to add and remove components from any part of an application. These add a real depth to Flex as very little code is required.

All told these State features really shine when Flash Catalyst is applied. These features of the framework make code generated by Catalyst very easy to understand and change from a developer perspective. Truth be told I was very concerned about the readability of Catalyst output but the framework additions to Flex really smooth make this seamless.
</pre></description>
	</item>

	<item>
	  <title>stateGroups, includeIn, excludeFrom</title>
	  <pubDate>Mon, 07 Dec 2009 14:52:41 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups%2C+includeIn%2C+excludeFrom</link>
	  <description><pre id="diff">When managing many states, you can group states into stateGroups to simplify things. Since at each container of an application you can have only 1 state value at a time, &quot;currentState&quot;, using stateGroups lets you use 2 states at the same time.<ins> In the demo below, look at the state for &quot;addCheckBoxandButton&quot;, this state includes 2 states.</ins>

{syntax mxml}&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
			   xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; 
			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt; 
	&lt;s:layout&gt;
		&lt;s:VerticalLayout/&gt;
	&lt;/s:layout&gt;
	
	&lt;s:states&gt; 
		&lt;s:State name=&quot;default&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBox&quot; stateGroups=&quot;Group1&quot;/&gt; 
		&lt;s:State name=&quot;addTextInput&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBoxandButton&quot; stateGroups=&quot;Group1&quot;/&gt; 
	&lt;/s:states&gt;
	
	&lt;s:HGroup&gt;
		&lt;!-- Included in the addCheckBox and addCheckBoxandButton view states. --&gt; 
		&lt;s:CheckBox id=&quot;myCB&quot; label=&quot;Checkbox&quot; 
					includeIn=&quot;Group1&quot;/&gt;
		
		&lt;!-- Included in the addTextInput view state. --&gt; 
		&lt;s:TextInput id=&quot;myTI&quot; 
					 includeIn=&quot;addTextInput&quot;/&gt;    
		
		&lt;!-- Included in the addCheckBoxandButton view state. --&gt; 
		&lt;s:Button id=&quot;myB&quot; 
				  includeIn=&quot;addCheckBoxandButton&quot;/&gt;
		
		&lt;!-- Exclude from addTextInput view state. --&gt; 
		&lt;s:TextArea text=&quot;Exclude from addTextInput&quot; 
					excludeFrom=&quot;addTextInput&quot;/&gt;             
	&lt;/s:HGroup&gt;
	
	&lt;s:HGroup&gt;
		&lt;s:Button label=&quot;Add CheckBox&quot; 
				  click=&quot;currentState='addCheckBox'&quot;/&gt; 
		&lt;s:Button label=&quot;Add Textinput&quot; 
				  click=&quot;currentState='addTextInput'&quot;/&gt;    
		&lt;s:Button label=&quot;Add Group 1&quot; 
				  click=&quot;currentState='addCheckBoxandButton'&quot;/&gt; 
		&lt;s:Button label=&quot;Default&quot; 
				  click=&quot;currentState='default'&quot;/&gt;
	&lt;/s:HGroup&gt; 
&lt;/s:Application&gt;{/syntax}
  
<ins>The other thing to notice here is the use of the attribute &quot;excludeFrom&quot; and &quot;includeIn&quot;. These attributes make it easy to add and remove components from any part of an application. These add a real depth to Flex as very little code is required.

All told these State features really shine when Flash Catalyst is applied. These features of the framework make code generated by Catalyst very easy to understand and change from a developer perspective. Truth be told I was very concerned about the readability of Catalyst output but the framework additions to Flex really smooth make this seamless.</ins>
</pre></description>
	</item>

	<item>
	  <title>stateGroups, includeIn, excludeFrom</title>
	  <pubDate>Mon, 07 Dec 2009 14:47:23 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups%2C+includeIn%2C+excludeFrom</link>
	  <description><pre id="diff"></pre></description>
	</item>

	<item>
	  <title>stateGroups, includeIn, excludeFrom</title>
	  <pubDate>Mon, 07 Dec 2009 14:47:17 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups%2C+includeIn%2C+excludeFrom</link>
	  <description><pre id="diff">When managing many states, you can group states into stateGroups to simplify things. Since at each container of an application you can have only 1 state value at a time, &quot;currentState&quot;, using stateGroups lets you use 2 states at the same time.

{syntax mxml}&lt;?xml version=&quot;1.0&quot;?&gt;
<del>&lt;!-- states\StatesSimpleGroups.mxml --&gt;</del>
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
			   xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; 
			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt; 
	&lt;s:layout&gt;
		&lt;s:VerticalLayout/&gt;
	&lt;/s:layout&gt;
	
	&lt;s:states&gt; 
		&lt;s:State name=&quot;default&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBox&quot; stateGroups=&quot;Group1&quot;/&gt; 
		&lt;s:State name=&quot;addTextInput&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBoxandButton&quot; stateGroups=&quot;Group1&quot;/&gt; 
	&lt;/s:states&gt;
	
	&lt;s:HGroup&gt;
		&lt;!-- Included in the addCheckBox and addCheckBoxandButton view states. --&gt; 
		&lt;s:CheckBox id=&quot;myCB&quot; label=&quot;Checkbox&quot; 
					includeIn=&quot;Group1&quot;/&gt;
		
		&lt;!-- Included in the addTextInput view state. --&gt; 
		&lt;s:TextInput id=&quot;myTI&quot; 
					 includeIn=&quot;addTextInput&quot;/&gt;    
		
		&lt;!-- Included in the addCheckBoxandButton view state. --&gt; 
		&lt;s:Button id=&quot;myB&quot; 
				  includeIn=&quot;addCheckBoxandButton&quot;/&gt;
		
		&lt;!-- Exclude from addTextInput view state. --&gt; 
		&lt;s:TextArea text=&quot;Exclude from addTextInput&quot; 
					excludeFrom=&quot;addTextInput&quot;/&gt;             
	&lt;/s:HGroup&gt;
	
	&lt;s:HGroup&gt;
		&lt;s:Button label=&quot;Add CheckBox&quot; 
				  click=&quot;currentState='addCheckBox'&quot;/&gt; 
		&lt;s:Button label=&quot;Add Textinput&quot; 
				  click=&quot;currentState='addTextInput'&quot;/&gt;    
		&lt;s:Button label=&quot;Add Group 1&quot; 
				  click=&quot;currentState='addCheckBoxandButton'&quot;/&gt; 
		&lt;s:Button label=&quot;Default&quot; 
				  click=&quot;currentState='default'&quot;/&gt;
	&lt;/s:HGroup&gt; 
&lt;/s:Application&gt;{/syntax}
  
</pre></description>
	</item>

	<item>
	  <title>stateGroups, includeIn, excludeFrom</title>
	  <pubDate>Mon, 07 Dec 2009 14:46:57 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups%2C+includeIn%2C+excludeFrom</link>
	  <description><pre id="diff"><del>test</del><ins>When managing many states, you can group states into stateGroups to simplify things. Since at each container of an application you can have only 1 state value at a time, &quot;currentState&quot;, using stateGroups lets you use 2 states at the same time.

{syntax mxml}&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!-- states\StatesSimpleGroups.mxml --&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
			   xmlns:mx=&quot;library://ns.adobe.com/flex/halo&quot; 
			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt; 
	&lt;s:layout&gt;
		&lt;s:VerticalLayout/&gt;
	&lt;/s:layout&gt;
	
	&lt;s:states&gt; 
		&lt;s:State name=&quot;default&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBox&quot; stateGroups=&quot;Group1&quot;/&gt; 
		&lt;s:State name=&quot;addTextInput&quot;/&gt; 
		&lt;s:State name=&quot;addCheckBoxandButton&quot; stateGroups=&quot;Group1&quot;/&gt; 
	&lt;/s:states&gt;
	
	&lt;s:HGroup&gt;
		&lt;!-- Included in the addCheckBox and addCheckBoxandButton view states. --&gt; 
		&lt;s:CheckBox id=&quot;myCB&quot; label=&quot;Checkbox&quot; 
					includeIn=&quot;Group1&quot;/&gt;
		
		&lt;!-- Included in the addTextInput view state. --&gt; 
		&lt;s:TextInput id=&quot;myTI&quot; 
					 includeIn=&quot;addTextInput&quot;/&gt;    
		
		&lt;!-- Included in the addCheckBoxandButton view state. --&gt; 
		&lt;s:Button id=&quot;myB&quot; 
				  includeIn=&quot;addCheckBoxandButton&quot;/&gt;
		
		&lt;!-- Exclude from addTextInput view state. --&gt; 
		&lt;s:TextArea text=&quot;Exclude from addTextInput&quot; 
					excludeFrom=&quot;addTextInput&quot;/&gt;             
	&lt;/s:HGroup&gt;
	
	&lt;s:HGroup&gt;
		&lt;s:Button label=&quot;Add CheckBox&quot; 
				  click=&quot;currentState='addCheckBox'&quot;/&gt; 
		&lt;s:Button label=&quot;Add Textinput&quot; 
				  click=&quot;currentState='addTextInput'&quot;/&gt;    
		&lt;s:Button label=&quot;Add Group 1&quot; 
				  click=&quot;currentState='addCheckBoxandButton'&quot;/&gt; 
		&lt;s:Button label=&quot;Default&quot; 
				  click=&quot;currentState='default'&quot;/&gt;
	&lt;/s:HGroup&gt; 
&lt;/s:Application&gt;{/syntax}
  </ins>
</pre></description>
	</item>

	<item>
	  <title>stateGroups, includeIn, excludeFrom</title>
	  <pubDate>Mon, 07 Dec 2009 14:33:13 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups%2C+includeIn%2C+excludeFrom</link>
	  <description><pre id="diff"><del>VŠp.LÑa..WŠp 20091207-1433-13.bakXzÊXŠpÈmeta.datˆÚæ</del><ins>test</ins>
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Mon, 07 Dec 2009 14:32:58 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].



!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}




!!'''Outline:'''
*[What is Flex?]
*[Languages of Flex]
*[The Foundation of Flex - spark.components.Application]
*[MXML Namespaces]
*[spark.components.Application Events]
*[Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties]
*[States]
<del>*stateGroups,</del><ins>*[stateGroups,</ins> includeIn, <del>excludeFrom</del><ins>excludeFrom]</ins>
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learn Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>stateGroups includeIn excludeFrom</title>
	  <pubDate>Mon, 07 Dec 2009 14:32:23 -0500</pubDate>
	  <link>http://onflash.org/learn/fx4/index.php?page=stateGroups+includeIn+excludeFrom</link>
	  <description><pre id="diff"><del>RŠp.LÑa..SŠp 20091207-1432-23.bakÖPÊTŠpÈmeta.datx‘æ</del><ins>test</ins>
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Wed, 28 Oct 2009 12:36:22 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].



!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}




!!'''Outline:'''
*[What is Flex?]
*[Languages of Flex]
*[The Foundation of Flex - spark.components.Application]
*[MXML <del>Namespace]</del><ins>Namespaces]</ins>
*[spark.components.Application Events]
*[Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties]
*[States]
*stateGroups, includeIn, excludeFrom
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learn Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Wed, 28 Oct 2009 12:36:04 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].



!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}




!!'''Outline:'''
*[What<del> is Flex?|What</del> is Flex?]
*[Languages<del> of Flex (MXML &amp; ActionScript 3)|Languages</del> of Flex]
*[The<del> Foundation of Flex - spark.components.Application|The</del> Foundation of Flex - spark.components.Application]
*[MXML <del>Namespaces|MXML Namespaces]</del><ins>Namespace]</ins>
*[spark.components.Application<del> Events|spark.components.Application</del> Events]
*[Element<del> Creation|Element</del> Creation]
*[addElement,<del> addElementAt, removeElement, removeElementAt|addElement,</del> addElementAt, removeElement, removeElementAt]
*[Element<del> Properties|Element</del> Properties]
*[States]
*stateGroups, includeIn, excludeFrom
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learn Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Wed, 28 Oct 2009 12:34:23 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].



!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}




!!'''Outline:'''
*[What is Flex?|What is Flex?]
*[Languages of Flex (MXML &amp; ActionScript 3)|Languages of Flex]
*[The Foundation of Flex - spark.components.Application|The Foundation of Flex - spark.components.Application]
*[MXML Namespaces|MXML Namespaces]
*[spark.components.Application Events|spark.components.Application Events]
*[Element Creation|Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt|addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties|Element Properties]
<del>*[States|States]
*[stateGroups,</del><ins>*[States]
*stateGroups,</ins> includeIn, <del>excludeFrom]</del><ins>excludeFrom</ins>
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learn Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Wed, 28 Oct 2009 12:33:41 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].



!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}




!!'''Outline:'''
*[What is Flex?|What is Flex?]
*[Languages of Flex (MXML &amp; ActionScript 3)|Languages of Flex]
*[The Foundation of Flex - spark.components.Application|The Foundation of Flex - spark.components.Application]
*[MXML Namespaces|MXML Namespaces]
*[spark.components.Application Events|spark.components.Application Events]
*[Element Creation|Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt|addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties|Element Properties]
*[States|States]
<ins>*[stateGroups, includeIn, excludeFrom]</ins>
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learn Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Tue, 27 Oct 2009 11:33:26 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff"></pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Tue, 27 Oct 2009 11:32:18 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].



!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}




!!'''Outline:'''
*[What is Flex?|What is Flex?]
*[Languages of Flex (MXML &amp; ActionScript 3)|Languages of Flex]
*[The Foundation of Flex - spark.components.Application|The Foundation of Flex - spark.components.Application]
*[MXML Namespaces|MXML Namespaces]
*[spark.components.Application Events|spark.components.Application Events]
*[Element Creation|Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt|addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties|Element Properties]
*[States|States]
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy <del>'''Learning</del><ins>'''Learn</ins> Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>Element Properties</title>
	  <pubDate>Tue, 27 Oct 2009 01:34:26 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Properties</link>
	  <description><pre id="diff">Element properties are very important in Flex MXML and ActionScript. In MXML they are set as attribute strings and child elements but at compile time are converted to typed values. 

Attribute string properties can support boolean values (&quot;true&quot; or &quot;false&quot;), numeric values ( &quot;1&quot;, &quot;2.5&quot;, &quot;#FF0000&quot;), string values (&quot;Duhhhh&quot;), bindings ( &quot;{ foo.text }&quot; ... more on this later )

Here is an example:
{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:Label  
			fontSize=&quot;30&quot;
			text=&quot;I am label with attribute properties!&quot;/&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;{/syntax}

With MXML elements you can specify values with much more complex structure. In this example we set values into a Spark DropDownList using the &lt;s:ArrayCollection&gt; and &lt;fx:String&gt; elements.

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:DropDownList&gt; 
			&lt;s:dataProvider&gt;
				&lt;s:ArrayCollection&gt;
					&lt;fx:String&gt;AK&lt;/fx:String&gt;
					&lt;fx:String&gt;AL&lt;/fx:String&gt;
					&lt;fx:String&gt;AR&lt;/fx:String&gt;
				&lt;/s:ArrayCollection&gt;
			&lt;/s:dataProvider&gt;
		&lt;/s:DropDownList&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;{/syntax}

The nested element model also supports inline graphics in Flex 4. Just as you can specify data for the dataProvider property, you can add graphics inline into an application. Here is a brief graphics example of Flex 4 using MXML nested elements. Look at the &lt;s:Rect&gt; element with nested stroke and fill:

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Group&gt;
		&lt;s:Rect 
			x=&quot;0&quot; y=&quot;0&quot; 
			radiusX=&quot;4&quot; 
			radiusY=&quot;4&quot; 
			height=&quot;100%&quot; 
			width=&quot;100%&quot;&gt;
			&lt;s:stroke&gt;
				&lt;s:LinearGradientStroke 
					weight=&quot;1&quot; 
					scaleMode=&quot;normal&quot;/&gt;
			&lt;/s:stroke&gt;
			&lt;s:fill&gt;
				&lt;s:LinearGradient&gt;
					&lt;s:entries&gt;
<del>						&lt;mx:GradientEntry</del><ins>						&lt;s:GradientEntry</ins> 
							color=&quot;0x999999&quot;/&gt;
					&lt;/s:entries&gt;
				&lt;/s:LinearGradient&gt;
			&lt;/s:fill&gt;
		&lt;/s:Rect&gt;        
		
		&lt;s:Button 
			label=&quot;Button 1&quot; 
			left=&quot;10&quot;
			top=&quot;13&quot;
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 2&quot;
			left=&quot;110&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 3&quot;
			left=&quot;210&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 4&quot;
			left=&quot;310&quot; 
			top=&quot;13&quot; 
			right=&quot;10&quot; 
			bottom=&quot;10&quot;/&gt;
		
	&lt;/s:Group&gt;
&lt;/s:Application&gt;{/syntax}

In ActionScript, you can set element values directly as typed values. Make sure to use correct types when setting values by ActionScript mismatched types will give you errors at compilation and at runtime. In the following example a spark Button component is created and attributes are set using ActionScript:

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();

				//set some properties
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge dynamic s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into the Application
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
&lt;/s:Application&gt;{/syntax}


 {COMMENTS}

</pre></description>
	</item>

	<item>
	  <title>States</title>
	  <pubDate>Mon, 26 Oct 2009 20:46:57 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=States</link>
	  <description><pre id="diff">The States feature has changed wildly in Flex 4 and is my favorite feature of the release.

'''What is a State?'''
In Flex, a state is a series of property values associated with a state name. When the state is set, all the values within the state are applied in bulk. States are a very handy way to organize your application as changing from different views within your application is typically managed by changing many properties all at once. By using the states feature you only need to set the value of '''currentState''' to the state name you define.

Here is a simple States example. In the example I define 3 states named &quot;One&quot; &quot;Two&quot; &quot;Three&quot; and navigate between them with 3 buttons:

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
<del>			click=&quot;this.currentState = 'One'&quot;/&gt;</del><ins>			click=&quot;this.currentState='One'&quot;/&gt;</ins>
		
		&lt;s:Button 
			label=&quot;Two&quot; 
<del>			click=&quot;this.currentState = 'Two'&quot;/&gt;</del><ins>			click=&quot;this.currentState='Two'&quot;/&gt;</ins>
		
		&lt;s:Button 
			label=&quot;Three&quot; 
<del>			click=&quot;this.currentState = 'Three'&quot;/&gt;</del><ins>			click=&quot;this.currentState='Three'&quot;/&gt;</ins>
		
	&lt;/s:HGroup&gt;
	
&lt;/s:Application&gt;{/syntax}

'''Wow, that was boring!''' 

The prior example worked perfectly but we didn't set any state property values so it wasn't that exciting. In Flex 4 the syntax for State property values changed. Before Flex 4, all state properties were set within the &lt;s:State&gt; component but now you can additionally set state values on the components they affect. This makes understanding the effect of state changes much easier to see and work with. Since states affect properties, the new syntax extends the existing dot notation property syntax like so:

{syntax mxml}&lt;s:Label 
	text.One = &quot;One&quot; 
	text.Two = &quot;Two&quot; 
	text.Three = &quot;Three&quot; /&gt;{/syntax}

Notice that the 'text' value has a different value for each state. Whenever the state changes, the value of the &quot;text&quot; property will change if a property is specified for the state change. If we were to set &quot;currentState='foo'&quot;, since there isn't a property value designated, the value would remain depending on which state had fired prior.

'''''HINT: In FB4 states have code hinting if you define the &lt;s:states&gt; tag first!'''''

Here is the above example complete:
{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
<del>			click=&quot;this.currentState = 'One'&quot;/&gt;</del><ins>			click=&quot;this.currentState='One'&quot;/&gt;</ins>
		
		&lt;s:Button 
			label=&quot;Two&quot; 
<del>			click=&quot;this.currentState = 'Two'&quot;/&gt;</del><ins>			click=&quot;this.currentState='Two'&quot;/&gt;</ins>
		
		&lt;s:Button 
			label=&quot;Three&quot; 
<del>			click=&quot;this.currentState = 'Three'&quot;/&gt;</del><ins>			click=&quot;this.currentState='Three'&quot;/&gt;</ins>
		
	&lt;/s:HGroup&gt;
	
	&lt;s:Label
		text.One = &quot;One&quot; 
		text.Two = &quot;Two&quot; 
		text.Three = &quot;Three&quot;
		horizontalCenter=&quot;0&quot;
		top=&quot;50&quot;
		fontSize=&quot;40&quot;
		/&gt;
	
&lt;/s:Application&gt;{/syntax}

Enough of this simple stuff, lets get crazy with States! Lets add a Panel, set its title value and resize it using States. Also note that the state buttons are disabled when a state is selected! That is a ton of logic that you didn't need to write and is just the tip of the iceberg in using States.

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:Panel
	 	resizeEffect=&quot;Resize&quot;
		title.One=&quot;One&quot;
		title.Two=&quot;Two&quot;
		title.Three=&quot;Three&quot;
		width.One=&quot;800&quot;
		width.Two=&quot;200&quot;
		width.Three=&quot;400&quot;
		height.One=&quot;400&quot;
		height.Two=&quot;600&quot;
		height.Three=&quot;200&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;
		&gt;
		
		&lt;s:Label
			text.One=&quot;One&quot; 
			text.Two=&quot;Two&quot; 
			text.Three=&quot;Three&quot;
			horizontalCenter=&quot;0&quot;
			verticalCenter=&quot;0&quot;
			fontSize=&quot;40&quot;
			/&gt;

	&lt;/s:Panel&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot;
			enabled.One=&quot;false&quot;
<del>			click=&quot;this.currentState = 'One'&quot;/&gt;</del><ins>			click=&quot;this.currentState='One'&quot;/&gt;</ins>
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			enabled.Two=&quot;false&quot;
<del>			click=&quot;this.currentState = 'Two'&quot;/&gt;</del><ins>			click=&quot;this.currentState='Two'&quot;/&gt;</ins>
		
		&lt;s:Button 
			label=&quot;Three&quot;
			enabled.Three=&quot;false&quot; 
<del>			click=&quot;this.currentState = 'Three'&quot;/&gt;</del><ins>			click=&quot;this.currentState='Three'&quot;/&gt;</ins>
		
	&lt;/s:HGroup&gt;
	
&lt;/s:Application&gt;{/syntax}

What I really like is just how readable this code is and how you can make changes to States code easily. Not only is this great for in app State use but States are an essential part of skinning in Flex. &lt;s:Button&gt; has 4 states and simply implementing different graphics per state will dramatically alter the look and feel.

In Flash Catalyst, states are used extensively and the code they generate is a powerful way to learn both Flex Skinning and using States within application development.

&quot;States in Flex 4 are ninja quality magic!&quot; - Ted :)

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>Element Properties</title>
	  <pubDate>Mon, 26 Oct 2009 20:45:16 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Properties</link>
	  <description><pre id="diff">Element properties are very important in Flex MXML and ActionScript. In MXML they are set as attribute strings and child elements but at compile time are converted to typed values. 

Attribute string properties can support boolean values (&quot;true&quot; or &quot;false&quot;), numeric values ( &quot;1&quot;, &quot;2.5&quot;, &quot;#FF0000&quot;), string values (&quot;Duhhhh&quot;), bindings ( &quot;{ foo.text }&quot; ... more on this later )

Here is an example:
{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:Label  
			fontSize=&quot;30&quot;
			text=&quot;I am label with attribute properties!&quot;/&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;{/syntax}

With MXML elements you can specify values with much more complex structure. In this example we set values into a Spark DropDownList using the &lt;s:ArrayCollection&gt; and &lt;fx:String&gt; elements.

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:DropDownList&gt; 
			&lt;s:dataProvider&gt;
				&lt;s:ArrayCollection&gt;
					&lt;fx:String&gt;AK&lt;/fx:String&gt;
					&lt;fx:String&gt;AL&lt;/fx:String&gt;
					&lt;fx:String&gt;AR&lt;/fx:String&gt;
				&lt;/s:ArrayCollection&gt;
			&lt;/s:dataProvider&gt;
		&lt;/s:DropDownList&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;{/syntax}

The nested element model also supports inline graphics in Flex 4. Just as you can specify data for the dataProvider property, you can add graphics inline into an application. Here is a brief graphics example of Flex 4 using MXML nested elements. Look at the &lt;s:Rect&gt; element with nested stroke and fill:

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Group&gt;
		&lt;s:Rect 
			x=&quot;0&quot; y=&quot;0&quot; 
			radiusX=&quot;4&quot; 
			radiusY=&quot;4&quot; 
			height=&quot;100%&quot; 
			width=&quot;100%&quot;&gt;
			&lt;s:stroke&gt;
				&lt;s:LinearGradientStroke 
					weight=&quot;1&quot; 
					scaleMode=&quot;normal&quot;/&gt;
			&lt;/s:stroke&gt;
			&lt;s:fill&gt;
				&lt;s:LinearGradient&gt;
					&lt;s:entries&gt;
						&lt;mx:GradientEntry 
							color=&quot;0x999999&quot;/&gt;
					&lt;/s:entries&gt;
				&lt;/s:LinearGradient&gt;
			&lt;/s:fill&gt;
		&lt;/s:Rect&gt;        
		
		&lt;s:Button 
			label=&quot;Button 1&quot; 
			left=&quot;10&quot;
			top=&quot;13&quot;
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 2&quot;
			left=&quot;110&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 3&quot;
			left=&quot;210&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 4&quot;
			left=&quot;310&quot; 
			top=&quot;13&quot; 
			right=&quot;10&quot; 
			bottom=&quot;10&quot;/&gt;
		
	&lt;/s:Group&gt;
&lt;/s:Application&gt;{/syntax}

In ActionScript, you can set element values directly as typed values. Make sure to use correct types when setting values by ActionScript mismatched types will give you errors at compilation and at runtime. In the following example a spark Button component is created and attributes are set using ActionScript:

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();

				//set some properties
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge dynamic s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into <del>&lt;s:Application&gt;</del><ins>the Application</ins>
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
&lt;/s:Application&gt;{/syntax}


 {COMMENTS}

</pre></description>
	</item>

	<item>
	  <title>Element Properties</title>
	  <pubDate>Mon, 26 Oct 2009 20:44:27 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Properties</link>
	  <description><pre id="diff">Element properties are very important in Flex MXML and ActionScript. In MXML they are set as attribute strings and child elements but at compile time are converted to typed values. 

Attribute string properties can support boolean values (&quot;true&quot; or &quot;false&quot;), numeric values ( &quot;1&quot;, &quot;2.5&quot;, &quot;#FF0000&quot;), string values (&quot;Duhhhh&quot;), bindings ( &quot;{ foo.text }&quot; ... more on this later )

Here is an example:
{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:Label  
			fontSize=&quot;30&quot;
			text=&quot;I am label with attribute properties!&quot;/&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;{/syntax}

With MXML elements you can specify values with much more complex structure. In this example we set values into a Spark DropDownList using the &lt;s:ArrayCollection&gt; and &lt;fx:String&gt; elements.

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:DropDownList&gt; 
			&lt;s:dataProvider&gt;
				&lt;s:ArrayCollection&gt;
					&lt;fx:String&gt;AK&lt;/fx:String&gt;
					&lt;fx:String&gt;AL&lt;/fx:String&gt;
					&lt;fx:String&gt;AR&lt;/fx:String&gt;
				&lt;/s:ArrayCollection&gt;
			&lt;/s:dataProvider&gt;
		&lt;/s:DropDownList&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;{/syntax}

The nested element model also supports inline graphics in Flex 4. Just as you can specify data for the dataProvider property, you can add graphics inline into an application. Here is a brief graphics example of Flex 4 using MXML nested elements. Look at the &lt;s:Rect&gt; element with nested stroke and fill:

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Group&gt;
		&lt;s:Rect 
			x=&quot;0&quot; y=&quot;0&quot; 
			radiusX=&quot;4&quot; 
			radiusY=&quot;4&quot; 
			height=&quot;100%&quot; 
			width=&quot;100%&quot;&gt;
			&lt;s:stroke&gt;
				&lt;s:LinearGradientStroke 
					weight=&quot;1&quot; 
					scaleMode=&quot;normal&quot;/&gt;
			&lt;/s:stroke&gt;
			&lt;s:fill&gt;
				&lt;s:LinearGradient&gt;
					&lt;s:entries&gt;
						&lt;mx:GradientEntry 
							color=&quot;0x999999&quot;/&gt;
					&lt;/s:entries&gt;
				&lt;/s:LinearGradient&gt;
			&lt;/s:fill&gt;
		&lt;/s:Rect&gt;        
		
		&lt;s:Button 
			label=&quot;Button 1&quot; 
			left=&quot;10&quot;
			top=&quot;13&quot;
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 2&quot;
			left=&quot;110&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 3&quot;
			left=&quot;210&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 4&quot;
			left=&quot;310&quot; 
			top=&quot;13&quot; 
			right=&quot;10&quot; 
			bottom=&quot;10&quot;/&gt;
		
	&lt;/s:Group&gt;
&lt;/s:Application&gt;{/syntax}

In ActionScript, you can set element values directly as typed values. Make sure to use correct types when setting values by ActionScript mismatched types will give you errors at compilation and at runtime. In the following example a spark Button component is created and attributes are set using ActionScript:

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();
<ins>
				//set some properties</ins>
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge dynamic s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into &lt;s:Application&gt;
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
&lt;/s:Application&gt;{/syntax}


 {COMMENTS}

</pre></description>
	</item>

	<item>
	  <title>addElement, addElementAt, removeElement, removeElementAt</title>
	  <pubDate>Mon, 26 Oct 2009 20:42:54 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=addElement%2C+addElementAt%2C+removeElement%2C+removeElementAt</link>
	  <description><pre id="diff">In Flex 4 to add or remove elements from containers, you need to use the element API: 

*addElement - Add an element into a container
*addElementAt - Add a element into a container at a certain depth location
*removeElement - Remove an element from a container
*removeElementAt - Remove an element from a container at a certain depth location

In Flex 3 and before, the low level addChild method was used to add or remove components from containers but in Flex 4 this is not the case. To add/remove a new element into an MXML component, you use it's &quot;id&quot; attribute and one of the above methods.

This simple example uses addElement and removeElementAt to give you an idea about how they work. The example adds a dynamically created button into a VGroup container using addElement and then allows you to remove the 2nd item using removeElementAt( 2 ).


{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

	&lt;fx:Script&gt;
		&lt;![CDATA[
			import spark.components.Button;
			import flash.utils.getTimer;
			
			protected function addElementClick( event:MouseEvent ):void
			{
<ins>
				//create a new button into temp variable 'bu'				</ins>
				var bu:Button = new Button();
<ins>
				//set the label property</ins>
				bu.label = &quot;Added with addElement! &quot; + getTimer();
<ins>
				//add the button into myGroup using the addElement method!</ins>
				myGroup.addElement( bu );
			}

			protected function removeElementClick( event:MouseEvent ):void
			{
<ins>
				//if there are more than 2 elements in the group</ins>
				if( myGroup.numChildren &gt; 2 ){
<ins>
					//remove the 2nd item in myGroup</ins>
					myGroup.removeElementAt( 2 );
<ins></ins>
				}
<ins></ins>
			}

		]]&gt;
	&lt;/fx:Script&gt;

	
	&lt;s:VGroup 
		id=&quot;myGroup&quot; 
		horizontalCenter=&quot;0&quot; 
		horizontalAlign=&quot;center&quot;&gt;
		
		&lt;s:Button 
			label=&quot;addElement&quot; 
			click=&quot;addElementClick( event )&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;removeElement&quot; 
			click=&quot;removeElementClick( event )&quot;/&gt;
		
	&lt;/s:VGroup&gt;
	
&lt;/s:Application&gt;{/syntax}

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>The Foundation of Flex - spark.components.Application</title>
	  <pubDate>Mon, 26 Oct 2009 20:38:11 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=The+Foundation+of+Flex+-+spark.components.Application</link>
	  <description><pre id="diff">&lt;s:Application&gt; ( spark.components.Application Class ) is the foundation of Flex 4. This single class contains a ton of logic from which you can build just about any type of software application. If you were building a house, &lt;s:Application&gt; would provide the concrete slab, electrical hookups, plumbing hookups, gas lines, meters all ready to go including any all the required construction permits. In this strange construction analogy, &lt;s:Application&gt; is also ideal if you were building a skyscraper, a small shed, or anything in between. The components and libraries within Flex are all dependent on &lt;s:Application&gt;, without the logic &lt;s:Application&gt; provides many things just wouldn't work. 

'''Example:'''
{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Label
		text=&quot;Learning Flex 4 from Scratch!&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}


'''Wait a second! What is up with the &quot;s:&quot; in &lt;s:Application&gt;?'''

That is the Spark namespace. In Flex 4 there are 2 component sets, Spark and '--Halo--' &quot;MX&quot; and these were divided into separate MXML namespaces to prevent confusion, avoid collision, and enable compatibility between versions of Flex. I will be focusing on Spark in this series although you can use &quot;MX&quot; components within a Spark application given component compatibility. 



Below are a few of the core features that &lt;s:Application&gt; provides:

'''Preloader''' - This shows download progress as your app loads and is customizable.

'''Framework Caching''' - This caches a signed version of the Flex Framework in Flash Player as a SWZ. This can optionally make your output SWF files very small. 

'''Component Instantiation''' - &lt;s:Application&gt; creates all application component instances on demand.

'''Layout and Resizing''' - &lt;s:Application&gt; lays out and resizes all components via LayoutManager.

'''Drag &amp; Drop''' - &lt;s:Application&gt; handles drag and drop interactions via DragManager.

'''Focus''' - &lt;s:Application&gt; handles focus for keyboard and mouse events via FocusManager

'''ToolTips and Popups''' - Any component that appears above others or needs modality is managed via PopUpManager or ToolTopManager in &lt;s:Application&gt;.

'''History''' - &lt;s:Application&gt; tracks history so that the browser back button has context via HistoryManager and BrowserManager.

'''Cursor''' - &lt;s:Application&gt; managed the cursor to show data loading via, you guessed it, CursorManager

'''System''' - &lt;s:Application&gt; also provides some deep voodoo that I do not understand in SystemManager. ( I think only Ely and Alex know what this really does! )

Managers can be found [here|http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/mx/managers/package-detail.html].

Atop all this goodness, &lt;s:Application&gt; also provides the infrastructure for <del>States.</del><ins>[States].</ins> States are my favorite Flex 4 feature and if you think you know States, hold onto your hat. States have been re-written in Flex 4 and are darn close to Ninja quality magic. Where I avoided States before, I now encourage you to dive in deep!

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>The Foundation of Flex - spark.components.Application</title>
	  <pubDate>Mon, 26 Oct 2009 20:36:23 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=The+Foundation+of+Flex+-+spark.components.Application</link>
	  <description><pre id="diff">&lt;s:Application&gt; ( spark.components.Application Class ) is the foundation of Flex 4. This single class contains a ton of logic from which you can build just about any type of software application. If you were building a house, &lt;s:Application&gt; would provide the concrete slab, electrical hookups, plumbing hookups, gas lines, meters all ready to go including any all the required construction permits. In this strange construction analogy, &lt;s:Application&gt; is also ideal if you were building a skyscraper, a small shed, or anything in between. The components and libraries within Flex are all dependent on &lt;s:Application&gt;, without the logic &lt;s:Application&gt; provides many things just wouldn't work. 
<ins>
'''Example:'''
{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Label
		text=&quot;Learning Flex 4 from Scratch!&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}
</ins>

'''Wait a second! What is up with the &quot;s:&quot; in &lt;s:Application&gt;?'''

That is the Spark namespace. In Flex 4 there are 2 component sets, Spark and '--Halo--' &quot;MX&quot; and these were divided into separate MXML namespaces to prevent confusion, avoid collision, and enable compatibility between versions of Flex. I will be focusing on Spark in this series although you can use &quot;MX&quot; components within a Spark application given component compatibility. 
<ins>
</ins>

Below are a few of the core features that &lt;s:Application&gt; provides:

'''Preloader''' - This shows download progress as your app loads and is customizable.

'''Framework Caching''' - This caches a signed version of the Flex Framework in Flash Player as a SWZ. This can optionally make your output SWF files very small. 

'''Component Instantiation''' - &lt;s:Application&gt; creates all application component instances on demand.

'''Layout and Resizing''' - &lt;s:Application&gt; lays out and resizes all components via LayoutManager.

'''Drag &amp; Drop''' - &lt;s:Application&gt; handles drag and drop interactions via DragManager.

'''Focus''' - &lt;s:Application&gt; handles focus for keyboard and mouse events via FocusManager

'''ToolTips and Popups''' - Any component that appears above others or needs modality is managed via PopUpManager or ToolTopManager in &lt;s:Application&gt;.

'''History''' - &lt;s:Application&gt; tracks history so that the browser back button has context via HistoryManager and BrowserManager.

'''Cursor''' - &lt;s:Application&gt; managed the cursor to show data loading via, you guessed it, CursorManager

'''System''' - &lt;s:Application&gt; also provides some deep voodoo that I do not understand in SystemManager. ( I think only Ely and Alex know what this really does! )

Managers can be found [here|http://help.adobe.com/en_US/FlashPlatform/beta/reference/actionscript/3/mx/managers/package-detail.html].

Atop all this goodness, &lt;s:Application&gt; also provides the infrastructure for States. States are my favorite Flex 4 feature and if you think you know States, hold onto your hat. States have been re-written in Flex 4 and are darn close to Ninja quality magic. Where I avoided States before, I now encourage you to dive in deep!

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Mon, 26 Oct 2009 20:35:04 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].



!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
<del>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</del>
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}




!!'''Outline:'''
*[What is Flex?|What is Flex?]
*[Languages of Flex (MXML &amp; ActionScript 3)|Languages of Flex]
*[The Foundation of Flex - spark.components.Application|The Foundation of Flex - spark.components.Application]
*[MXML Namespaces|MXML Namespaces]
*[spark.components.Application Events|spark.components.Application Events]
*[Element Creation|Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt|addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties|Element Properties]
*[States|States]
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learning Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>Languages of Flex</title>
	  <pubDate>Mon, 26 Oct 2009 20:32:33 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Languages+of+Flex</link>
	  <description><pre id="diff">Flex has 2 languages, MXML and ActionScript 3. 

MXML is a dialect of XML designed for component layout, <del>instantiation</del><ins>instantiation,</ins> and, new to Flex 4, graphics. Flex 4 adds a new dialect of MXML called FXG (Flash XML Graphics). FXG allows you to draw with declarative markup and is used extensively for skinning and other mayhem. Just think about FXG as new graphics tags and you are set.

ActionScript 3 is based on ECMAScript but adds support for Classes and Namespaces. If you have worked with a Class based language (Java, C#) or a dynamic language (Python, JavaScript), you will find ActionScript easy to work with. 

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Mon, 26 Oct 2009 20:31:09 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].
<ins></ins>


!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}
<ins></ins>



!!'''Outline:'''
*[What is Flex?|What is Flex?]
*[Languages of Flex (MXML &amp; ActionScript 3)|Languages of Flex]
*[The Foundation of Flex - spark.components.Application|The Foundation of Flex - spark.components.Application]
*[MXML Namespaces|MXML Namespaces]
*[spark.components.Application Events|spark.components.Application Events]
*[Element Creation|Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt|addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties|Element Properties]
*[States|States]
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learning Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Mon, 26 Oct 2009 20:30:50 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].
<ins></ins>

!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
<ins>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;</ins>
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
<del>		click=&quot;showLabel.text='Learning Flex 4 from Scratch!'&quot;/&gt;</del><ins>		click=&quot;showLabel.visible=!showLabel.visible&quot;/&gt;</ins>
	
	&lt;s:Label
		id=&quot;showLabel&quot;
<ins>		text=&quot;Learning Flex 4 from Scratch!&quot;
		visible=&quot;false&quot;</ins>
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}
<ins></ins>


!!'''Outline:'''
*[What is Flex?|What is Flex?]
*[Languages of Flex (MXML &amp; ActionScript 3)|Languages of Flex]
*[The Foundation of Flex - spark.components.Application|The Foundation of Flex - spark.components.Application]
*[MXML Namespaces|MXML Namespaces]
*[spark.components.Application Events|spark.components.Application Events]
*[Element Creation|Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt|addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties|Element Properties]
*[States|States]
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???
<del></del>



!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learning Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>Home</title>
	  <pubDate>Mon, 26 Oct 2009 20:03:44 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Home</link>
	  <description><pre id="diff">Welcome to '''Learn Fx4 from Scratch''', this wiki will attempt to cover Flex 4 from beginning to end from a developer perspective. 

!!'''I assume you...'''
* ... know nothing about Flex.
* ... have programming experience.
* ... know XML, we will be seeing lots of it.
* ... have downloaded and installed [Flash Builder 4 Beta 2|http://www.adobe.com/cfusion/entitlement/index.cfm?e=labs_flashbuilder4].
<ins>
!!'''Hello World:'''

{syntax mxml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button 
		label=&quot;Click Me!&quot;
		height=&quot;100&quot; width=&quot;200&quot;
		fontSize=&quot;20&quot;
		horizontalCenter=&quot;0&quot; top=&quot;50&quot;
		click=&quot;showLabel.text='Learning Flex 4 from Scratch!'&quot;/&gt;
	
	&lt;s:Label
		id=&quot;showLabel&quot;
		fontSize=&quot;40&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;/&gt;

&lt;/s:Application&gt;{/syntax}</ins>


!!'''Outline:'''
*[What is Flex?|What is Flex?]
*[Languages of Flex (MXML &amp; ActionScript 3)|Languages of Flex]
*[The Foundation of Flex - spark.components.Application|The Foundation of Flex - spark.components.Application]
*[MXML Namespaces|MXML Namespaces]
*[spark.components.Application Events|spark.components.Application Events]
*[Element Creation|Element Creation]
*[addElement, addElementAt, removeElement, removeElementAt|addElement, addElementAt, removeElement, removeElementAt]
*[Element Properties|Element Properties]
*[States|States]
*ID Attribute
*MXML is AS3!
*&lt;fx:Script/&gt;
*Using Components
*Containers and Layout
*Graphics &amp; FXG
*Spark Skinning
*Custom Components
*Data, Data, Data
*???




!!'''Why?'''
Somehow after a year working as Community Manager at Adobe, I found myself needing to learn Flex all over again '''from Scratch'''. To help me learn Flex 4, I decided to create this wiki in parallel as I learn. As I publish new pages in the wiki, I am learning too. Hopefully many will find the end result valuable. 

I hope you enjoy '''Learning Flex 4 from Scratch'''!

Cheers,

'''ted ;)'''
</pre></description>
	</item>

	<item>
	  <title>States</title>
	  <pubDate>Mon, 26 Oct 2009 19:53:09 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=States</link>
	  <description><pre id="diff">The States feature has changed wildly in Flex 4 and is my favorite feature of the release.

'''What is a State?'''
In Flex, a state is a series of property values associated with a state name. When the state is set, all the values within the state are applied in bulk. States are a very handy way to organize your application as changing from different views within your application is typically managed by changing many properties all at once. By using the states feature you only need to set the value of '''currentState''' to the state name you define.

Here is a simple States example. In the example I define 3 states named &quot;One&quot; &quot;Two&quot; &quot;Three&quot; and navigate between them with 3 buttons:

{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
&lt;/s:Application&gt;{/syntax}

'''Wow, that was boring!''' 

The prior example worked perfectly but we didn't set any state property values so it wasn't that exciting. In Flex 4 the syntax for State property values changed. Before Flex 4, all state properties were set within the &lt;s:State&gt; component but now you can additionally set state values on the components they affect. This makes understanding the effect of state changes much easier to see and work with. Since states affect properties, the new syntax extends the existing dot notation property syntax like so:

{syntax <del>xml}&lt;s:Label</del><ins>mxml}&lt;s:Label</ins> 
	text.One = &quot;One&quot; 
	text.Two = &quot;Two&quot; 
	text.Three = &quot;Three&quot; /&gt;{/syntax}

Notice that the 'text' value has a different value for each state. Whenever the state changes, the value of the &quot;text&quot; property will change if a property is specified for the state change. If we were to set &quot;currentState='foo'&quot;, since there isn't a property value designated, the value would remain depending on which state had fired prior.

'''''HINT: In FB4 states have code hinting if you define the &lt;s:states&gt; tag first!'''''

Here is the above example complete:
{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
	&lt;s:Label
		text.One = &quot;One&quot; 
		text.Two = &quot;Two&quot; 
		text.Three = &quot;Three&quot;
		horizontalCenter=&quot;0&quot;
		top=&quot;50&quot;
		fontSize=&quot;40&quot;
		/&gt;
	
&lt;/s:Application&gt;{/syntax}

Enough of this simple stuff, lets get crazy with States! Lets add a Panel, set its title value and resize it using States. Also note that the state buttons are disabled when a state is selected! That is a ton of logic that you didn't need to write and is just the tip of the iceberg in using States.

{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:Panel
	 	resizeEffect=&quot;Resize&quot;
		title.One=&quot;One&quot;
		title.Two=&quot;Two&quot;
		title.Three=&quot;Three&quot;
		width.One=&quot;800&quot;
		width.Two=&quot;200&quot;
		width.Three=&quot;400&quot;
		height.One=&quot;400&quot;
		height.Two=&quot;600&quot;
		height.Three=&quot;200&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;
		&gt;
		
		&lt;s:Label
			text.One=&quot;One&quot; 
			text.Two=&quot;Two&quot; 
			text.Three=&quot;Three&quot;
			horizontalCenter=&quot;0&quot;
			verticalCenter=&quot;0&quot;
			fontSize=&quot;40&quot;
			/&gt;

	&lt;/s:Panel&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot;
			enabled.One=&quot;false&quot;
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			enabled.Two=&quot;false&quot;
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot;
			enabled.Three=&quot;false&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
&lt;/s:Application&gt;{/syntax}

What I really like is just how readable this code is and how you can make changes to States code easily. Not only is this great for in app State use but States are an essential part of skinning in Flex. &lt;s:Button&gt; has 4 states and simply implementing different graphics per state will dramatically alter the look and feel.

In Flash Catalyst, states are used extensively and the code they generate is a powerful way to learn both Flex Skinning and using States within application development.

&quot;States in Flex 4 are ninja quality magic!&quot; - Ted :)

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>Element Properties</title>
	  <pubDate>Mon, 26 Oct 2009 19:52:14 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Properties</link>
	  <description><pre id="diff">Element properties are very important in Flex MXML and ActionScript. In MXML they are set as attribute strings and child elements but at compile time are converted to typed values. 

Attribute string properties can support boolean values (&quot;true&quot; or &quot;false&quot;), numeric values ( &quot;1&quot;, &quot;2.5&quot;, &quot;#FF0000&quot;), string values (&quot;Duhhhh&quot;), bindings ( &quot;{ foo.text }&quot; ... more on this later )

Here is an example:
{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:Label  
			fontSize=&quot;30&quot;
			text=&quot;I am label with attribute properties!&quot;/&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;{/syntax}

With MXML elements you can specify values with much more complex structure. In this example we set values into a Spark DropDownList using the &lt;s:ArrayCollection&gt; and &lt;fx:String&gt; elements.

{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:DropDownList&gt; 
			&lt;s:dataProvider&gt;
				&lt;s:ArrayCollection&gt;
					&lt;fx:String&gt;AK&lt;/fx:String&gt;
					&lt;fx:String&gt;AL&lt;/fx:String&gt;
					&lt;fx:String&gt;AR&lt;/fx:String&gt;
				&lt;/s:ArrayCollection&gt;
			&lt;/s:dataProvider&gt;
		&lt;/s:DropDownList&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;{/syntax}

The nested element model also supports inline graphics in Flex 4. Just as you can specify data for the dataProvider property, you can add graphics inline into an application. Here is a brief graphics example of Flex 4 using MXML nested elements. Look at the &lt;s:Rect&gt; element with nested stroke and fill:

{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Group&gt;
		&lt;s:Rect 
			x=&quot;0&quot; y=&quot;0&quot; 
			radiusX=&quot;4&quot; 
			radiusY=&quot;4&quot; 
			height=&quot;100%&quot; 
			width=&quot;100%&quot;&gt;
			&lt;s:stroke&gt;
				&lt;s:LinearGradientStroke 
					weight=&quot;1&quot; 
					scaleMode=&quot;normal&quot;/&gt;
			&lt;/s:stroke&gt;
			&lt;s:fill&gt;
				&lt;s:LinearGradient&gt;
					&lt;s:entries&gt;
						&lt;mx:GradientEntry 
							color=&quot;0x999999&quot;/&gt;
					&lt;/s:entries&gt;
				&lt;/s:LinearGradient&gt;
			&lt;/s:fill&gt;
		&lt;/s:Rect&gt;        
		
		&lt;s:Button 
			label=&quot;Button 1&quot; 
			left=&quot;10&quot;
			top=&quot;13&quot;
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 2&quot;
			left=&quot;110&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 3&quot;
			left=&quot;210&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 4&quot;
			left=&quot;310&quot; 
			top=&quot;13&quot; 
			right=&quot;10&quot; 
			bottom=&quot;10&quot;/&gt;
		
	&lt;/s:Group&gt;
&lt;/s:Application&gt;{/syntax}

In ActionScript, you can set element values directly as typed values. Make sure to use correct types when setting values by ActionScript mismatched types will give you errors at compilation and at runtime. In the following example a spark Button component is created and attributes are set using ActionScript:

{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge dynamic s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into &lt;s:Application&gt;
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
&lt;/s:Application&gt;{/syntax}


 {COMMENTS}

</pre></description>
	</item>

	<item>
	  <title>addElement, addElementAt, removeElement, removeElementAt</title>
	  <pubDate>Mon, 26 Oct 2009 19:51:32 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=addElement%2C+addElementAt%2C+removeElement%2C+removeElementAt</link>
	  <description><pre id="diff">In Flex 4 to add or remove elements from containers, you need to use the element API: 

*addElement - Add an element into a container
*addElementAt - Add a element into a container at a certain depth location
*removeElement - Remove an element from a container
*removeElementAt - Remove an element from a container at a certain depth location

In Flex 3 and before, the low level addChild method was used to add or remove components from containers but in Flex 4 this is not the case. To add/remove a new element into an MXML component, you use it's &quot;id&quot; attribute and one of the above methods.

This simple example uses addElement and removeElementAt to give you an idea about how they work. The example adds a dynamically created button into a VGroup container using addElement and then allows you to remove the 2nd item using removeElementAt( 2 ).


{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

	&lt;fx:Script&gt;
		&lt;![CDATA[
			import spark.components.Button;
			import flash.utils.getTimer;
			
			protected function addElementClick( event:MouseEvent ):void
			{
				var bu:Button = new Button();
				bu.label = &quot;Added with addElement! &quot; + getTimer();
				myGroup.addElement( bu );
			}

			protected function removeElementClick( event:MouseEvent ):void
			{
				if( myGroup.numChildren &gt; 2 ){
					myGroup.removeElementAt( 2 );
				}
			}

		]]&gt;
	&lt;/fx:Script&gt;

	
	&lt;s:VGroup 
		id=&quot;myGroup&quot; 
		horizontalCenter=&quot;0&quot; 
		horizontalAlign=&quot;center&quot;&gt;
		
		&lt;s:Button 
			label=&quot;addElement&quot; 
			click=&quot;addElementClick( event )&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;removeElement&quot; 
			click=&quot;removeElementClick( event )&quot;/&gt;
		
	&lt;/s:VGroup&gt;
	
&lt;/s:Application&gt;{/syntax}

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>Element Creation</title>
	  <pubDate>Mon, 26 Oct 2009 19:50:59 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Creation</link>
	  <description><pre id="diff">In Flex there are 2 ways to create elements, MXML and ActionScript.

In MXML simply adding a tag will create an instance and add it into the &lt;s:Application&gt; all at once. Here is an example of creating a Spark Button in MXML:


{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button
		left=&quot;25&quot;
		right=&quot;25&quot;
		top=&quot;25&quot;
		bottom=&quot;25&quot;
		label=&quot;Huge s:Button positioned 25px from all sides of s:Application!&quot;/&gt;
	
&lt;/s:Application&gt;{/syntax}

MXML handles creating the &lt;s:button&gt; instance, setting properties declared as attributes (left, top, label, etc), and adding it into the &lt;s:Application&gt; instance.

Sometimes you want to create component instances in ActionScript. To do this you need to import spark.components.Button, create an instance using '''new''', set some properties, and use the addElement method to add the button into &lt;s:Application&gt;. Here is the example:


{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into &lt;s:Application&gt;
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
&lt;/s:Application&gt;{/syntax}

The above two applications are identical in their output but the later example adds the Button dynamically. There are use cases where each technique is valuable to know and understand. Sometimes MXML is easier and sometime AS is easier. Actually in a later section I will show you how to leverage the best of both because MXML and ActionScript are very closely related, if not identical. 

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>spark.components.Application Events</title>
	  <pubDate>Mon, 26 Oct 2009 19:50:30 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=spark.components.Application+Events</link>
	  <description><pre id="diff"></pre></description>
	</item>

	<item>
	  <title>spark.components.Application Events</title>
	  <pubDate>Mon, 26 Oct 2009 19:48:38 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=spark.components.Application+Events</link>
	  <description><pre id="diff">When an application starts, there are a series of events in &lt;s:Application&gt; that you can listen for. Listening for events in MXML is simple as you just add attributes to MXML like so:


{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
       xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
       xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot; 
       preinitialize=&quot;trace('preinitialize')&quot;
       initialize=&quot;trace('initialize')&quot; 
       creationComplete=&quot;trace('creationComplete')&quot; 
       applicationComplete=&quot;trace('applicationComplete')&quot;&gt;

&lt;/s:Application&gt;{/syntax}

When an xml attribute is an event, the code between quotes is ActionScript. So the above code will trace when run in debug (Press the green bug in Flash Builder and trace will send text to the Console! Simple and effective tracing). The events in this example are important as they occur in a certain order:

'''preinitialize''' - This happens just before child components are initialized and created
'''initialize''' - This happens after child components are initialized.
'''creationComplete''' - This happens after child components are created.
'''applicationComplete''' - This happens last and marks the start of your application running.

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>MXML Namespaces</title>
	  <pubDate>Mon, 26 Oct 2009 19:48:12 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=MXML+Namespaces</link>
	  <description><pre id="diff">At the start of every MXML document, there are a few xml namespaces defined, where it says &quot;xmlns:&quot; below. 

{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
      xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
      xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

&lt;/s:Application&gt;{/syntax}

Here are the important parts:
xmlns:fx = &quot;http://ns.adobe.com/mxml/2009&quot;

The &quot;fx&quot; above maps all component to &quot;http://ns.adobe.com/mxml/2009&quot; so if you see: &lt;fx:Script&gt; or &lt;fx:Declarations&gt; these tags are defined for import here &quot;http://ns.adobe.com/mxml/2009&quot;. 

Flex comes with some predefined namespaces:

Core Flex: http://ns.adobe.com/mxml/2009
Spark Components: library://ns.adobe.com/flex/spark
Halo &quot;MX&quot; Components: library://ns.adobe.com/flex/halo

Namespaces are quite flexible and you can define them how you want, this even works:

{syntax <del>xml}&lt;?xml</del><ins>mxml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;sparkrocks:Application 
        xmlns:flexrocks=&quot;http://ns.adobe.com/mxml/2009&quot; 
        xmlns:sparkrocks=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

       &lt;sparkrocks:Button 
              label=&quot;Hello World&quot;/&gt;

&lt;/sparkrocks:Application&gt;{/syntax}


When we get to custom components we will revisit XML Namespaces in Flex 4 as they are key to importing custom code.

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>States</title>
	  <pubDate>Mon, 26 Oct 2009 19:27:16 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=States</link>
	  <description><pre id="diff">The States feature has changed wildly in Flex 4 and is my favorite feature of the release.

'''What is a State?'''
In Flex, a state is a series of property values associated with a state name. When the state is set, all the values within the state are applied in bulk. States are a very handy way to organize your application as changing from different views within your application is typically managed by changing many properties all at once. By using the states feature you only need to set the value of '''currentState''' to the state name you define.

Here is a simple States example. In the example I define 3 states named &quot;One&quot; &quot;Two&quot; &quot;Three&quot; and navigate between them with 3 buttons:

{syntax xml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
&lt;/s:Application&gt;{/syntax}

'''Wow, that was boring!''' 

The prior example worked perfectly but we didn't set any state property values so it wasn't that exciting. In Flex 4 the syntax for State property values changed. Before Flex 4, all state properties were set within the &lt;s:State&gt; component but now you can additionally set state values on the components they affect. This makes understanding the effect of state changes much easier to see and work with. Since states affect properties, the new syntax extends the existing dot notation property syntax like so:

{syntax xml}&lt;s:Label 
	text.One = &quot;One&quot; 
	text.Two = &quot;Two&quot; 
	text.Three = &quot;Three&quot; /&gt;{/syntax}

Notice that the 'text' value has a different value for each state. Whenever the state changes, the value of the &quot;text&quot; property will change if a property is specified for the state change. If we were to set &quot;currentState='foo'&quot;, since there isn't a property value designated, the value would remain depending on which state had fired prior.

'''''HINT: In FB4 states have code hinting if you define the &lt;s:states&gt; tag first!'''''

Here is the above example complete:
<del>{/syntax}&lt;?xml</del><ins>{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
	&lt;s:Label
		text.One = &quot;One&quot; 
		text.Two = &quot;Two&quot; 
		text.Three = &quot;Three&quot;
		horizontalCenter=&quot;0&quot;
		top=&quot;50&quot;
		fontSize=&quot;40&quot;
		/&gt;
	
&lt;/s:Application&gt;{/syntax}

Enough of this simple stuff, lets get crazy with States! Lets add a Panel, set its title value and resize it using States. Also note that the state buttons are disabled when a state is selected! That is a ton of logic that you didn't need to write and is just the tip of the iceberg in using States.

{syntax xml}&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:Panel
	 	resizeEffect=&quot;Resize&quot;
		title.One=&quot;One&quot;
		title.Two=&quot;Two&quot;
		title.Three=&quot;Three&quot;
		width.One=&quot;800&quot;
		width.Two=&quot;200&quot;
		width.Three=&quot;400&quot;
		height.One=&quot;400&quot;
		height.Two=&quot;600&quot;
		height.Three=&quot;200&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;
		&gt;
		
		&lt;s:Label
			text.One=&quot;One&quot; 
			text.Two=&quot;Two&quot; 
			text.Three=&quot;Three&quot;
			horizontalCenter=&quot;0&quot;
			verticalCenter=&quot;0&quot;
			fontSize=&quot;40&quot;
			/&gt;

	&lt;/s:Panel&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot;
			enabled.One=&quot;false&quot;
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			enabled.Two=&quot;false&quot;
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot;
			enabled.Three=&quot;false&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
&lt;/s:Application&gt;{/syntax}

What I really like is just how readable this code is and how you can make changes to States code easily. Not only is this great for in app State use but States are an essential part of skinning in Flex. &lt;s:Button&gt; has 4 states and simply implementing different graphics per state will dramatically alter the look and feel.

In Flash Catalyst, states are used extensively and the code they generate is a powerful way to learn both Flex Skinning and using States within application development.

&quot;States in Flex 4 are ninja quality magic!&quot; - Ted :)

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>States</title>
	  <pubDate>Mon, 26 Oct 2009 19:26:28 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=States</link>
	  <description><pre id="diff">The States feature has changed wildly in Flex 4 and is my favorite feature of the release.

'''What is a State?'''
In Flex, a state is a series of property values associated with a state name. When the state is set, all the values within the state are applied in bulk. States are a very handy way to organize your application as changing from different views within your application is typically managed by changing many properties all at once. By using the states feature you only need to set the value of '''currentState''' to the state name you define.

Here is a simple States example. In the example I define 3 states named &quot;One&quot; &quot;Two&quot; &quot;Three&quot; and navigate between them with 3 buttons:

<del>{{&lt;?xml</del><ins>{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

'''Wow, that was boring!''' 

The prior example worked perfectly but we didn't set any state property values so it wasn't that exciting. In Flex 4 the syntax for State property values changed. Before Flex 4, all state properties were set within the &lt;s:State&gt; component but now you can additionally set state values on the components they affect. This makes understanding the effect of state changes much easier to see and work with. Since states affect properties, the new syntax extends the existing dot notation property syntax like so:

<del>{{&lt;s:Label</del><ins>{syntax xml}&lt;s:Label</ins> 
	text.One = &quot;One&quot; 
	text.Two = &quot;Two&quot; 
	text.Three = &quot;Three&quot; <del>/&gt;}}</del><ins>/&gt;{/syntax}</ins>

Notice that the 'text' value has a different value for each state. Whenever the state changes, the value of the &quot;text&quot; property will change if a property is specified for the state change. If we were to set &quot;currentState='foo'&quot;, since there isn't a property value designated, the value would remain depending on which state had fired prior.

'''''HINT: In FB4 states have code hinting if you define the &lt;s:states&gt; tag first!'''''

Here is the above example complete:
<del>{{&lt;?xml</del><ins>{/syntax}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
	&lt;s:Label
		text.One = &quot;One&quot; 
		text.Two = &quot;Two&quot; 
		text.Three = &quot;Three&quot;
		horizontalCenter=&quot;0&quot;
		top=&quot;50&quot;
		fontSize=&quot;40&quot;
		/&gt;
	
<del>&lt;/s:Application&gt;
}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

Enough of this simple stuff, lets get crazy with States! Lets add a Panel, set its title value and resize it using States. Also note that the state buttons are disabled when a state is selected! That is a ton of logic that you didn't need to write and is just the tip of the iceberg in using States.

<del>{{&lt;?xml</del><ins>{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:Panel
	 	resizeEffect=&quot;Resize&quot;
		title.One=&quot;One&quot;
		title.Two=&quot;Two&quot;
		title.Three=&quot;Three&quot;
		width.One=&quot;800&quot;
		width.Two=&quot;200&quot;
		width.Three=&quot;400&quot;
		height.One=&quot;400&quot;
		height.Two=&quot;600&quot;
		height.Three=&quot;200&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;
		&gt;
		
		&lt;s:Label
			text.One=&quot;One&quot; 
			text.Two=&quot;Two&quot; 
			text.Three=&quot;Three&quot;
			horizontalCenter=&quot;0&quot;
			verticalCenter=&quot;0&quot;
			fontSize=&quot;40&quot;
			/&gt;

	&lt;/s:Panel&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot;
			enabled.One=&quot;false&quot;
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			enabled.Two=&quot;false&quot;
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot;
			enabled.Three=&quot;false&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
<del>&lt;/s:Application&gt;
}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

What I really like is just how readable this code is and how you can make changes to States code easily. Not only is this great for in app State use but States are an essential part of skinning in Flex. &lt;s:Button&gt; has 4 states and simply implementing different graphics per state will dramatically alter the look and feel.

In Flash Catalyst, states are used extensively and the code they generate is a powerful way to learn both Flex Skinning and using States within application development.

&quot;States in Flex 4 are ninja quality magic!&quot; - Ted :)

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>Element Properties</title>
	  <pubDate>Mon, 26 Oct 2009 19:25:11 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Properties</link>
	  <description><pre id="diff">Element properties are very important in Flex MXML and ActionScript. In MXML they are set as attribute strings and child elements but at compile time are converted to typed values. 

Attribute string properties can support boolean values (&quot;true&quot; or &quot;false&quot;), numeric values ( &quot;1&quot;, &quot;2.5&quot;, &quot;#FF0000&quot;), string values (&quot;Duhhhh&quot;), bindings ( &quot;{ foo.text }&quot; ... more on this later )

Here is an example:
<del>{{&lt;?xml</del><ins>{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:Label  
			fontSize=&quot;30&quot;
			text=&quot;I am label with attribute properties!&quot;/&gt;
		
	&lt;/s:VGroup&gt;
		
<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

With MXML elements you can specify values with much more complex structure. In this example we set values into a Spark DropDownList using the &lt;s:ArrayCollection&gt; and &lt;fx:String&gt; elements.

<del>{{&lt;?xml</del><ins>{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:DropDownList&gt; 
			&lt;s:dataProvider&gt;
				&lt;s:ArrayCollection&gt;
					&lt;fx:String&gt;AK&lt;/fx:String&gt;
					&lt;fx:String&gt;AL&lt;/fx:String&gt;
					&lt;fx:String&gt;AR&lt;/fx:String&gt;
				&lt;/s:ArrayCollection&gt;
			&lt;/s:dataProvider&gt;
		&lt;/s:DropDownList&gt;
		
	&lt;/s:VGroup&gt;
		
<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

The nested element model also supports inline graphics in Flex 4. Just as you can specify data for the dataProvider property, you can add graphics inline into an application. Here is a brief graphics example of Flex 4 using MXML nested elements. Look at the &lt;s:Rect&gt; element with nested stroke and fill:

<del>{{&lt;?xml</del><ins>{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Group&gt;
		&lt;s:Rect 
			x=&quot;0&quot; y=&quot;0&quot; 
			radiusX=&quot;4&quot; 
			radiusY=&quot;4&quot; 
			height=&quot;100%&quot; 
			width=&quot;100%&quot;&gt;
			&lt;s:stroke&gt;
				&lt;s:LinearGradientStroke 
					weight=&quot;1&quot; 
					scaleMode=&quot;normal&quot;/&gt;
			&lt;/s:stroke&gt;
			&lt;s:fill&gt;
				&lt;s:LinearGradient&gt;
					&lt;s:entries&gt;
						&lt;mx:GradientEntry 
							color=&quot;0x999999&quot;/&gt;
					&lt;/s:entries&gt;
				&lt;/s:LinearGradient&gt;
			&lt;/s:fill&gt;
		&lt;/s:Rect&gt;        
		
		&lt;s:Button 
			label=&quot;Button 1&quot; 
			left=&quot;10&quot;
			top=&quot;13&quot;
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 2&quot;
			left=&quot;110&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 3&quot;
			left=&quot;210&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 4&quot;
			left=&quot;310&quot; 
			top=&quot;13&quot; 
			right=&quot;10&quot; 
			bottom=&quot;10&quot;/&gt;
		
	&lt;/s:Group&gt;
<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

In ActionScript, you can set element values directly as typed values. Make sure to use correct types when setting values by ActionScript mismatched types will give you errors at compilation and at runtime. In the following example a spark Button component is created and attributes are set using ActionScript:

<del>{{&lt;?xml</del><ins>{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge dynamic s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into &lt;s:Application&gt;
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>


 {COMMENTS}

</pre></description>
	</item>

	<item>
	  <title>addElement, addElementAt, removeElement, removeElementAt</title>
	  <pubDate>Mon, 26 Oct 2009 19:24:02 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=addElement%2C+addElementAt%2C+removeElement%2C+removeElementAt</link>
	  <description><pre id="diff">In Flex 4 to add or remove elements from containers, you need to use the element API: 

*addElement - Add an element into a container
*addElementAt - Add a element into a container at a certain depth location
*removeElement - Remove an element from a container
*removeElementAt - Remove an element from a container at a certain depth location

In Flex 3 and before, the low level addChild method was used to add or remove components from containers but in Flex 4 this is not the case. To add/remove a new element into an MXML component, you use it's &quot;id&quot; attribute and one of the above methods.

This simple example uses addElement and removeElementAt to give you an idea about how they work. The example adds a dynamically created button into a VGroup container using addElement and then allows you to remove the 2nd item using removeElementAt( 2 ).


<del>{{&lt;?xml</del><ins>{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

	&lt;fx:Script&gt;
		&lt;![CDATA[
			import spark.components.Button;
			import flash.utils.getTimer;
			
			protected function addElementClick( event:MouseEvent ):void
			{
				var bu:Button = new Button();
				bu.label = &quot;Added with addElement! &quot; + getTimer();
				myGroup.addElement( bu );
			}

			protected function removeElementClick( event:MouseEvent ):void
			{
				if( myGroup.numChildren &gt; 2 ){
					myGroup.removeElementAt( 2 );
				}
			}

		]]&gt;
	&lt;/fx:Script&gt;

	
	&lt;s:VGroup 
		id=&quot;myGroup&quot; 
		horizontalCenter=&quot;0&quot; 
		horizontalAlign=&quot;center&quot;&gt;
		
		&lt;s:Button 
			label=&quot;addElement&quot; 
			click=&quot;addElementClick( event )&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;removeElement&quot; 
			click=&quot;removeElementClick( event )&quot;/&gt;
		
	&lt;/s:VGroup&gt;
	
<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>Element Creation</title>
	  <pubDate>Mon, 26 Oct 2009 19:23:06 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Creation</link>
	  <description><pre id="diff">In Flex there are 2 ways to create elements, MXML and ActionScript.

In MXML simply adding a tag will create an instance and add it into the &lt;s:Application&gt; all at once. Here is an example of creating a Spark Button in MXML:

<del>{{&lt;?xml</del><ins>
{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button
		left=&quot;25&quot;
		right=&quot;25&quot;
		top=&quot;25&quot;
		bottom=&quot;25&quot;
		label=&quot;Huge s:Button positioned 25px from all sides of s:Application!&quot;/&gt;
	
<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

MXML handles creating the &lt;s:button&gt; instance, setting properties declared as attributes (left, top, label, etc), and adding it into the &lt;s:Application&gt; instance.

Sometimes you want to create component instances in ActionScript. To do this you need to import spark.components.Button, create an instance using '''new''', set some properties, and use the addElement method to add the button into &lt;s:Application&gt;. Here is the example:

<del>{{&lt;?xml</del><ins>
{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into &lt;s:Application&gt;
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

The above two applications are identical in their output but the later example adds the Button dynamically. There are use cases where each technique is valuable to know and understand. Sometimes MXML is easier and sometime AS is easier. Actually in a later section I will show you how to leverage the best of both because MXML and ActionScript are very closely related, if not identical. 

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>spark.components.Application Events</title>
	  <pubDate>Mon, 26 Oct 2009 19:22:03 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=spark.components.Application+Events</link>
	  <description><pre id="diff">When an application starts, there are a series of events in &lt;s:Application&gt; that you can listen for. Listening for events in MXML is simple as you just add attributes to MXML like so:

<del>{{&lt;?xml</del><ins>
{syntax xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
       xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
       xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot; 
       preinitialize=&quot;trace('preinitialize')&quot;
       initialize=&quot;trace('initialize')&quot; 
       creationComplete=&quot;trace('creationComplete')&quot; 
       applicationComplete=&quot;trace('applicationComplete')&quot;&gt;

<del>&lt;/s:Application&gt;
}}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

When an xml attribute is an event, the code between quotes is ActionScript. So the above code will trace when run in debug (Press the green bug in Flash Builder and trace will send text to the Console! Simple and effective tracing). The events in this example are important as they occur in a certain order:

'''preinitialize''' - This happens just before child components are initialized and created
'''initialize''' - This happens after child components are initialized.
'''creationComplete''' - This happens after child components are created.
'''applicationComplete''' - This happens last and marks the start of your application running.

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>MXML Namespaces</title>
	  <pubDate>Mon, 26 Oct 2009 19:20:43 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=MXML+Namespaces</link>
	  <description><pre id="diff">At the start of every MXML document, there are a few xml namespaces defined, where it says &quot;xmlns:&quot; below. 

{syntax <del>xml}
&lt;?xml</del><ins>xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
      xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
      xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

<del>&lt;/s:Application&gt;
{/syntax}</del><ins>&lt;/s:Application&gt;{/syntax}</ins>

Here are the important parts:
xmlns:fx = &quot;http://ns.adobe.com/mxml/2009&quot;

The &quot;fx&quot; above maps all component to &quot;http://ns.adobe.com/mxml/2009&quot; so if you see: &lt;fx:Script&gt; or &lt;fx:Declarations&gt; these tags are defined for import here &quot;http://ns.adobe.com/mxml/2009&quot;. 

Flex comes with some predefined namespaces:

Core Flex: http://ns.adobe.com/mxml/2009
Spark Components: library://ns.adobe.com/flex/spark
Halo &quot;MX&quot; Components: library://ns.adobe.com/flex/halo

Namespaces are quite flexible and you can define them how you want, this even works:

{syntax <del>xml}
&lt;?xml</del><ins>xml}&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;sparkrocks:Application 
        xmlns:flexrocks=&quot;http://ns.adobe.com/mxml/2009&quot; 
        xmlns:sparkrocks=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

       &lt;sparkrocks:Button 
              label=&quot;Hello World&quot;/&gt;

<del>&lt;/sparkrocks:Application&gt;
{/syntax}</del><ins>&lt;/sparkrocks:Application&gt;{/syntax}</ins>


When we get to custom components we will revisit XML Namespaces in Flex 4 as they are key to importing custom code.

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>MXML Namespaces</title>
	  <pubDate>Mon, 26 Oct 2009 19:20:08 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=MXML+Namespaces</link>
	  <description><pre id="diff">At the start of every MXML document, there are a few xml namespaces defined, where it says &quot;xmlns:&quot; below. 

<del>{{&lt;?xml</del><ins>{syntax xml}
&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
      xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
      xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

<del>&lt;/s:Application&gt;}}</del><ins>&lt;/s:Application&gt;
{/syntax}</ins>

Here are the important parts:
xmlns:fx = &quot;http://ns.adobe.com/mxml/2009&quot;

The &quot;fx&quot; above maps all component to &quot;http://ns.adobe.com/mxml/2009&quot; so if you see: &lt;fx:Script&gt; or &lt;fx:Declarations&gt; these tags are defined for import here &quot;http://ns.adobe.com/mxml/2009&quot;. 

Flex comes with some predefined namespaces:

Core Flex: http://ns.adobe.com/mxml/2009
Spark Components: library://ns.adobe.com/flex/spark
Halo &quot;MX&quot; Components: library://ns.adobe.com/flex/halo

Namespaces are quite flexible and you can define them how you want, this even works:

<del>{{&lt;?xml</del><ins>{syntax xml}
&lt;?xml</ins> version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;sparkrocks:Application 
        xmlns:flexrocks=&quot;http://ns.adobe.com/mxml/2009&quot; 
        xmlns:sparkrocks=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

       &lt;sparkrocks:Button 
              label=&quot;Hello World&quot;/&gt;

<del>&lt;/sparkrocks:Application&gt;}}</del><ins>&lt;/sparkrocks:Application&gt;
{/syntax}</ins>


When we get to custom components we will revisit XML Namespaces in Flex 4 as they are key to importing custom code.

 {COMMENTS}
</pre></description>
	</item>

	<item>
	  <title>What is Flex?</title>
	  <pubDate>Mon, 26 Oct 2009 19:16:35 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=What+is+Flex%3F</link>
	  <description><pre id="diff"></pre></description>
	</item>

	<item>
	  <title>What is Flex?</title>
	  <pubDate>Mon, 26 Oct 2009 19:12:43 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=What+is+Flex%3F</link>
	  <description><pre id="diff"></pre></description>
	</item>

	<item>
	  <title>What is Flex?</title>
	  <pubDate>Mon, 26 Oct 2009 19:12:25 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=What+is+Flex%3F</link>
	  <description><pre id="diff">Flex is a framework ( components &amp; code ) and SDK ( compilers &amp; debuggers ) to help you create applications. Flex provides a reusable library of components and code to allow you to focus on application experience vs reinventing the wheel. The output of the Flex SDK is a SWF file that runs in Flash Player within the browser or an AIR file that runs in the AIR Runtime on the desktop.

<del> {COMMENTS}</del><ins>{COMMENTS}</ins>
</pre></description>
	</item>

	<item>
	  <title>States</title>
	  <pubDate>Mon, 26 Oct 2009 18:54:05 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=States</link>
	  <description><pre id="diff">The States feature has changed wildly in Flex 4 and is my favorite feature of the release.

'''What is a State?'''
In Flex, a state is a series of property values associated with a state name. When the state is set, all the values within the state are applied in bulk. States are a very handy way to organize your application as changing from different views within your application is typically managed by changing many properties all at once. By using the states feature you only need to set the value of '''currentState''' to the state name you define.

Here is a simple States example. In the example I define 3 states named &quot;One&quot; &quot;Two&quot; &quot;Three&quot; and navigate between them with 3 buttons:

{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
&lt;/s:Application&gt;}}

'''Wow, that was boring!''' 

The prior example worked perfectly but we didn't set any state property values so it wasn't that exciting. In Flex 4 the syntax for State property values changed. Before Flex 4, all state properties were set within the &lt;s:State&gt; component but now you can additionally set state values on the components they affect. This makes understanding the effect of state changes much easier to see and work with. Since states affect properties, the new syntax extends the existing dot notation property syntax like so:

{{&lt;s:Label 
	text.One = &quot;One&quot; 
	text.Two = &quot;Two&quot; 
	text.Three = &quot;Three&quot; /&gt;}}

Notice that the 'text' value has a different value for each state. Whenever the state changes, the value of the &quot;text&quot; property will change if a property is specified for the state change. If we were to set &quot;currentState='foo'&quot;, since there isn't a property value designated, the value would remain depending on which state had fired prior.

'''''HINT: In FB4 states have code hinting if you define the &lt;s:states&gt; tag first!'''''

Here is the above example complete:
{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot; 
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
	&lt;s:Label
		text.One = &quot;One&quot; 
		text.Two = &quot;Two&quot; 
		text.Three = &quot;Three&quot;
		horizontalCenter=&quot;0&quot;
		top=&quot;50&quot;
		fontSize=&quot;40&quot;
		/&gt;
	
&lt;/s:Application&gt;
}}

Enough of this simple stuff, lets get crazy with States! Lets add a Panel, set its title value and resize it using States. Also note that the state buttons are disabled when a state is selected! That is a ton of logic that you didn't need to write and is just the tip of the iceberg in using States.

{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:states&gt;
		&lt;s:State name=&quot;One&quot;/&gt;
		&lt;s:State name=&quot;Two&quot;/&gt;
		&lt;s:State name=&quot;Three&quot;/&gt;
	&lt;/s:states&gt;
	
	&lt;s:Panel
	 	resizeEffect=&quot;Resize&quot;
		title.One=&quot;One&quot;
		title.Two=&quot;Two&quot;
		title.Three=&quot;Three&quot;
		width.One=&quot;800&quot;
		width.Two=&quot;200&quot;
		width.Three=&quot;400&quot;
		height.One=&quot;400&quot;
		height.Two=&quot;600&quot;
		height.Three=&quot;200&quot;
		horizontalCenter=&quot;0&quot;
		verticalCenter=&quot;0&quot;
		&gt;
		
		&lt;s:Label
			text.One=&quot;One&quot; 
			text.Two=&quot;Two&quot; 
			text.Three=&quot;Three&quot;
			horizontalCenter=&quot;0&quot;
			verticalCenter=&quot;0&quot;
			fontSize=&quot;40&quot;
			/&gt;

	&lt;/s:Panel&gt;
	
	&lt;s:HGroup 
		horizontalCenter=&quot;0&quot;&gt;
		
		&lt;s:Button 
			label=&quot;One&quot;
			enabled.One=&quot;false&quot;
			click=&quot;this.currentState = 'One'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Two&quot; 
			enabled.Two=&quot;false&quot;
			click=&quot;this.currentState = 'Two'&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Three&quot;
			enabled.Three=&quot;false&quot; 
			click=&quot;this.currentState = 'Three'&quot;/&gt;
		
	&lt;/s:HGroup&gt;
	
&lt;/s:Application&gt;
}}

What I really like is just how readable this code is and how you can make changes to States code easily. Not only is this great for in app State use but States are an essential part of skinning in Flex. &lt;s:Button&gt; has 4 states and simply implementing different graphics per state will dramatically alter the look and feel.

In Flash Catalyst, states are used extensively and the code they generate is a powerful way to learn both Flex Skinning and using States within application development.

&quot;States in Flex 4 are ninja quality magic!&quot; - Ted :)

<ins> {COMMENTS}</ins>
</pre></description>
	</item>

	<item>
	  <title>Element Properties</title>
	  <pubDate>Mon, 26 Oct 2009 18:53:48 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Properties</link>
	  <description><pre id="diff">Element properties are very important in Flex MXML and ActionScript. In MXML they are set as attribute strings and child elements but at compile time are converted to typed values. 

Attribute string properties can support boolean values (&quot;true&quot; or &quot;false&quot;), numeric values ( &quot;1&quot;, &quot;2.5&quot;, &quot;#FF0000&quot;), string values (&quot;Duhhhh&quot;), bindings ( &quot;{ foo.text }&quot; ... more on this later )

Here is an example:
{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:Label  
			fontSize=&quot;30&quot;
			text=&quot;I am label with attribute properties!&quot;/&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;}}

With MXML elements you can specify values with much more complex structure. In this example we set values into a Spark DropDownList using the &lt;s:ArrayCollection&gt; and &lt;fx:String&gt; elements.

{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:VGroup 
		horizontalCenter=&quot;0&quot;
		top=&quot;30&quot;&gt;
		
		&lt;s:DropDownList&gt; 
			&lt;s:dataProvider&gt;
				&lt;s:ArrayCollection&gt;
					&lt;fx:String&gt;AK&lt;/fx:String&gt;
					&lt;fx:String&gt;AL&lt;/fx:String&gt;
					&lt;fx:String&gt;AR&lt;/fx:String&gt;
				&lt;/s:ArrayCollection&gt;
			&lt;/s:dataProvider&gt;
		&lt;/s:DropDownList&gt;
		
	&lt;/s:VGroup&gt;
		
&lt;/s:Application&gt;}}

The nested element model also supports inline graphics in Flex 4. Just as you can specify data for the dataProvider property, you can add graphics inline into an application. Here is a brief graphics example of Flex 4 using MXML nested elements. Look at the &lt;s:Rect&gt; element with nested stroke and fill:

{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Group&gt;
		&lt;s:Rect 
			x=&quot;0&quot; y=&quot;0&quot; 
			radiusX=&quot;4&quot; 
			radiusY=&quot;4&quot; 
			height=&quot;100%&quot; 
			width=&quot;100%&quot;&gt;
			&lt;s:stroke&gt;
				&lt;s:LinearGradientStroke 
					weight=&quot;1&quot; 
					scaleMode=&quot;normal&quot;/&gt;
			&lt;/s:stroke&gt;
			&lt;s:fill&gt;
				&lt;s:LinearGradient&gt;
					&lt;s:entries&gt;
						&lt;mx:GradientEntry 
							color=&quot;0x999999&quot;/&gt;
					&lt;/s:entries&gt;
				&lt;/s:LinearGradient&gt;
			&lt;/s:fill&gt;
		&lt;/s:Rect&gt;        
		
		&lt;s:Button 
			label=&quot;Button 1&quot; 
			left=&quot;10&quot;
			top=&quot;13&quot;
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 2&quot;
			left=&quot;110&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 3&quot;
			left=&quot;210&quot; 
			top=&quot;13&quot; 
			bottom=&quot;10&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;Button 4&quot;
			left=&quot;310&quot; 
			top=&quot;13&quot; 
			right=&quot;10&quot; 
			bottom=&quot;10&quot;/&gt;
		
	&lt;/s:Group&gt;
&lt;/s:Application&gt;}}

In ActionScript, you can set element values directly as typed values. Make sure to use correct types when setting values by ActionScript mismatched types will give you errors at compilation and at runtime. In the following example a spark Button component is created and attributes are set using ActionScript:

{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge dynamic s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into &lt;s:Application&gt;
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
&lt;/s:Application&gt;}}

<ins>
 {COMMENTS}</ins>

</pre></description>
	</item>

	<item>
	  <title>addElement, addElementAt, removeElement, removeElementAt</title>
	  <pubDate>Mon, 26 Oct 2009 18:53:16 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=addElement%2C+addElementAt%2C+removeElement%2C+removeElementAt</link>
	  <description><pre id="diff">In Flex 4 to add or remove elements from containers, you need to use the element API: 

*addElement - Add an element into a container
*addElementAt - Add a element into a container at a certain depth location
*removeElement - Remove an element from a container
*removeElementAt - Remove an element from a container at a certain depth location

In Flex 3 and before, the low level addChild method was used to add or remove components from containers but in Flex 4 this is not the case. To add/remove a new element into an MXML component, you use it's &quot;id&quot; attribute and one of the above methods.

This simple example uses addElement and removeElementAt to give you an idea about how they work. The example adds a dynamically created button into a VGroup container using addElement and then allows you to remove the 2nd item using removeElementAt( 2 ).


{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;

	&lt;fx:Script&gt;
		&lt;![CDATA[
			import spark.components.Button;
			import flash.utils.getTimer;
			
			protected function addElementClick( event:MouseEvent ):void
			{
				var bu:Button = new Button();
				bu.label = &quot;Added with addElement! &quot; + getTimer();
				myGroup.addElement( bu );
			}

			protected function removeElementClick( event:MouseEvent ):void
			{
				if( myGroup.numChildren &gt; 2 ){
					myGroup.removeElementAt( 2 );
				}
			}

		]]&gt;
	&lt;/fx:Script&gt;

	
	&lt;s:VGroup 
		id=&quot;myGroup&quot; 
		horizontalCenter=&quot;0&quot; 
		horizontalAlign=&quot;center&quot;&gt;
		
		&lt;s:Button 
			label=&quot;addElement&quot; 
			click=&quot;addElementClick( event )&quot;/&gt;
		
		&lt;s:Button 
			label=&quot;removeElement&quot; 
			click=&quot;removeElementClick( event )&quot;/&gt;
		
	&lt;/s:VGroup&gt;
	
&lt;/s:Application&gt;}}
<ins>
 {COMMENTS}</ins>
</pre></description>
	</item>

	<item>
	  <title>Element Creation</title>
	  <pubDate>Mon, 26 Oct 2009 18:53:02 -0400</pubDate>
	  <link>http://onflex.org/learn/fx4/index.php?page=Element+Creation</link>
	  <description><pre id="diff">In Flex there are 2 ways to create elements, MXML and ActionScript.

In MXML simply adding a tag will create an instance and add it into the &lt;s:Application&gt; all at once. Here is an example of creating a Spark Button in MXML:

{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;&gt;
	
	&lt;s:Button
		left=&quot;25&quot;
		right=&quot;25&quot;
		top=&quot;25&quot;
		bottom=&quot;25&quot;
		label=&quot;Huge s:Button positioned 25px from all sides of s:Application!&quot;/&gt;
	
&lt;/s:Application&gt;}}

MXML handles creating the &lt;s:button&gt; instance, setting properties declared as attributes (left, top, label, etc), and adding it into the &lt;s:Application&gt; instance.

Sometimes you want to create component instances in ActionScript. To do this you need to import spark.components.Button, create an instance using '''new''', set some properties, and use the addElement method to add the button into &lt;s:Application&gt;. Here is the example:

{{&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application 
	xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot; 
	xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
 	applicationComplete=&quot;onApplicationComplete( event )&quot;&gt;
	
	&lt;fx:Script&gt;
		&lt;![CDATA[
			
			//import 
			import mx.events.FlexEvent;
			import spark.components.Button;

			protected function onApplicationComplete( event:FlexEvent ):void
			{
				//create new Button instance
				var bu:Button = new Button();
				bu.left=25;
				bu.right=25;
				bu.top=25;
				bu.bottom=25;
				bu.label = &quot;Huge s:Button positioned 25px from all sides of s:Application!&quot;;
				
				//add into &lt;s:Application&gt;
				this.addElement( bu );
			}

		]]&gt;
	&lt;/fx:Script&gt;
	
&lt;/s:Application&gt;}}

The above two applications are identical in their output but the later example adds the Button dynamically. There are use cases where each technique is valuable to know and understand. Sometimes MXML is easier and sometime AS is easier. Actually in a later section I will show you how to leverage the best of both because MXML and ActionScript are very closely related, if not identical. 
<ins>
 {COMMENTS}</ins>
</pre></description>
	</item>
</channel>
</rss>