<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Flexpert to the rescue &#187; view state</title>
	<atom:link href="http://www.flexpert.be/tag/view-state/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flexpert.be</link>
	<description>Blog site about all things Adobe</description>
	<lastBuildDate>Sat, 28 Aug 2010 17:07:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Milestone: the first video tutorial is online</title>
		<link>http://www.flexpert.be/2009/08/milestone-the-first-video-tutorial-is-online/</link>
		<comments>http://www.flexpert.be/2009/08/milestone-the-first-video-tutorial-is-online/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 15:14:12 +0000</pubDate>
		<dc:creator>Steven Peeters</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[transition]]></category>
		<category><![CDATA[video tutorial]]></category>
		<category><![CDATA[view state]]></category>

		<guid isPermaLink="false">http://www.flexpert.be/?p=250</guid>
		<description><![CDATA[It took me quite some time to figure out what it takes to make video tutorials: choose a subject, write a storyboard, prepare the entire story, record a zillion times &#8217;cause you&#8217;re never quite happy with the result, edit it afterwards, make a page to publish it, &#8230; And I&#8217;m probably forgetting a few steps [...]]]></description>
			<content:encoded><![CDATA[<p>It took me quite some time to figure out what it takes to make video tutorials: choose a subject, write a storyboard, prepare the entire story, record a zillion times &#8217;cause you&#8217;re never quite happy with the result, edit it afterwards, make a page to publish it, &#8230; And I&#8217;m probably forgetting a few steps now.</p>
<p>But all that hard work is now done for the first time, so it should become a little easier for the next couple of tutorials. So, if you fancy the visual side of tutorials instead of just reading the blog post, you can now view my very first one <a href="http://www.flexpert.be/video-tutorials/">here</a>. Of course, you can still read <a href="http://www.flexpert.be/flex/view-state-transition-problem-effects-dont-play/">the blog post</a> on the subject in the blog section of the Flexpert website.</p>
<p>Enjoy !!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexpert.be/2009/08/milestone-the-first-video-tutorial-is-online/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>View state transition problem: effects don&#8217;t play</title>
		<link>http://www.flexpert.be/2009/07/view-state-transition-problem-effects-dont-play/</link>
		<comments>http://www.flexpert.be/2009/07/view-state-transition-problem-effects-dont-play/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 13:17:33 +0000</pubDate>
		<dc:creator>Steven Peeters</dc:creator>
				<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[effect]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[transition]]></category>
		<category><![CDATA[view state]]></category>

		<guid isPermaLink="false">http://www.flexpert.be/?p=126</guid>
		<description><![CDATA[Question: When I’m using view states, I apply transitions to make the view state changes more fluent an attractive. There seems to be a problem though, because when I have a component in the second view state that I want to fade out upon returning to the base state, that effect is never played. Do [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: medium;"><strong>Question:</strong></span></p>
<p><em>When I’m using view states, I apply transitions to make the view state changes more fluent an attractive. There seems to be a problem though, because when I have a component in the second view state that I want to fade out upon returning to the base state, that effect is never played. Do you have a clue why this doesn’t happen and if there a solution for this problem?</em></p>
<p><span style="font-size: medium;"><strong>Solution:</strong></span></p>
<p>If you are using view states and want to apply certain transitions between these states, there are some things to keep in mind. When adding components to a state, the transition effects (also called behaviors) are applied to that component while adding it. So this means that the effects will be visible during initialization of the view state. However, <strong>when you go back to the original base state, the component is removed again before the effects have had the chance of being displayed.</strong> Luckily, in Flex there are a couple of ways of dealing with this issue.</p>
<p>The <strong>first way</strong> of making sure the effects are visible is to not make use of a transition when going back to the base state. Instead, <strong>you use the effect triggers of the component itself to trigger the effect</strong>. When the component is removed, you need to use the <strong>removedEffect </strong>trigger like in the following example:</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;vertical&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- The font needs to be embedded for the texxt to fade out</span>
<span style="color: #000000;">as well. Otherwise, the button will fade, but the text</span>
<span style="color: #000000;">will simply remain fully opaque througout the effect --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Style</span><span style="color: #7400FF;">&gt;</span></span>
@font-face {
src: local(&quot;Verdana&quot;);
fontFamily: myFont;
fontWeight: bold;
}
&nbsp;
global {
fontFamily: myFont;
}
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Style</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- This is the Fade effect we are going to use when the component is removed </span>
<span style="color: #000000;">          from the display list --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Fade</span> id=<span style="color: #ff0000;">&quot;fade&quot;</span> alphaFrom=<span style="color: #ff0000;">&quot;1&quot;</span> alphaTo=<span style="color: #ff0000;">&quot;0&quot;</span> duration=<span style="color: #ff0000;">&quot;2000&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Define the view state --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:states</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;extraButton&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- This button will fade in through the transitions and will fade out via the </span>
<span style="color: #000000;">          removedEffect trigger --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;btn2&quot;</span> label=<span style="color: #ff0000;">&quot;Click me now&quot;</span> click=<span style="color: #ff0000;">&quot;currentState=''&quot;</span> removedEffect=<span style="color: #ff0000;">&quot;{fade}&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Define the view state transition --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:transitions</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Transition</span> fromState=<span style="color: #ff0000;">&quot;&quot;</span> toState=<span style="color: #ff0000;">&quot;extraButton&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Fade</span> target=<span style="color: #ff0000;">&quot;{btn2}&quot;</span> alphaFrom=<span style="color: #ff0000;">&quot;0&quot;</span> alphaTo=<span style="color: #ff0000;">&quot;1&quot;</span> duration=<span style="color: #ff0000;">&quot;2000&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Transition</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:transitions</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- This component will be visible by default and triggers the second view state --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;btn1&quot;</span> label=<span style="color: #ff0000;">&quot;Click me&quot;</span> click=<span style="color: #ff0000;">&quot;currentState='extraButton'&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span>&amp;gt;</span></pre></div></div>

<p><br/></p>
<p>The problem with this approach is that the transition effects are scattered throughout your code. <strong>However, there is also a second, in my opinion more appropriate way of dealing with this transition problem and that is through the use of transitions.</strong> This means that all of your transitional code will be located in 1 spot and this is so much easier to maintain.</p>
<p>But how do we solve the issue of the effect not being shown? Well, in fact (and this is not often mentioned in books and courses), you <strong>do have total control of when an item is being added or removed considering the effects that need to be played on the component. </strong>To do this, you can simply use the <strong>&lt;mx:AddChildAction&gt;</strong> and <strong>&lt;mx:RemoveChildAction&gt;</strong> tags. Just place them in the right order within a &lt;ms:Sequence&gt; tag after the appropriate effect and your effect will be displayed properly. Just take a look at this example code:<</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- The font needs to be embedded for the texxt to fade out as well.</span>
<span style="color: #000000;">Otherwise, the button will fade, but the text will simply remain fully opaque</span>
<span style="color: #000000;">througout the effect --&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Style</span><span style="color: #7400FF;">&gt;</span></span>
@font-face {
src: local(&quot;Verdana&quot;);
fontFamily: myFont;
fontWeight: bold;
}
&nbsp;
global {
fontFamily: myFont;
}
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Style</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Define the view state --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:states</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:State</span> name=<span style="color: #ff0000;">&quot;extraButton&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- This button will fade in and out through the transitions --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;btn2&quot;</span> label=<span style="color: #ff0000;">&quot;Click me now&quot;</span> click=<span style="color: #ff0000;">&quot;currentState=''&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:AddChild</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:State</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:states</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- Define the view state transition --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:transitions</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Transition</span> fromState=<span style="color: #ff0000;">&quot;&quot;</span> toState=<span style="color: #ff0000;">&quot;extraButton&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Fade</span> target=<span style="color: #ff0000;">&quot;{btn2}&quot;</span> alphaFrom=<span style="color: #ff0000;">&quot;0&quot;</span> alphaTo=<span style="color: #ff0000;">&quot;1&quot;</span> duration=<span style="color: #ff0000;">&quot;2000&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Transition</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- The fade out effect is accomplished by adding a sequence with the </span>
<span style="color: #000000;">          RemoveChildAction after the effect --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Transition</span> fromState=<span style="color: #ff0000;">&quot;extraButton&quot;</span> toState=<span style="color: #ff0000;">&quot;&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Sequence</span> target=<span style="color: #ff0000;">&quot;{btn2}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Fade</span> alphaFrom=<span style="color: #ff0000;">&quot;1&quot;</span> alphaTo=<span style="color: #ff0000;">&quot;0&quot;</span> duration=<span style="color: #ff0000;">&quot;2000&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RemoveChildAction</span><span style="color: #7400FF;">/&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Sequence</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Transition</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:transitions</span><span style="color: #7400FF;">&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #808080; font-style: italic;">&lt;!-- This component will be visible by default and triggers the second view state --&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Buttonid</span>=<span style="color: #ff0000;">&quot;btn1&quot;</span> label=<span style="color: #ff0000;">&quot;Click me&quot;</span> click=<span style="color: #ff0000;">&quot;currentState='extraButton'&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
&nbsp;
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p><br/></p>
<p>You can view the results of the latter solution in the application below.</p>
<p>
<object width="200" height="150">
<param name="movie" value="http://www.flexpert.be/swfexamples/Transitions.swf"></param>
<param name="quality" value="high"></param>
<param name="wmode" value="window"></param>
<param name="menu" value="false"></param>
<param name="bgcolor" value="#FFFFFF"></param>
<embed type="application/x-shockwave-flash" width="200" height="150" src="http://www.flexpert.be/swfexamples/Transitions.swf" quality="high" bgcolor="#FFFFFF" wmode="window" menu="false" ></embed>
</object>
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flexpert.be/2009/07/view-state-transition-problem-effects-dont-play/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
