<?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>RiaCodes</title>
	<atom:link href="http://www.riacodes.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.riacodes.com</link>
	<description>Resources, tutorials , tips &#38; tricks for RIA : Flex, Flash, Air, AS3</description>
	<lastBuildDate>Wed, 24 Feb 2010 21:34:35 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create a skippable and redirectable video intro for a website</title>
		<link>http://www.riacodes.com/flash/create-a-skippable-and-redirectable-video-intro-for-a-website/</link>
		<comments>http://www.riacodes.com/flash/create-a-skippable-and-redirectable-video-intro-for-a-website/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 17:39:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1230</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_video-intro/preview.gif"/>]]></description>
			<content:encoded><![CDATA[<p>In the following actionscript 3 lesson, we are going to create a video intro that the user can skip to access the main site or that will automatically redirect to the main site when the video has finished playing.<br />
<span id="more-1230"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_video-intro/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_video-intro/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flash file (Actionscript 3.0) and save it as video.fla. </p>
<p><em>2.</em> Rename &#8220;layer1&#8243; to &#8220;btn&#8221;. Create the &#8220;skip&#8221; button and give it an instance of skip_btn.</p>
<p><em>3.</em> Create an &#8220;actions&#8221; layer and open the actions panel.<br />
First, we need to set up the video and add to the NetStream instance a listener for the NET_STATUS event.</p>
<pre class="brush: jscript;">
var conn:NetConnection = new NetConnection();
conn.connect(null);

var stream:NetStream = new NetStream(conn);
stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
stream.client = this;

var video:Video = new Video();
video.width = 640;
video.height = 480;
video.x = 0;
video.y = 0;
addChild(video);
video.attachNetStream(stream);
</pre>
<p><em>4.</em> The onStatus function detects the end of the video stream in order to redirect the user to the main page of the site.</p>
<pre class="brush: jscript;">
function onStatus(e:Object):void{
	 if(e.info.code == &quot;NetStream.Play.Stop&quot;) gotoSite();
}
</pre>
<p>Then play the video :</p>
<pre class="brush: jscript;">stream.play(&quot;video.flv&quot;);</pre>
<p><em>5.</em> Finally we create the gotoSite function that will be called either by the skip button or when the videos has finished playing.</p>
<pre class="brush: jscript;">
skip_btn.addEventListener(MouseEvent.CLICK, gotoSite);

function gotoSite(e:Event = null):void{
	navigateToURL(new URLRequest(&quot;http://www.riacodes.com&quot;), &quot;_self&quot;);
}
</pre>
<p><em>6.</em> Here&#8217;s the entire code, test your movie to see the code in action.</p>
<pre class="brush: jscript;">
var conn:NetConnection = new NetConnection();
conn.connect(null);

var stream:NetStream = new NetStream(conn);
stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
stream.client = this;

var video:Video = new Video();
video.width = 640;
video.height = 480;
video.x = 0;
video.y = 0;
addChild(video);
video.attachNetStream(stream);

function onStatus(e:Object):void{
	 if(e.info.code == &quot;NetStream.Play.Stop&quot;) gotoSite();
}

stream.play(&quot;video.flv&quot;);

skip_btn.addEventListener(MouseEvent.CLICK, gotoSite);

function gotoSite(e:Event = null):void{
	navigateToURL(new URLRequest(&quot;http://www.riacodes.com&quot;), &quot;_self&quot;);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/create-a-skippable-and-redirectable-video-intro-for-a-website/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Circular Menu with AS3 Part 2</title>
		<link>http://www.riacodes.com/flash/circular-menu-with-as3-part-2/</link>
		<comments>http://www.riacodes.com/flash/circular-menu-with-as3-part-2/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:41:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1244</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_circular-menu-part2/preview.gif"/>]]></description>
			<content:encoded><![CDATA[<p>Following many requests on the tutorial entitled <a href="http://www.riacodes.com/flash/circular-menu-with-as3/">Circular Menu with AS3</a> about linking each button to a different url, we post here one solution.</p>
<p><span id="more-1244"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_circular-menu-part2/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_circular-menu-part2/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Starting from the finished file of <a href="http://www.riacodes.com/flash/circular-menu-with-as3/">Circular Menu with AS3</a>. Open menu.fla and with the &#8220;actions&#8221; layer selected open the actions panel.</p>
<p><em>2.</em> We are going to add few lines of code to make it work. Create an Array containing the different urls to assign to the buttons : </p>
<pre class="brush: jscript;">
var menu_items:Array = [&quot;HOME&quot;,&quot;ABOUT&quot;,&quot;PORTFOLIO&quot;,&quot;CONTACT&quot;,&quot;FACEBOOK&quot;];
var urls:Array = [&quot;http://www.riacodes.com&quot;,
				  &quot;http://www.riacodes.com/about&quot;,
				  &quot;http://www.riacodes.com/flash&quot;,
				  &quot;http://www.riacodes.com/contact&quot;,
				  &quot;http://www.facebook.com&quot;];
</pre>
<p><em>3.</em> In the buildMenu function, inside the loop, assign to each button its own url by setting a urlsite property.</p>
<pre class="brush: jscript; highlight: [6];">
for (var i:int = 0; i&lt; menu_items.length; i++){
		btn = new myButton();
		btn.buttonMode=true;
		btn.labelBtn.text = menu_items[i];
		btn.mouseChildren=false;
		btn.urlsite = urls[i];
		menu.addChild(btn);
		TweenLite.to(btn,2,{rotation: -i*angle,ease:Bounce.easeOut});
}
</pre>
<p><em>4.</em> Finally in the clickHandler function we use the navigateToURL method and pass it the url of the button which has triggered the event.</p>
<pre class="brush: jscript;">
function clickHandler(e:MouseEvent ):void{
	navigateToURL(new URLRequest(e.target.urlsite));
}
</pre>
<p><em>5.</em> Here&#8217;s the final code, test your application to see it in action.</p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.easing.*;

var menu_items:Array = [&quot;HOME&quot;,&quot;ABOUT&quot;,&quot;PORTFOLIO&quot;,&quot;CONTACT&quot;,&quot;FACEBOOK&quot;];
var urls:Array = [&quot;http://www.riacodes.com&quot;,
				  &quot;http://www.riacodes.com/about&quot;,
				  &quot;http://www.riacodes.com/flash&quot;,
				  &quot;http://www.riacodes.com/contact&quot;,
				  &quot;http://www.facebook.com&quot;];

var menu:Sprite = new Sprite();
menu.x= stage.stageWidth / 2;
menu.y=stage.stageHeight /2;
addChild(menu);

buildMenu();

function buildMenu(){

	var btn:myButton;
	var angle:int=360/menu_items.length;

	for (var i:int = 0; i&lt; menu_items.length; i++){
		btn = new myButton();
		btn.buttonMode=true;
		btn.labelBtn.text = menu_items[i];
		btn.mouseChildren=false;
		btn.urlsite = urls[i];
		menu.addChild(btn);
		TweenLite.to(btn,2,{rotation: -i*angle,ease:Bounce.easeOut});
	}
}

menu.addEventListener(MouseEvent.CLICK,clickHandler );

function clickHandler(e:MouseEvent ):void{
	navigateToURL(new URLRequest(e.target.urlsite));
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/circular-menu-with-as3-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to print with AS3</title>
		<link>http://www.riacodes.com/flash/how-to-print-with-as3/</link>
		<comments>http://www.riacodes.com/flash/how-to-print-with-as3/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 18:50:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1217</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_print/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this short tutorial, let&#8217;s see how we can print the content of our swf files using the PrintJob class with actionscript 3.<br />
<span id="more-1217"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_print/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_print/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flash file (Actionscript 3.0) and save it as print.fla. </p>
<p><em>2.</em> Rename &#8220;layer1&#8243; to &#8220;Content&#8221; and here create the content that you want to print (images, text &#8230;). Convert the whole content into a movie clip and give it an instance name of &#8220;content_mc&#8221;. </p>
<p><em>3.</em> Create a new layer at the top named &#8220;button&#8221; and create the print button. Give it an instance of print_btn.</p>
<p><em>4.</em> Finally create the &#8220;actions&#8221; layer. Open the actions panel.<br />
First add a Click event listener to the button that willl be handled by the printContent function.<br />
Inside the function, in order to print the content we use the PrintJob class. To do so we create a new PrintJob instance.<br />
If needed we resize the content to fit within the page dimensions. Then we add the content as a page to the print job and send it to the printer.</p>
<pre class="brush: jscript;">
print_btn.addEventListener(MouseEvent.CLICK,printContent);

function printContent(evt:MouseEvent) {
	var printJob:PrintJob = new PrintJob();

	if (printJob.start()) {

		if (content_mc.width&gt;printJob.pageWidth) {
			content_mc.width=printJob.pageWidth;
			content_mc.scaleY=content_mc.scaleX;
		}

		printJob.addPage(content_mc);
		printJob.send();
	}
}
</pre>
<p><em>5.</em> Test your movie to see the code in action and print your content &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/how-to-print-with-as3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Draggable Area with AS3</title>
		<link>http://www.riacodes.com/flash/draggable-area-with-as3/</link>
		<comments>http://www.riacodes.com/flash/draggable-area-with-as3/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 15:53:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1208</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_draggable-area/preview.gif"/>]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick tip/tut that you might find useful to create a draggable area with actionscript 3.<br />
<span id="more-1208"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_draggable-area/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_draggable-area/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flash file (Actionscript 3.0) and save it as drag_area.fla. </p>
<p><em>2.</em> Rename &#8220;layer1&#8243; to &#8220;Area&#8221; and import on the stage an image much bigger than your stage and convert it to a movie clip with registration point at the top left. Give it an instance name of area_mc.</p>
<p><em>3.</em> Finally, create a new &#8220;actions&#8221; layer and open the actions panel. Type the code beneath. To create the draggable area, we use the startDrag method and specify its bounds parameter.</p>
<pre class="brush: jscript;">
area_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragArea);
area_mc.addEventListener(MouseEvent.MOUSE_UP, dropArea);

function dragArea(e:MouseEvent):void{
	var bounds:Rectangle = new Rectangle(
								stage.stageWidth - area_mc.width,
								stage.stageHeight - area_mc.height,
								area_mc.width - stage.stageWidth,
								area_mc.height - stage.stageHeight
							);
	area_mc.startDrag(false, bounds);
}

function dropArea(e:MouseEvent):void{
	area_mc.stopDrag();
}
</pre>
<p><em>4.</em> That&#8217;s it, test your movie to see it in action.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/draggable-area-with-as3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Year Countdown with AS3</title>
		<link>http://www.riacodes.com/flash/new-year-countdown-with-as3/</link>
		<comments>http://www.riacodes.com/flash/new-year-countdown-with-as3/#comments</comments>
		<pubDate>Tue, 29 Dec 2009 17:09:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1192</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_new-year-countdown/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>For the last tutorial of 2009, let&#8217;s create with actionscript 3 a countdown for the coming of 2010 new year.<br />
<span id="more-1192"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_new-year-countdown/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_new-year-countdown/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flash file (Actionscript 3.0) and save it as countdown.fla. </p>
<p><em>2.</em> On the first frame, create 4 dynamic text boxes to display numbers of days, hours, minutes and seconds remaining. Give them instance name of &#8220;day_txt&#8221;, &#8220;hour_txt&#8221;, &#8220;min_txt&#8221;, &#8220;sec_txt&#8221;.</p>
<p><em>3.</em> Create a blank keyframe and put in here what you want do display when the countdown is finished. Here we simply put a &#8220;Happy New Year ~ 2010&#8243; text.</p>
<p><em>3.</em> With the first frame selected open the actions panel to add some code.<br />
First put a stop() and  create a date object to store the 2010 new year date. Note that with AS3 month begins with 0, this is why we put month minus 1.<br />
Next create a timer and set its parameter to 1000 (1000ms = 1s). Add a timer event listener and call the start() method.</p>
<pre class="brush: jscript;">
stop();

var year:Number = 2010;
var month:Number = 1;
var day : Number = 1;

var finalDate:Date = new Date(year,month-1,day); 

var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, updateTime);
timer.start();
</pre>
<p><em>4.</em> Inside the updateTime function that handles the Timer event, create a new date object, to store the current date that will be updated every second.<br />
To calculate the remaining time, we simply make the difference between the final date and the current date.</p>
<pre class="brush: jscript;">
function updateTime(e:TimerEvent):void{

	var now:Date = new Date();
	var remainTime:Number = finalDate.getTime() - now.getTime();

}
</pre>
<p><em>5.</em> Still inside the updateTime function , we check whether the remaining time is superior to 0. If so, we make a series of calculations to retrieve the days, hours, minutes and seconds remaining. Also we check if the numbers are 2 digits so that we can add a 0 before to those who are just 1 digit. Finally we set the text properties of the 4 text boxes that we&#8217;ve put on the stage to their respective values. </p>
<pre class="brush: jscript;">
if (remainTime &gt;0) {

		var secs:Number = Math.floor(remainTime/1000);
		var mins:Number = Math.floor(secs/60);
		var hours:Number = Math.floor(mins/60);
		var days:Number = Math.floor(hours/24);

		var secsText:String = (secs%60).toString();
		var minsText:String = (mins%60).toString();
		var hoursText:String = (hours%24).toString();
		var daysText:String = days.toString();

		if (secsText.length &lt; 2) {secsText = &quot;0&quot; + secsText;}
		if (minsText.length &lt; 2) {minsText = &quot;0&quot; + minsText;}
		if (hoursText.length &lt; 2) {hoursText = &quot;0&quot; + hoursText;}
		if (daysText.length &lt; 2) {daysText = &quot;0&quot; + daysText;}

		day_txt.text = daysText;
		hour_txt.text = hoursText;
		min_txt.text = minsText;
		sec_txt.text = secsText;
}
</pre>
<p><em>6.</em> Else if the remaining time is <= 0 we remove the listener, stop the timer and display the second frame to wish you a Happy New Year.</p>
<p><em></em>Here&#8217;s the final code, test your movie to see it in action.</p>
<pre class="brush: jscript;">
stop();

var year:Number = 2010;
var month:Number = 1;
var day : Number = 1;

var finalDate:Date = new Date(year,month-1,day); 

var timer:Timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, updateTime);
timer.start();

function updateTime(e:TimerEvent):void{

	var now:Date = new Date();
	var remainTime:Number = finalDate.getTime() - now.getTime();

	if (remainTime &gt;0) {

		var secs:Number = Math.floor(remainTime/1000);
		var mins:Number = Math.floor(secs/60);
		var hours:Number = Math.floor(mins/60);
		var days:Number = Math.floor(hours/24);

		var secsText:String = (secs%60).toString();
		var minsText:String = (mins%60).toString();
		var hoursText:String = (hours%24).toString();
		var daysText:String = days.toString();

		if (secsText.length &lt; 2) {secsText = &quot;0&quot; + secsText;}
		if (minsText.length &lt; 2) {minsText = &quot;0&quot; + minsText;}
		if (hoursText.length &lt; 2) {hoursText = &quot;0&quot; + hoursText;}
		if (daysText.length &lt; 2) {daysText = &quot;0&quot; + daysText;}

		day_txt.text = daysText;
		hour_txt.text = hoursText;
		min_txt.text = minsText;
		sec_txt.text = secsText;
	}

	else {
		timer.removeEventListener(TimerEvent.TIMER, updateTime);
		timer.stop();
		gotoAndStop(2);
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/new-year-countdown-with-as3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Christmas Tree Lighting with AS3</title>
		<link>http://www.riacodes.com/flash/christmas-tree-lighting-with-as3/</link>
		<comments>http://www.riacodes.com/flash/christmas-tree-lighting-with-as3/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 15:22:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1167</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_christmas-tree/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>The following flash tutorial will guide you to create a Christmas Tree animation where the user can decorate the tree as he wishes and then put the light on to make the christmas bulbs sparkling.<br />
<span id="more-1167"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_christmas-tree/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_christmas-tree/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flash file (Actionscript 3.0) and save it as tree.fla. </p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;tree&#8221; and on this layer draw your christmas tree. Convert it to a movie clip and give it an instance name of &#8220;tree_mc&#8221;.</p>
<p><em>3.</em> Create a new layer named &#8220;bulbs&#8221;. On this layer create all kinds of bulbs that you want to put on your tree. Convert each bulb to a movie clip with registration point at the top left and export it for actionscript (class : RedBulb, BlueBulb, &#8230;).</p>
<p><img src="http://www.files.riacodes.com/flash_christmas-tree/1.gif" alt="Screenshot"/></p>
<p>Give each bulb an instance name of &#8220;red_bulb&#8221;, &#8220;blue_bulb&#8221; etc &#8230;</p>
<p><em>4.</em> Create a new layer named &#8220;light_btn&#8221;. Create a movie clip with 2 frames, the first for the ON state and the second for the OFF state. Give it an instance name of &#8220;light_mc&#8221;.</p>
<p><em>5.</em> Create an &#8220;actions&#8221; layer and with its first frame selected open the actions panel.<br />
There are 2 parts to do. The first part consists of creating the drag and drop bulbs that the user can put on the tree to his convenience. The second part consists of making the lighting.</p>
<p><em>6.</em> So let&#8217;s begin coding. First store all bulbs types in an array. When the user will interact with them a new bulb of the chosen type will be created. To do so, loop through the array to add a MouseDown event listener.</p>
<pre class="brush: jscript;">
var bulbsType : Array = [red_bulb, blue_bulb,yellow_bulb, purple_bulb, orange_bulb];

for (var i:int = 0; i&lt;bulbsType .length;i++){
	bulbsType [i].addEventListener(MouseEvent.MOUSE_DOWN, createBulb);
	bulbsType [i].buttonMode = true;
}
</pre>
<p><em>7.</em> Create an array that we use to store all bulbs that the user will put on the tree.</p>
<pre class="brush: jscript;">
var bulbs:Array  = new Array();
</pre>
<p>In the createBulb function, first we check which bulb type the user has chosen and create the matching bulb using the classes that we have created earlier by exporting each bulb type to actionscript.<br />
Then we call the startDrag method and add MouseUp and  MouseDown event listeners in order to create the drag and drop interactions.</p>
<pre class="brush: jscript;">
function createBulb(e:MouseEvent):void {
	var bulb:MovieClip;

	switch(e.target.name){
		case &quot;red_bulb&quot;:
			bulb = new RedBulb();
			break;
		case &quot;blue_bulb&quot;:
			bulb = new BlueBulb();
			break;
		case &quot;yellow_bulb&quot;:
			bulb = new YellowBulb();
			break;
		case &quot;purple_bulb&quot;:
			bulb = new PurpleBulb();
			break;
		case &quot;orange_bulb&quot;:
			bulb = new OrangeBulb();
			break;
	}

	bulb.buttonMode = true;
	bulb.x = e.target.x;
	bulb.y = e.target.y;
	addChild(bulb);			

	bulb.startDrag();
	bulb.addEventListener(MouseEvent.MOUSE_DOWN, dragBulb);
	bulb.addEventListener(MouseEvent.MOUSE_UP, dropBulb);		

}
</pre>
<p><em>8.</em> The dragBulb function simply call the StartDrag method.<br />
The dropBulb function checks whether the bulb has hit the tree. If so it calls the stopDrag method and add the bulb to the array that contains all the bulbs.</p>
<pre class="brush: jscript;">
function dragBulb(e:MouseEvent):void {
	e.target.startDrag();
}

function dropBulb(e:MouseEvent):void {
	if (e.target.hitTestObject(tree_mc)){
		e.target.stopDrag();
		bulbs.push(e.target);
	}
}
</pre>
<p><em>9.</em> Now for the lighting part, we use a Timer to create the sparkling effect on the bulbs.<br />
When the light is ON we start the Timer and loop though the array containing all bulbs on the tree to change randomly their alpha property.<br />
When light is OFF we stop the Timer.  </p>
<pre class="brush: jscript;">
var lighting:Boolean = false;
light_mc.stop();
light_mc.buttonMode = true;
light_mc.addEventListener(MouseEvent.CLICK,toggleLight);

var timer:Timer = new Timer(200);
timer.addEventListener(TimerEvent.TIMER, lightOn);

function toggleLight(e:MouseEvent):void{
	if(!lighting){
		timer.start();
		light_mc.gotoAndStop(2);
		lighting = true;
	}
	else {
		timer.stop();
		light_mc.gotoAndStop(1);
		lighting = false;
		for (var i:int =0; i &lt; bulbs.length; i++){
  			var bulb:MovieClip = bulbs[i];
  			bulb.alpha = .5;
		}
	}
}

function lightOn(e:TimerEvent):void{
	for (var i:int =0; i &lt; bulbs.length; i++){
  		var bulb:MovieClip = bulbs[i];
  		bulb.alpha = Math.random();
	}
}
</pre>
<p><em></em> Here&#8217;s the final code, test your movie to see in action. Merry Christmas !!!</p>
<pre class="brush: jscript;">
var bulbsType : Array = [red_bulb, blue_bulb,yellow_bulb, purple_bulb, orange_bulb];

for (var i:int = 0; i&lt;bulbsType .length;i++){
	bulbsType [i].addEventListener(MouseEvent.MOUSE_DOWN, createBulb);
	bulbsType [i].buttonMode = true;
}

var bulbs:Array  = new Array();

function createBulb(e:MouseEvent):void {
	var bulb:MovieClip;

	switch(e.target.name){
		case &quot;red_bulb&quot;:
			bulb = new RedBulb();
			break;
		case &quot;blue_bulb&quot;:
			bulb = new BlueBulb();
			break;
		case &quot;yellow_bulb&quot;:
			bulb = new YellowBulb();
			break;
		case &quot;purple_bulb&quot;:
			bulb = new PurpleBulb();
			break;
		case &quot;orange_bulb&quot;:
			bulb = new OrangeBulb();
			break;
	}

	bulb.buttonMode = true;
	bulb.x = e.target.x;
	bulb.y = e.target.y;
	addChild(bulb);			

	bulb.startDrag();
	bulb.addEventListener(MouseEvent.MOUSE_DOWN, dragBulb);
	bulb.addEventListener(MouseEvent.MOUSE_UP, dropBulb);		

}

function dragBulb(e:MouseEvent):void {
	e.target.startDrag();
}

function dropBulb(e:MouseEvent):void {
	if (e.target.hitTestObject(tree_mc)){
		e.target.stopDrag();
		bulbs.push(e.target);
	}
}

var lighting:Boolean = false;
light_mc.stop();
light_mc.buttonMode = true;
light_mc.addEventListener(MouseEvent.CLICK,toggleLight);

var timer:Timer = new Timer(200);
timer.addEventListener(TimerEvent.TIMER, lightOn);

function toggleLight(e:MouseEvent):void{
	if(!lighting){
		timer.start();
		light_mc.gotoAndStop(2);
		lighting = true;
	}
	else {
		timer.stop();
		light_mc.gotoAndStop(1);
		lighting = false;
		for (var i:int =0; i &lt; bulbs.length; i++){
  			var bulb:MovieClip = bulbs[i];
  			bulb.alpha = .5;
		}
	}
}

function lightOn(e:TimerEvent):void{
	for (var i:int =0; i &lt; bulbs.length; i++){
  		var bulb:MovieClip = bulbs[i];
  		bulb.alpha = Math.random();
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/christmas-tree-lighting-with-as3/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Falling Snow Christmas Card with AS3</title>
		<link>http://www.riacodes.com/flash/falling-snow-christmas-card-with-as3/</link>
		<comments>http://www.riacodes.com/flash/falling-snow-christmas-card-with-as3/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 16:09:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1147</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_snow-christmas/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>This tutorial covers how you can create falling snow with actionscript 3 over an image to create an animated Christmas Card.</p>
<p><span id="more-1147"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_snow-christmas/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_snow-christmas/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flash file (Actionscript 3.0) and save it as snow.fla. </p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;card&#8221;. On this layer import the image of your choice that will be the card.<br />
In our example, the image was taken from <a href="http://www.xmas-wallpapers.com/Snowman-Wallpapers/laughing-christmas-snowmen/" target="_blank">www.xmas-wallpapers.com</a></p>
<p><em>3.</em> Create a new &#8220;actions&#8221; layer.<br />
First before writing the code, let&#8217;s create a snowflake. Draw the shape of your snowflake and convert it to a movie clip with registration point at the top left. Export if for Actionscript with a Class Name of Snowflake.<br />
Remove the snowflake that you&#8217;ve just created from the stage as now all will happen in the code.</p>
<p><em>4.</em> With the actions layers first frame selected, open the actions panel.<br />
First add an enterframe event listener : </p>
<pre class="brush: jscript;">
addEventListener(Event.ENTER_FRAME, createSnow);
</pre>
<p><em>5.</em> In the createSnow function that handles the enterframe event, we create a snowflake by using the Snowflake class  and set its x position to a random value. Also we add an enterframe listener to the snowflake in order to animate it.</p>
<pre class="brush: jscript;">
function createSnow(event:Event):void{
	var snowflake : Snowflake = new Snowflake();
	snowflake.x = Math.random() * stage.stageWidth;
	snowflake.y = 0 ;
	addChild(snowflake);
	snowflake.addEventListener(Event.ENTER_FRAME, moveSnowflake);
}
</pre>
<p><em>6.</em> In the moveSnowflake function, we check whether the snowflake is still visible on the stage by monitoring its y property.<br />
If so, we modify its y, alpha, scaleX and scaleY properties to make it falling and melting.<br />
Else as we don&#8217;t see anymore the snowflake, we remove its event listener and remove him from the display list.</p>
<pre class="brush: jscript;">
function moveSnowflake(e:Event):void{
	if(e.target.y &lt; stage.stageHeight){
		e.target.y += 10 + Math.random() * 5 ;
		e.target.alpha -= 0.015;
		e.target.scaleX = e.target.scaleY -= 0.01;

	}
	else{
		e.target.removeEventListener(Event.ENTER_FRAME,moveSnowflake);
		removeChild(e.target as Snowflake);
	}
}
</pre>
<p><em>7.</em> Here&#8217;s the final code, test your movie to see it in action. And Merry Christmas !!!</p>
<pre class="brush: jscript;">
addEventListener(Event.ENTER_FRAME, createSnow);

function createSnow(event:Event):void{
	var snowflake : Snowflake = new Snowflake();
	snowflake.x = Math.random() * stage.stageWidth;
	snowflake.y = 0 ;
	addChild(snowflake);
	snowflake.addEventListener(Event.ENTER_FRAME, moveSnowflake);
}

function moveSnowflake(e:Event):void{
	if(e.target.y &lt; stage.stageHeight){
		e.target.y += 10 + Math.random() * 5 ;
		e.target.alpha -= 0.015;
		e.target.scaleX = e.target.scaleY -= 0.01;

	}
	else{
		e.target.removeEventListener(Event.ENTER_FRAME,moveSnowflake);
		removeChild(e.target as Snowflake);
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/falling-snow-christmas-card-with-as3/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Smooth Horizontal Tweened Menu with AS3</title>
		<link>http://www.riacodes.com/flash/smooth-horizontal-menu-with-as3/</link>
		<comments>http://www.riacodes.com/flash/smooth-horizontal-menu-with-as3/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 14:27:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1128</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_smooth-horizontal-menu/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this new actionscript 3 tutorial, we are going to build a smooth horizontal tweened menu. As usual we use the Tweenlite engine.</p>
<p><span id="more-1128"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_smooth-horizontal-menu/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_smooth-horizontal-menu/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flash file (Actionscript 3.0) and save it as menu.fla. </p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;menu&#8221;. First we are going to design our arrow shaped menu items. To do it, with the rectangle tool selected draw a rectangle on the stage with the fill color of your choice and no stroke color. To create the end part of the menu_item use the polystar tool to create a triangle that you stick to the rectangle. Now with your menu item shape built, convert it to a Movie Clip with registration point at the top left. Give it an instance name of &#8220;menu1_mc&#8221;.</p>
<p><em>3.</em> To add the label to the menu item, double click on the movie clip you&#8217;ve just created so you can edit it.<br />
With the Text tool, draw a static text box and type your label. And we are done with this first menu item.</p>
<p><em>4.</em> Next create the others menu items by following the same steps. Once finished position each menu item one below the other and put all of them to the left of the stage so that only the triangle part is visible on the stage.</p>
<p><em>5.</em> Now let&#8217;s add the actionscript. We’ll use the Tweenlite engine so first if you don’t already have it go to <a href="http://blog.greensock.com/tweenlite/" target="_blank">http://blog.greensock.com/tweenlite/</a> to download the AS3 version.<br />
Extract the zip file and get the com directory. Place this directory at the same level of your flash file.</p>
<p><em>6.</em> Create a new &#8220;actions&#8221; layer and with its first frame selected open the actions panel.<br />
First to use the Tweenlite engine and its easing properites write the following statements : </p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.easing.*;
</pre>
<p><em>7. </em> Then create an array that contains each menu item&#8217;s instance name. Next loop through this array to add to each item the Mouse Event listeners (for the rollover, rollout and click events) and set their button mode to true so that a hand cursor appears when we hover them.</p>
<pre class="brush: jscript;">
var menu_items:Array = [menu1_mc,menu2_mc,menu3_mc,menu4_mc];

for (var i:int = 0; i&lt; menu_items.length; i++){
	menu_items[i].addEventListener(MouseEvent.ROLL_OVER,overHandler);
	menu_items[i].addEventListener(MouseEvent.ROLL_OVER,outHandler);
	menu_items[i].addEventListener(MouseEvent.CLICK,clickHandler );
	menu_items[i].buttonMode = true;
}
</pre>
<p><em>8.</em> The overHandler function uses the Tweenlite engine to change the x property of the menu item to 0 so that the menu item stretches out. Also we set the Tweenlite ease property to Bounce.easeOut to make it more catchy.</p>
<pre class="brush: jscript;">
function overHandler(e:MouseEvent):void{
	TweenLite.to(e.currentTarget,1,{x:0,ease:Bounce.easeOut});
}

&lt;em&gt;9.&lt;/em&gt; The outHandler function sets the menu item that triggered the rollout event back to its original position. And finally the clickHandler function simply trace which menu item was clicked.

[javascript]
function outHandler(e:MouseEvent):void{
	TweenLite.to(e.currentTarget,1,{x:-168,ease:Bounce.easeOut});
}

function clickHandler(e:MouseEvent ):void{
	trace(e.currentTarget.name + &quot; was clicked&quot;);
}
</pre>
<p><em>10.</em> Here&#8217;s the final code, test your movie to see it in action.</p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.easing.*;

var menu_items:Array = [menu1_mc,menu2_mc,menu3_mc,menu4_mc];

for (var i:int = 0; i&lt; menu_items.length; i++){
	menu_items[i].addEventListener(MouseEvent.ROLL_OVER,overHandler);
	menu_items[i].addEventListener(MouseEvent.ROLL_OUT,outHandler);
	menu_items[i].addEventListener(MouseEvent.CLICK,clickHandler );
	menu_items[i].buttonMode = true;
}

function overHandler(e:MouseEvent):void{
	TweenLite.to(e.currentTarget,1,{x:0,ease:Bounce.easeOut});
}
function outHandler(e:MouseEvent):void{
	TweenLite.to(e.currentTarget,1,{x:-168,ease:Bounce.easeOut});
}

function clickHandler(e:MouseEvent ):void{
	// TO DO ...
	trace(e.currentTarget.name + &quot; was clicked&quot;);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/smooth-horizontal-menu-with-as3/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Circular Menu with AS3</title>
		<link>http://www.riacodes.com/flash/circular-menu-with-as3/</link>
		<comments>http://www.riacodes.com/flash/circular-menu-with-as3/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 16:45:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1103</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_circular-menu/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this actionscript 3 lesson, let&#8217;s see how to create a nice circular menu that appears with a special effect.</p>
<p><span id="more-1103"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_circular-menu/" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flash_circular-menu/src.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flash file (Actionscript 3.0) and save it as menu.fla. </p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;actions&#8221;.<br />
We’ll use the Tweenlite engine so first if you don’t already have it go to <a href="http://blog.greensock.com/tweenlite/" target="_blank">http://blog.greensock.com/tweenlite/</a> to download the AS3 version.<br />
Extract the zip file and get the com directory. Place this directory at the same level of your flash file.</p>
<p><img src="http://www.files.riacodes.com/flash_circular-menu/3.jpg"/></p>
<p><em>3.</em> With the rectangle tool selected draw a black rectangle on the stage. Convert it to a Movie Clip and export it for Actionscript with a class name of myButton.</p>
<p><img src="http://www.files.riacodes.com/flash_circular-menu/1.jpg" alt="Screenshot"/></p>
<p><em>4.</em> Double click on the movie clip to edit it. With the Text tool selected draw a Dynamic Text box and set its color property to white. As we are going to rotate the text, embed your font by clicking on the Embed&#8230; button. In our case we just embed the Uppercase[A-Z].<br />
Give the movie clip an instance name of labelBtn.</p>
<p><img src="http://www.files.riacodes.com/flash_circular-menu/2.jpg" alt="Screenshot"/></p>
<p><em>5.</em> Return to Scene1 and remove the movieclip we&#8217;ve just created from the stage.</p>
<p><em>6</em> With the first frame selected of the actions layer, open the actions panel.<br />
First to use the Tweenlite engine write the following imports : </p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.easing.*;
</pre>
<p><em>7. </em> Then create an array that contains each menu item label.<br />
Next create a menu Sprite and position it at the center of the stage.</p>
<pre class="brush: jscript;">
var menu_items:Array = [&quot;HOME&quot;,&quot;ABOUT ME&quot;,&quot;PORTFOLIO&quot;,&quot;BLOG&quot;,&quot;CONTACT&quot;];

var menu:Sprite = new Sprite();
menu.x= stage.stageWidth / 2;
menu.y=stage.stageHeight /2;
addChild(menu);
</pre>
<p><em>8.</em> Now we need to create each menu items and to do that create a buildMenu function.<br />
Inside this function, we loop through the menu_items array to create different &#8220;myButton&#8221; items.<br />
To position and animate each item, we use Tweenlite to set their rotation property to a different value.</p>
<pre class="brush: jscript;">
function buildMenu(){

	var btn:myButton;
	var angle:int=360/menu_items.length;

	for (var i:int = 0; i&lt; menu_items.length; i++){
		btn = new myButton();
		btn.buttonMode=true;
		btn.labelBtn.text = menu_items[i];
		btn.mouseChildren=false;
		menu.addChild(btn);
		TweenLite.to(btn,2,{rotation: -i*angle,ease:Bounce.easeOut});
	}
}
</pre>
<p><em>9.</em> Finally we add a Click event listener to the menu and let you continue.</p>
<pre class="brush: jscript;">
menu.addEventListener(MouseEvent.CLICK,clickHandler );

function clickHandler(e:MouseEvent ):void{
	// TO DO ...
	trace(myButton(e.target).labelBtn.text);
}
</pre>
<p><em>10.</em> Here&#8217;s the final code, test your movie to see it in action.</p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.easing.*;

var menu_items:Array = [&quot;HOME&quot;,&quot;ABOUT ME&quot;,&quot;PORTFOLIO&quot;,&quot;BLOG&quot;,&quot;CONTACT&quot;];

var menu:Sprite = new Sprite();
menu.x= stage.stageWidth / 2;
menu.y=stage.stageHeight /2;

addChild(menu);
buildMenu();

function buildMenu(){

	var btn:myButton;
	var angle:int=360/menu_items.length;

	for (var i:int = 0; i&lt; menu_items.length; i++){
		btn = new myButton();
		btn.buttonMode=true;
		btn.labelBtn.text = menu_items[i];
		btn.mouseChildren=false;
		menu.addChild(btn);
		TweenLite.to(btn,2,{rotation: -i*angle,ease:Bounce.easeOut});
	}
}

menu.addEventListener(MouseEvent.CLICK,clickHandler );

function clickHandler(e:MouseEvent ):void{
	// TO DO ...
	trace(myButton(e.target).labelBtn.text);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/circular-menu-with-as3/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Create a Show/Hide Sliding Panel using Flex</title>
		<link>http://www.riacodes.com/flex/create-a-show-hide-sliding-panel-using-flex/</link>
		<comments>http://www.riacodes.com/flex/create-a-show-hide-sliding-panel-using-flex/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 15:16:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1083</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flex_sliding-panel/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>This tutorial will show you how to add a nice hide/show sliding panel at the top of your flex application that when clicked will reveal itself.<br />
<span id="more-1083"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flex_sliding-panel/demo" target="_blank"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/demo.png" alt="View Demo" /></a><a href="http://www.files.riacodes.com/flex_sliding-panel/demo/srcview/SlidingPanel.zip"><img src="http://www.riacodes.com/wp-content/themes/riacodes/images/icons/download.png" alt="Download Source" /></a></div>
<p><em>1.</em> Create a new flex project named SlidingPanel, set the name of the main MXML application file to Main.mxml and set its layout to absolute. </p>
<p><em>2.</em> First let&#8217;s create the top panel. To do so add a Canvas component and give it an id of &#8220;panel&#8221;. To make it open or close, add a Button at the bottom of the canvas and set its properties as shown in the code below. Its click event will be handled by the toggleBtn function that we are going to create later.<br />
When the application will be launched we want only the button &#8220;Open&#8221; to be visible so in order to do that set the canvas y property to -180.</p>
<pre class="brush: xml;">
&lt;mx:Canvas id=&quot;panel&quot; width=&quot;100%&quot; height=&quot;200&quot; y=&quot;-180&quot; backgroundColor=&quot;#000000&quot;&gt;
		&lt;mx:LinkButton id=&quot;btn&quot; width=&quot;100%&quot;  height=&quot;21&quot;
			bottom=&quot;0&quot; horizontalCenter=&quot;0&quot;
			label=&quot;Open&quot;
		  	click=&quot;toggleBtn(event)&quot;/&gt;
&lt;/mx:Canvas&gt;
</pre>
<p>We let you put your own content inside this panel.</p>
<p><em>3.</em> To make the panel appear and disappear we need to create 2 Move effects, one to slide out and the other to slide in.<br />
The first one will be used to open the panel. To do so set its yTo property to 0 so that the panel is fully visible and when its effectEnd event will occur we set the label property of the button to &#8220;Close&#8221;.<br />
Follow the same process for the second Move effect that we&#8217;ll use to close the panel.<br />
To make these effects more eye-catching, we add a bounce easing.</p>
<pre class="brush: xml;">
&lt;mx:Move id=&quot;panelOut&quot; target=&quot;{panel}&quot; yTo=&quot;0&quot; effectEnd=&quot;btn.label='Close'&quot;
		duration=&quot;1500&quot; easingFunction=&quot;Bounce.easeOut&quot;/&gt;
&lt;mx:Move id=&quot;panelIn&quot; target=&quot;{panel}&quot; yTo=&quot;-180&quot; effectEnd=&quot;btn.label='Open'&quot;
		duration=&quot;1000&quot; easingFunction=&quot;Bounce.easeIn&quot;/&gt;
</pre>
<p><em>4.</em> Next add a Script section to create the toggleBtn function. In this function we check whether the panel is opened or not and we play the corresponding Move effect.</p>
<pre class="brush: jscript;">
&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.effects.easing.*;

			private function toggleBtn(e:MouseEvent):void{
				if(e.currentTarget.label== 'Open')
					 panelOut.play();
				else
					panelIn.play();
			}
		]]&gt;
&lt;/mx:Script&gt;
</pre>
<p><em>5.</em> Finally we add some CSS to custom the app.</p>
<pre class="brush: xml;">
&lt;mx:Style&gt;
		Application{
		   backgroundGradientColors: #E2DEDE, #3C2580;
		}
		LinkButton {
		   rollOverColor: #000000;
		   selectionColor: #000000;
		   color: #ffffff;
		   textRollOverColor: #ffffff;
		   textAlign: center;
		}
&lt;/mx:Style&gt;
</pre>
<p><em></em> Here&#8217;s the final code, run your application to see it in action.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot; layout=&quot;absolute&quot;&gt;

	&lt;mx:Style&gt;
		Application{
		   backgroundGradientColors: #E2DEDE, #3C2580;
		}
		LinkButton {
		   rollOverColor: #000000;
		   selectionColor: #000000;
		   color: #ffffff;
		   textRollOverColor: #ffffff;
		   textAlign: center;
		}
	&lt;/mx:Style&gt;

	&lt;mx:Script&gt;
		&lt;![CDATA[
			import mx.effects.easing.*;

			private function toggleBtn(e:MouseEvent):void{
				if(e.currentTarget.label== 'Open')
					 panelOut.play();
				else
					panelIn.play();
			}
		]]&gt;
	&lt;/mx:Script&gt;

	&lt;mx:Move id=&quot;panelOut&quot; target=&quot;{panel}&quot; yTo=&quot;0&quot; effectEnd=&quot;btn.label='Close'&quot;
		duration=&quot;1500&quot; easingFunction=&quot;Bounce.easeOut&quot;/&gt;
	&lt;mx:Move id=&quot;panelIn&quot; target=&quot;{panel}&quot; yTo=&quot;-180&quot; effectEnd=&quot;btn.label='Open'&quot;
		duration=&quot;1000&quot; easingFunction=&quot;Bounce.easeIn&quot;/&gt;        

	&lt;mx:Canvas id=&quot;panel&quot; width=&quot;100%&quot; height=&quot;200&quot; y=&quot;-180&quot; backgroundColor=&quot;#000000&quot;&gt;
       &lt;!--Add the content of your sliding panel here  --&gt;
		&lt;mx:LinkButton id=&quot;btn&quot; width=&quot;100%&quot;  height=&quot;21&quot;
			bottom=&quot;0&quot; horizontalCenter=&quot;0&quot;
			label=&quot;Open&quot;
		  	click=&quot;toggleBtn(event)&quot;/&gt;
	&lt;/mx:Canvas&gt;

	&lt;!--Add the content of your page here--&gt;

&lt;/mx:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flex/create-a-show-hide-sliding-panel-using-flex/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
