<?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>Iwo Banaś - Flex Blog &#187; effects</title>
	<atom:link href="http://www.iwobanas.com/category/reusable-components/effects/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iwobanas.com</link>
	<description>Adobe Flex and AIR thoughts, custom components, how-to’s...</description>
	<lastBuildDate>Tue, 02 Feb 2010 22:54:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Implementing Slide effects &#8211; iteration 3</title>
		<link>http://www.iwobanas.com/2009/06/implementing-slide-effects-iteration-3/</link>
		<comments>http://www.iwobanas.com/2009/06/implementing-slide-effects-iteration-3/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 11:18:33 +0000</pubDate>
		<dc:creator>Iwo Banas</dc:creator>
				<category><![CDATA[effects]]></category>
		<category><![CDATA[reusable components]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[how-to]]></category>

		<guid isPermaLink="false">http://www.iwobanas.com/?p=38</guid>
		<description><![CDATA[This post is a continuation of iteration 2. From the end user point of view Slide effects presented  here are almost identical to these from previous post. The only difference is that target components shadow or other filter drawn beside components bounds (0,0 to width, height rectangle) are not cropped during slide animation.
A number [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a continuation of <a href="http://www.iwobanas.com/2009/05/implementing-slide-effects-iteration-2/">iteration 2</a>. From the end user point of view Slide effects presented  here are almost identical to these from previous post. The only difference is that target components shadow or other filter drawn beside components bounds (0,0 to width, height rectangle) are not cropped during slide animation.</p>
<p>A number of changes was required to implement this functionality:</p>
<p><span id="more-38"></span></p>
<h3>Determining components visible bounds</h3>
<p>First of all actual components visible bounds have to be determined. I have found code to do that in private function of MaskEffectInstance class from Flex 3 framework. As I believe that such code shouldn’t be rewritten every time someone need it I have created utility class named ComponentUtils and copied code from MaskEffectInstance  to a public static function.</p>
<p>Knowing what are the visible bounds of the component I have discovered that x and y coordinate of visible rectangle are often negative (when filter is drawn at the left or above component). According to DisplayObjec documentation when scrollRect property is set the visible area upper-left corner is defined by components (0,0) point. So to enable displaying of filtered component (e.g. shadow) at the left or above component I had to move component there and back as described in next two paragraphs.</p>
<h3>Moving component (up/left) so that its origin (0,0 point) equals to visible rectangle upper-left corner</h3>
<p>To move component origin to visible rectangle origin I have adjusted its x and y coordinates in effect instance play() function:</p>
<pre>
target.x += visibleRect.x;
target.y += visibleRect.y
</pre>
<p>I have also remembered to restore component to its original position at effect end (onTweenEnd() function):</p>
<pre>
target.x -= visibleRect.x;
target.y -= visibleRect.y
</pre>
<h3>Moving component content back (down/right) so that it is displayed at the original location</h3>
<p>To balance component movement I have adjusted scrollRect x and y coordinates in concrete effect instance onTweenUpdate functions. If these values are set to negative values (visible rectangle x,y) component is moved right-down. After applying this changes effect seems to work as before but shadows are visible.
<p/>
<p>The following example demonstrates all SlideRight, SlideLeft, SlideDown and SlideUp effects.<br />
<a title="Sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_03/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="Slide effects sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_03/srcview/SlideEffect03.zip">here</a>.</p>
<p><iframe src="http://www.iwobanas.com/wp-content/uploads/slide_effect_03/SlideEffectsExample.html" width="100%" height="350" frameborder="no"></iframe></p>
<p>The following example demonstrates SlideDown and SlideUp effects applied to a VBox with DropShadowFilter enabled.<br />
<a title="Sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_03ex2/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="Slide effects sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_03ex2/srcview/SlideEffect03.zip">here</a>.</p>
<p><iframe src="http://www.iwobanas.com/wp-content/uploads/slide_effect_03ex2/SlideWithShadowExample.html" width="100%" height="350" frameborder="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwobanas.com/2009/06/implementing-slide-effects-iteration-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Implementing Slide effects &#8211; iteration 2</title>
		<link>http://www.iwobanas.com/2009/05/implementing-slide-effects-iteration-2/</link>
		<comments>http://www.iwobanas.com/2009/05/implementing-slide-effects-iteration-2/#comments</comments>
		<pubDate>Thu, 28 May 2009 15:36:57 +0000</pubDate>
		<dc:creator>Iwo Banas</dc:creator>
				<category><![CDATA[effects]]></category>
		<category><![CDATA[reusable components]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[how-to]]></category>

		<guid isPermaLink="false">http://www.iwobanas.com/?p=25</guid>
		<description><![CDATA[
This post is a continuation of Implementing SlideDown effect – iteration 1. It is quite short since extraction of Slide base class and implementation of SlideDown, SlideUp, SlideLeft and SlideRight classes was really straightforward. Most of the code from iteration 1 was used as base classes (Slide and SlideInstance). Concrete effect classes simply declares instanceClass [...]]]></description>
			<content:encoded><![CDATA[<p>
This post is a continuation of <a href="http://www.iwobanas.com/2009/05/implementing-slidedown-effect-%E2%80%93-iteration-1/">Implementing SlideDown effect – iteration 1</a>. It is quite short since extraction of Slide base class and implementation of SlideDown, SlideUp, SlideLeft and SlideRight classes was really straightforward. Most of the code from iteration 1 was used as base classes (Slide and SlideInstance). Concrete effect classes simply declares instanceClass in constructor while concrete effect instance classes overrides onTweenUpdate() method to tween animation in a specific direction.
</p>
<p><span id="more-25"></span></p>
<p>The following example demonstrates all SlideRight, SlideLeft, SlideDown and SlideUp effects.<br />
<a title="Sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_02/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="Slide effects sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_02/srcview/SlideEffect02.zip">here</a>.</p>
<p><iframe src="http://www.iwobanas.com/wp-content/uploads/slide_effect_02/SlideEffectsExample.html" width="100%" height="350" frameborder="no"></iframe></p>
<p>This implementation has one shortcoming, components are cropped to its width/height so if they have drop shadow or other filters enabled it may not be visible during animation. I will create Slide effect supporting filters in iteration 3.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwobanas.com/2009/05/implementing-slide-effects-iteration-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing SlideDown effect – iteration 1</title>
		<link>http://www.iwobanas.com/2009/05/implementing-slidedown-effect-%e2%80%93-iteration-1/</link>
		<comments>http://www.iwobanas.com/2009/05/implementing-slidedown-effect-%e2%80%93-iteration-1/#comments</comments>
		<pubDate>Tue, 26 May 2009 17:12:58 +0000</pubDate>
		<dc:creator>Iwo Banas</dc:creator>
				<category><![CDATA[effects]]></category>
		<category><![CDATA[reusable components]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flex 3]]></category>
		<category><![CDATA[how-to]]></category>

		<guid isPermaLink="false">http://www.iwobanas.com/?p=9</guid>
		<description><![CDATA[This tutorial describes how to create reusable effect which  can be applied both by calling play() function and by binding it to showEffect/hideEffect MXML attribute.
If you simply want to use slide effect in your application you don’t have to read whole this tutorial. Simply download sources, open included examples and you will surely understand [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial describes how to create reusable effect which  can be applied both by calling play() function and by binding it to showEffect/hideEffect MXML attribute.</p>
<p>If you simply want to use slide effect in your application you don’t have to read whole this tutorial. Simply <a title="SlideDown, SlideUp, SlideLeft, SlideRight sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_03/srcview/SlideEffect03.zip">download sources</a>, open included examples and you will surely understand how to use it.</p>
<p>I have divided this tutorial into three parts (posts):</p>
<ul>
<li> iteration 1 – Simple SlideDown effect (this article)</li>
<li> <a href="http://www.iwobanas.com/2009/05/implementing-slide-effects-iteration-2/">iteration 2 – Extracting Slide base class and implementing slide effect in 4 directions</a></li>
<li> <a href="http://www.iwobanas.com/2009/06/implementing-slide-effects-iteration-3/">iteration 3 &#8211; Adding filter support e.g. DropShadowFilter</a></li>
</ul>
<p><span id="more-9"></span></p>
<h3>Background</h3>
<p>Recently I needed to create a custom dropdown component, something like ComboBox but containing form instead of list inside dropdown. My first idea was to extend ComboBase, unfortunately it is more about handling list than about displaying dropdown so it was of no use in my case. Finally I decided to create my component from scratch. After some playing with PopUpManager I have my component almost ready, the only thing I needed was cool slide effect to animate showing and hiding of the dropdown.</p>
<p>I was pretty sure that there is such effect in Flex 3 framework since ComboBox and ColorPicker is using it. Disappointment again, both ComboBox and ColorPicker have their own implementations embedded into their code (personally I think that such code duplication is a reason of numerous bugs in Flex 3). So again I decided to create my own component from scratch &#8211; Slide effect this time.</p>
<p>I have divided this task into 3 iterations each covered by separate post.</p>
<h3>Iteration 1 – Simple SlideDown effect</h3>
<p>My first thought was to create SlideDown by combining Move effect(downward) with WipeUp but then I realized that WipeUp is not working as expected together with DropShadowFilter which I was using so I have to think about something else.</p>
<p>After some digging in reference documentation I have found DisplayObject.scrollRect property which does exactly what I needed. Although it is intended to support scrolling it is perfect for Slide effect implementation: scrollRect x and y properties can be used to animate the move while width/height can be used to crop component.</p>
<p>Implementation of new effect using TweenEffect as a base class was really straightforward. I will not describe it here in more details since there is nice doc about tween effect at <a title="Flex 3 reference" href="http://livedocs.adobe.com/flex/3/html/help.html?content=createeffects_3.html" target="_blank">http://livedocs.adobe.com/flex/3/html/help.html?content=createeffects_3.html</a></p>
<p>There are two flaws in this document, both refers to effect instance class play() function:</p>
<ul>
<li> Tween object created in this function should be assigned to TweenEffectInstance.tween public property not to local variable.</li>
<li> To avoid flickering at the beginning of effect call to mx_internal::applyTweenStartValues() is needed (I know that using mx_internal functions is not recommended but this function is not harmful at all and probably was marked mx_internal by accident).</li>
</ul>
<p>You can see complete code of my play() function below:</p>
<pre>
override public function play():void {
    super.play();

    // backup scrollRect value
    scrollRect = target.scrollRect;

    width = target.width;
    height = target.height;

    // We are tweenning two values: one from 0 to width, the other from 0 to height
    tween = createTween(this, [0, 0], [width, height], duration);

    // Call to this function is needed to prevent filckering at effect start
    // I have no idea why this function is mx_internal
    mx_internal::applyTweenStartValues();
}
</pre>
<p>I have also implemented additional initEffect() function to enable my effect to automatically detect correct showTarget value when used as “showEffect” “hideEffect”etc.  You can find code of this function below.</p>
<pre>
override public function initEffect(event:Event):void
{
	super.initEffect(event);

	// if showTarget is not explicitly set assign default value dependent on event type
	if (!_showExplicitlySet)
	{
		switch (event.type)
		{
			case FlexEvent.CREATION_COMPLETE:
			case FlexEvent.SHOW:
			case Event.ADDED:
			{
				showTarget = true;
				break;
			}

			case FlexEvent.HIDE:
			case Event.REMOVED:
			{
				showTarget = false;
				break;
			}
		}
	}
}
</pre>
<p>This example demonstrates SlideDown effect compared to WipeDown.<br />
<a title="Sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_01/srcview/index.html" target="_blank">View source</a> is enabled, you can download zipped sources from <a title="SlideDown sources" href="http://www.iwobanas.com/wp-content/uploads/slide_effect_01/srcview/SlideEffect01.zip">here</a>.</p>
<p><iframe src="http://www.iwobanas.com/wp-content/uploads/slide_effect_01/SlideEffectExample.html" width="100%" height="350" frameborder="no"></iframe></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iwobanas.com/2009/05/implementing-slidedown-effect-%e2%80%93-iteration-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
