<?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 &#187; Flash</title>
	<atom:link href="http://www.riacodes.com/category/flash/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>Thu, 15 Jul 2010 16:11:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Colorful Animated Menu with AS3</title>
		<link>http://www.riacodes.com/flash/colorful-animated-menu-with-as3/</link>
		<comments>http://www.riacodes.com/flash/colorful-animated-menu-with-as3/#comments</comments>
		<pubDate>Thu, 15 Jul 2010 15:19:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1464</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_colorful-menu/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this simple tut, let&#8217;s create a colorful horizontal menu with mouse over animation by using Actionscript 3 and the Tweenlite engine.<br />
<span id="more-1464"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_colorful-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_colorful-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> First let&#8217;s create the &#8220;template&#8221; button that will use to create the menu.<br />
Create a Movie Clip (Insert>New Symbol) and give it a name of MyBtn.<br />
Export you button for actionscript with a class name of MyBtn.<br />
Inside this movie clip reproduce the same thing as shown below:</p>
<p><img src="http://files.riacodes.com/flash_colorful-menu/1.gif" alt="Screenshot"/></p>
<p><em>3.</em> Open the actions panel. We’ll use the Tweenlite engine so first if you don’t already have it<br />
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.<br />
First write the following statements to use Tweenlite. We&#8217;ll use the Tint plugin to manage the colors so we need to activate it.(More infos at http://www.greensock.com/tweenlite/).</p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.plugins.*;
TweenPlugin.activate([TintPlugin]);
</pre>
<p><em>4.</em> Next store the label buttons in an array and their colors inside another array.</p>
<pre class="brush: jscript;">
var btnsArray:Array = [&quot;Home&quot;, &quot;News&quot;, &quot;About&quot;, &quot;Contact&quot;, &quot;Info&quot;];
var colors:Array= [0xFF0000,0x66CC00,0XFF9933,0x6633FF,0xFF33CC,0x660066];
</pre>
<p><em>5.</em> Then write a createButtons() function.<br />
Loop through the btnsArray. For each button, we use the MyBtn class that we&#8217;ve previously declared and use Tweenlite to change the tint property of the button&#8217;s rectangle.<br />
We set its x and y properties and its label by setting the btn_label text property.</p>
<p>Then we add the different mouse event listeners and add the button to the display list.</p>
<pre class="brush: jscript;">
createButtons();

function createButtons ():void{
	for (var i :uint= 0; i &lt; btnsArray.length; i++){
		var btn:MyBtn = new MyBtn();
		TweenLite.to (btn.btn_rect, 0, {tint: colors[i]});
		btn.x = i*115;
		btn.y = 0;
		btn.btn_label.text = btnsArray[i];

		btn.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
		btn.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
		btn.addEventListener(MouseEvent.CLICK, btnClick);

		btn.buttonMode = true;
		btn.mouseChildren = false;
		addChild (btn);
	}
}
</pre>
<p><em>6.</em> In the btnOver() function we change the button label color and increase the height of the rectangle.</p>
<pre class="brush: jscript;">
function btnOver (e:MouseEvent):void{
	var mc:MovieClip = e.currentTarget as MovieClip;
	TweenLite.to (mc.btn_label, .5, {tint: 0xFFFFFF});
	TweenLite.to (mc.btn_rect,.5, {height: 35});
}
}
</pre>
<p><em>7.</em> In the btnOut() function we reset the btn label color to black and decrease the height of the rectangle.</p>
<pre class="brush: jscript;">
function btnOut (e:MouseEvent):void{
	var mc:MovieClip = e.currentTarget as MovieClip;
	TweenLite.to (mc.btn_label, .5, {tint: 0x000000});
	TweenLite.to (mc.btn_rect, .5, {height: 5});
}
</pre>
<p><em>9.</em> Finally for the btnClick() function we let you continue write your own code. </p>
<pre class="brush: jscript;">
function btnClick(e:MouseEvent):void{
	//do your stuff here
}
</pre>
<p><em>10.</em> That&#8217;s it. 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.plugins.*;
TweenPlugin.activate([TintPlugin]);

var btnsArray:Array = [&quot;Home&quot;, &quot;News&quot;, &quot;About Me&quot;, &quot;Infos&quot;,&quot;Contact&quot;,];
var colors:Array= [0xFF0000,0x66CC00,0XFF9933,0x6633FF,0xFF33CC,0x660066];

createButtons();

function createButtons ():void{
	for (var i :uint= 0; i &lt; btnsArray.length; i++){
		var btn:MyBtn = new MyBtn();
		TweenLite.to (btn.btn_rect, 0, {tint: colors[i]});
		btn.x = i*115;
		btn.y = 0;
		btn.btn_label.text = btnsArray[i];

		btn.addEventListener(MouseEvent.MOUSE_OUT, btnOut);
		btn.addEventListener(MouseEvent.MOUSE_OVER, btnOver);
		btn.addEventListener(MouseEvent.CLICK, btnClick);

		btn.buttonMode = true;
		btn.mouseChildren = false;
		addChild (btn);
	}
}

function btnOver (e:MouseEvent):void{
	var mc:MovieClip = e.currentTarget as MovieClip;
	TweenLite.to (mc.btn_label, .5, {tint: 0xFFFFFF});
	TweenLite.to (mc.btn_rect,.5, {height: 35});
}

function btnOut (e:MouseEvent):void{
	var mc:MovieClip = e.currentTarget as MovieClip;
	TweenLite.to (mc.btn_label, .5, {tint: 0x000000});
	TweenLite.to (mc.btn_rect, .5, {height: 5});
}

function btnClick(e:MouseEvent):void{
	//do your stuff here
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/colorful-animated-menu-with-as3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Change the Text Column Layout with Flash CS5 and AS3</title>
		<link>http://www.riacodes.com/flash/change-the-text-column-layout-with-flash-cs5-and-as3/</link>
		<comments>http://www.riacodes.com/flash/change-the-text-column-layout-with-flash-cs5-and-as3/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 18:37:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1443</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_change-text-column-layout/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this first Flash CS5 tutorial, let&#8217;s start exploring Flash CS5 new features by creating an app using the Text Layout Framework where the user can change the text column layout. </p>
<p><span id="more-1443"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_change-text-column-layout/" 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_change-text-column-layout/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> With Flash CS5, create a new Flash file (Actionscript 3.0) and save it as columns.fla.</p>
<p><em>2.</em> Rename &#8220;Layer 1&#8243; to &#8220;Text&#8221;. With the Text tool selected, verify that it is set on TLF Text and draw a text box. </p>
<p><img src="http://www.files.riacodes.com/flash_change-text-column-layout/1.gif" alt="Screenshot"/></p>
<p>Give it an instance name of &#8220;tlf&#8221; and paste your text in it. </p>
<p><em>3.</em> Create a new layer named &#8220;button&#8221;. Create 3 buttons and give them instance names of &#8220;btn1&#8243;, &#8220;btn2&#8243; and &#8220;btn3&#8243;.</p>
<p><em>4.</em> Create a new &#8220;actions layer&#8221; and open the actions panel. First add the CLICK event listener to the three buttons.</p>
<pre class="brush: jscript;">
btn1.addEventListener(MouseEvent.CLICK, layoutColumns);
btn2.addEventListener(MouseEvent.CLICK, layoutColumns);
btn3.addEventListener(MouseEvent.CLICK, layoutColumns);
</pre>
<p><em>5.</em> Inside the layoutColumns() function we check which button has triggered the Click event to change the number of text columns and the gap between them accordingly. To do so we use the &#8220;columnCount&#8221; and &#8220;columnGap&#8221; properties of the new <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flashx/textLayout/formats/TextLayoutFormat.html" target="_blank">TextLayoutFormat</a> class.</p>
<pre class="brush: jscript;">
function layoutColumns(evt:MouseEvent):void {
	switch(evt.currentTarget.name){
		case &quot;btn1&quot; :
			tlf.columnCount =  1;
			break;
		case &quot;btn2&quot; :
			tlf.columnCount =  2;
			tlf.columnGap = 30;
			break;
		case &quot;btn3&quot; :
			tlf.columnCount =  3;
			tlf.columnGap = 20;
			break;
	}
}
</pre>
<p><em>6.</em> That&#8217;s it, here&#8217;s the final code, test your movie to see it in action.</p>
<pre class="brush: jscript;">
btn1.addEventListener(MouseEvent.CLICK, setColumn);
btn2.addEventListener(MouseEvent.CLICK, setColumn);
btn3.addEventListener(MouseEvent.CLICK, setColumn);

function setColumn(evt:MouseEvent):void {
	switch(evt.currentTarget.name){
		case &quot;btn1&quot; :
			tf.columnCount =  1;
			break;
		case &quot;btn2&quot; :
			tf.columnCount =  2;
			tf.columnGap = 30;
			break;
		case &quot;btn3&quot; :
			tf.columnCount =  3;
			tf.columnGap = 20;
			break;
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/change-the-text-column-layout-with-flash-cs5-and-as3/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Vertical Flip Effect Animation</title>
		<link>http://www.riacodes.com/flash/vertical-flip-effect-animation/</link>
		<comments>http://www.riacodes.com/flash/vertical-flip-effect-animation/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 18:45:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1427</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_vertical-flip-animation/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>Another easy and quick tutorial to animate movie clips using the Tweenlite engine. In this one, we are going to animate a &#8220;Welcome&#8221; text with a vertical flip effect.<br />
<span id="more-1427"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_vertical-flip-animation/" 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_vertical-flip-animation/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> With Flash CS4 or CS5, create a new flash file (Actionscript 3.0) and save it as flip.fla.</p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;content&#8221;. Create all your movie clips that you want to animate. Set their registration point at the center.</p>
<p><em>3.</em> Create a new layer named &#8220;butttn&#8221;. Create your button and set its instance name to &#8220;btn&#8221;.</p>
<p><em>4.</em> Create a new &#8220;actions&#8221; layer. We’ll use the Tweenlite engine, so first if you don’t already have it go <a href="http://www.greensock.com/tweenlite/" target="_blank">download its AS3 version.</a> Open the actions panel.<br />
First make the following import in order to use it.</p>
<pre class="brush: jscript;">
import com.greensock.*;
</pre>
<p><em>5.</em> At first we don&#8217;t want to see the movie clips. Loop through all the objects contained in &#8220;content_mc&#8221; to set their alpha property to 0.</p>
<pre class="brush: jscript;">
function init():void{
	for (var i:int =0; i &lt; content_mc.numChildren; i++) {
		 var mc:MovieClip = content_mc.getChildAt(i) as MovieClip;
		 mc.alpha = 0;
	}
}
</pre>
<p><em>6.</em> Next add a CLICK event listener to the button.<br />
In the flipAll() function, we begin by removing the button from the stage.<br />
Next we loop through all the movie clips. For each, we set its index to 0 so that if ever a movie clip intersects with one which is in front of it, this movie clip will stay at the back. And we use the Tweenlite engine to animate its alpha, rotationX and z properties. We specify the delay parameter to make the movie clips appear one after another.</p>
<pre class="brush: jscript;">
btn.addEventListener(MouseEvent.CLICK,flipAll);

function flipAll(e:MouseEvent):void{
	removeChild(btn);
	for (var i:int = 0; i &lt; content_mc.numChildren; i++){
     		var mc:MovieClip = content_mc.getChildAt(i) as MovieClip;
			content_mc.setChildIndex(mc,0);
			TweenLite.to(mc,.8,
						 {alpha: 1,
						 rotationX : mc.rotationX -360,
						 z:mc.z - 200,
						 delay: i*.3}
						 );
	}
}
</pre>
<p><em>7.</em> Here&#8217;s the final code, test your movie to see it in action.</p>
<pre class="brush: jscript;">
import com.greensock.*;

function init():void{
	for (var i:int =0; i &lt; content_mc.numChildren; i++) {
		 var mc:MovieClip = content_mc.getChildAt(i) as MovieClip;
		 mc.alpha = 0;
	}
}

btn.addEventListener(MouseEvent.CLICK,flipAll);

function flipAll(e:MouseEvent):void{
	removeChild(btn);
	for (var i:int = 0; i &lt; content_mc.numChildren; i++){
     		var mc:MovieClip = content_mc.getChildAt(i) as MovieClip;
			content_mc.setChildIndex(mc,0);
			TweenLite.to(mc,.8,
						 {alpha: 1,
						 rotationX : mc.rotationX -360,
						 z:mc.z - 200,
						 delay: i*.3}
						 );
	}
}

init();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/vertical-flip-effect-animation/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Swinging Image Effect with AS3</title>
		<link>http://www.riacodes.com/flash/swinging-image-effect-with-as3/</link>
		<comments>http://www.riacodes.com/flash/swinging-image-effect-with-as3/#comments</comments>
		<pubDate>Mon, 31 May 2010 22:57:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1411</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_swinging-image-effect/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this simple tutorial, let&#8217;s create a Swinging Image effect with Actionscript 3.<br />
<span id="more-1411"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_swinging-image-effect/" 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_swinging-image-effect/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> As we&#8217;ll use one of Flash Player 10’s 3D features, you need at least Flash CS4 to follow this tutorial.<br />
Create a new flash file (Actionscript 3.0) and save it as swingingImages.fla.</p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;content&#8221;. Import your images on the stage and convert each to a movie clip with registration point at the top left. Give them respective instance names of &#8220;pic1&#8243;, &#8220;pic2&#8243; etc&#8230;</p>
<p><em>3.</em> Create a new layer called &#8220;button&#8221;. Create your own button and give it an instance name of &#8220;btn&#8221;.</p>
<p><em>4.</em> Then create an &#8220;actions&#8221; layer. We&#8217;ll use the Tweenlite engine, so first if you don&#8217;t already have it go <a href="http://www.greensock.com/tweenlite/" target="_blank">download its AS3 version.</a> Open the actions panel.<br />
First make the following import in order to use it.</p>
<pre class="brush: jscript;">
import com.greensock.*;
</pre>
<p><em>5.</em> Store your images inside an array.</p>
<pre class="brush: jscript;">
var images : Array = [pic1,pic2,pic3,pic4]  ;
</pre>
<p><em>6.</em> Create an init() function to loop through the &#8220;images&#8221; array and set for each movie clip its alpha property to 0 and its rotationX property to 270. Thereby the images will be lifted and not visible.</p>
<pre class="brush: jscript;">
function init():void{
	for (var i:int = 0; i &lt; images.length; i++){
		var mc:MovieClip = images[i] as MovieClip;
		mc.alpha = 0;
		mc.rotationX = 270;
	}
}
</pre>
<p><em>7.</em> Next add a CLICK event listener to the button, event that will be handled by the swingImages function.<br />
Inside the swingImages function we first call the init() function.<br />
Then we loop through the &#8220;images&#8221; array and use the Tweenlite engine to animate its alpha and rotationX property. We specify the delay parameter to make the images appear one after another.</p>
<pre class="brush: jscript;">
btn.addEventListener(MouseEvent.CLICK,swingImages);

function swingImages(e:MouseEvent):void{
	init();
	for (var i:int = 0; i &lt; images.length; i++){
     		var mc:MovieClip = images[i] as MovieClip;
            TweenLite.to(mc,.5,{alpha: 1,rotationX: 0,delay: i*.4});
	}
}
</pre>
<p><em>8.</em> Finally call the init() function so that the images are not visible  at the beginning.<br />
Here&#8217;s the final code, test your movie to see it in action.</p>
<pre class="brush: jscript;">
import com.greensock.*;

var images : Array = [pic1,pic2,pic3,pic4] ;

function init():void{
	for (var i:int = 0; i &lt; images.length; i++){
		var mc:MovieClip = images[i] as MovieClip;
		mc.alpha = 0;
		mc.rotationX = 270;
	}
}

btn.addEventListener(MouseEvent.CLICK,swingImages);

function swingImages(e:MouseEvent):void{
	init();
	for (var i:int = 0; i &lt; images.length; i++){
     		var mc:MovieClip = images[i] as MovieClip;
            TweenLite.to(mc,.5,{alpha: 1,rotationX: 0,delay: i*.4});
	}
}

init();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/swinging-image-effect-with-as3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Typewriter Text Effect with AS3</title>
		<link>http://www.riacodes.com/flash/typewriter-text-effect-with-as3/</link>
		<comments>http://www.riacodes.com/flash/typewriter-text-effect-with-as3/#comments</comments>
		<pubDate>Wed, 26 May 2010 13:25:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1393</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_typewriter-text-effect/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>Quick &#038; easy code : see how to create a typewriter text effect with Actionscript 3. The text to be displayed will be loaded from a txt file.</p>
<p><span id="more-1393"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_typewriter-text-effect/" 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_typewriter-text-effect/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 typewriter.fla.</p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;actions&#8221;. Open the actions panel.<br />
Declare the following variables:</p>
<pre class="brush: jscript;">
var myText:String;
var counter:int = 0;
</pre>
<p><em>3.</em> Create a TextFormat object in order to format our text.</p>
<pre class="brush: jscript;">
var format : TextFormat = new TextFormat();
format.size = 16;
format.font = &quot;Verdana&quot;;
format.bold = true;
format.color = 0xFFFFFF;
</pre>
<p><em>4.</em> Create a TextField, set its properties as follow and add it to the display list.</p>
<pre class="brush: jscript;">
var textField : TextField = new TextField();
textField.width = 600;
textField.height = 350;
textField.selectable = false;
textField.wordWrap = true;
textField.defaultTextFormat = format;
textField.x = textField.y =10;
addChild(textField);
</pre>
<p><em>5.</em> Next create an initText function that set the &#8220;myText&#8221; variable to the string passed as argument. Also add an ENTER_FRAME event listener.</p>
<pre class="brush: jscript;">
function initText(string:String):void{
	myText = string;
	addEventListener(Event.ENTER_FRAME, writeText);
}
</pre>
<p><em>6.</em> The writeText function checks whether the counter variable is inferior or equal to the length of &#8220;myText&#8221;.<br />
While it&#8217;s true, we use the substr method that returns a substring consisting of the characters that start at index 0 and with a length specified by counter. When it becomes false, we remove the ENTER_FRAME listener.</p>
<pre class="brush: jscript;">
function writeText(e:Event):void{
	if (counter &lt;= myText.length){
   	     textField.text = myText.substr(0,counter);
   	     counter++;
	}
	else{
		removeEventListener(Event.ENTER_FRAME,writeText);
	}
}
</pre>
<p><em>7.</em> The text to be display is stored inside a text file.  So create your text file, type your own text and save it as text.txt inside the same directory of your fla file. Then load the file. When the load is complete, it simply calls the initText function.</p>
<pre class="brush: jscript;">
var textLoader:URLLoader = new URLLoader(new URLRequest(&quot;text.txt&quot;));
textLoader.addEventListener(Event.COMPLETE, function(e:Event){initText(e.target.data);});
</pre>
<p><em>8.</em> Here&#8217;s the final code, test your movie to see in action.</p>
<pre class="brush: jscript;">
var myText:String;
var counter:int = 0; 

var format : TextFormat = new TextFormat();
format.size = 16;
format.font = &quot;Verdana&quot;;
format.bold = true;
format.color = 0xFFFFFF; 

var textField : TextField = new TextField();
textField.width = 600;
textField.height = 350;
textField.selectable = false;
textField.wordWrap = true;
textField.defaultTextFormat = format;
textField.x = textField.y =10;
addChild(textField);

var textLoader:URLLoader = new URLLoader(new URLRequest(&quot;text.txt&quot;));
textLoader.addEventListener(Event.COMPLETE, function(e:Event){initText(e.target.data);});

function initText(string:String):void{
	myText = string;
	addEventListener(Event.ENTER_FRAME, writeText);
}

function writeText(e:Event):void{
	if (counter &lt;= myText.length){
   	     textField.text = myText.substr(0,counter);
   	     counter++;
	}
	else{
		removeEventListener(Event.ENTER_FRAME,writeText);
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/typewriter-text-effect-with-as3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Build a XML Driven Horizontal Images Slider</title>
		<link>http://www.riacodes.com/flash/build-a-driven-xml-horizontal-images-slider/</link>
		<comments>http://www.riacodes.com/flash/build-a-driven-xml-horizontal-images-slider/#comments</comments>
		<pubDate>Mon, 24 May 2010 11:07:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1355</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_horizontal-images-slider-xml/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this Actionscript 3 tutorial, learn step by step how to build a XML driven Horizontal World Cup Images Slider that the user controls with buttons or keyboard.</p>
<p><span id="more-1355"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_horizontal-images-slider-xml/" 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_horizontal-images-slider-xml/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 images-slider.fla.</p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;buttons&#8221;. Create the previous and next buttons and give them respective instance names of &#8220;previous_btn&#8221; and &#8220;next_btn&#8221;.</p>
<p><img src="http://www.files.riacodes.com/flash_horizontal-images-slider-xml/1.gif" alt="Screenshot"/></p>
<p><em>3.</em> Create a new layer named &#8220;loading infos&#8221;. With the Text tool, create a Dynamic text and give it an instance name of &#8220;loading_txt&#8221;. We&#8217;ll use it later to inform the user about the images&#8217; loading progression.</p>
<p><em>4.</em> Create a new layer named &#8220;container&#8221;.<br />
First let&#8217;s create a mask that will use to display only 3 images on the screen. As our images are 260px*196px, and that we want to display 3 images and let some space between the images (10px), in our case we have drawn a Rectangle of 800px*196px. Adjust the rectangle size according to your needs. Convert it to a Movie Clip with an instance name of &#8220;slider_mc&#8221;. Enter this movie clip to edit it. Reselect the rectangle shape and convert it to a Movie clip with an instance name of &#8220;mask_mc&#8221;. </p>
<p><em>5.</em> We&#8217;ll store the images&#8217; datas in an XML file. Create an xml file that match the following structure and save it as datas.xml. Put all your images inside an &#8220;images&#8221; folder.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?&gt;
&lt;images&gt;
	&lt;image src=&quot;1.jpg&quot;/&gt;
	&lt;image src=&quot;2.jpg&quot;/&gt;
	&lt;image src=&quot;3.jpg&quot;/&gt;
	&lt;image src=&quot;4.jpg&quot;/&gt;
	&lt;image src=&quot;5.jpg&quot;/&gt;
	&lt;image src=&quot;6.jpg&quot;/&gt;
	&lt;image src=&quot;7.jpg&quot;/&gt;
	&lt;image src=&quot;8.jpg&quot;/&gt;
	&lt;image src=&quot;9.jpg&quot;/&gt;
	&lt;image src=&quot;10.jpg&quot;/&gt;
	&lt;image src=&quot;11.jpg&quot;/&gt;
	&lt;image src=&quot;12.jpg&quot;/&gt;
	&lt;image src=&quot;13.jpg&quot;/&gt;
	&lt;image src=&quot;14.jpg&quot;/&gt;
	&lt;image src=&quot;15.jpg&quot;/&gt;
	&lt;image src=&quot;16.jpg&quot;/&gt;
&lt;/images&gt;
</pre>
<p><em>6.</em> Create an &#8220;actions&#8221; layer.  We&#8217;ll use the Tweenlite engine, so first go <a href="http://www.greensock.com/tweenlite/" target="_blank">download its AS3 version.</a> Open the actions panel.<br />
First make the following imports in order to use the Twenlite engine and its easing properties.</p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.easing.*;
</pre>
<p><em>7.</em> Next declare the following variables.</p>
<pre class="brush: jscript;">
var xml:XML;
var images:Array = new Array();
var totalImages:Number;
var nbDisplayed:Number = 3; // Number of images displayed on the screen
var imagesLoaded:int = 0;
var slideTo:Number = 0;
var imageWidth = 270;  // our images are 260px wide so we set to 270 to let some space when will position them
</pre>
<p><em>8.</em>  Create a new MovieClip where we&#8217;ll place all the images and set its mask property to the mask we&#8217;ve created before.</p>
<pre class="brush: jscript;">
var container_mc:MovieClip = new MovieClip();
slider_mc.addChild(container_mc);
container_mc.mask = slider_mc.mask_mc;
</pre>
<p><em>9.</em> Load the XML file by creating a loadXML funtion. When the load is complete, it will call the parseXML function.</p>
<pre class="brush: jscript;">
function loadXML(file:String):void{
	var xmlLoader:URLLoader = new URLLoader();
	xmlLoader.load(new URLRequest(file));
	xmlLoader.addEventListener(Event.COMPLETE, parseXML);
}
</pre>
<p><em>10.</em> Then we need to parse the XML. We set our xml variable to the xml data, get the total amount of images and call the loadImages function.</p>
<pre class="brush: jscript;">
function parseXML(e:Event):void{
	xml = new XML(e.target.data);
	totalImages = xml.children().length();
	loadImages();
}
</pre>
<p><em>11.</em> Inside the loadImages function, we create  a &#8220;for&#8221; statement to loop through the xml datas to create a Loader for each image. We store the Loader inside our images Array variable, and we add listeners for the ProgressEvent.PROGRESS event and the Event.COMPLETE event. </p>
<pre class="brush: jscript;">
function loadImages():void{
	for(var i:int = 0; i&lt;totalImages; i++){
		var loader:Loader = new Loader();
		loader.load(new URLRequest(&quot;images/&quot;+String(xml.children()[i].@src)));
		images.push(loader);
		loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgress);
	    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
	}
}
</pre>
<p><em>12.</em> The onProgress function is used to warn the user about the progression of the images&#8217; loading.</p>
<pre class="brush: jscript;">
function onProgress(e:ProgressEvent):void{
	loading_txt.text = &quot;Loading &quot; + imagesLoaded + &quot; / &quot; + totalImages;
}
</pre>
<p><em>13.</em> The onComplete function checks whether all images are loaded. If so, it calls the createImages() function.</p>
<pre class="brush: jscript;">
function onComplete(e:Event):void{
	imagesLoaded++;
	if(imagesLoaded == totalImages){
		loading_txt.text = &quot;&quot;;
		createImages();
	}
}
</pre>
<p><em>14.</em> Inside the createImages() function, create a &#8220;for&#8221; statement to loop through the images array in order to create a bitmap object. We set the x property of the bitmap by multiplying the i variable with our imageWidth variable. And we add the bitmap to the container_mc.</p>
<pre class="brush: jscript;">
function createImages():void{
	for(var i:int = 0; i &lt; images.length; i++){
		var bm:Bitmap = new Bitmap();
		bm = Bitmap(images[i].content);
		bm.smoothing = true;
		bm.x = i*imageWidth;
		container_mc.addChild(bm);
	}
}
</pre>
<p><em>15.</em> At this point, we&#8217;ve finished loading our images. Now let&#8217;s take care about the buttons to slide left and right.<br />
Add the CLICK event listeners for both buttons.</p>
<pre class="brush: jscript;">
previous_btn.addEventListener(MouseEvent.CLICK,slideLeft);
next_btn.addEventListener(MouseEvent.CLICK,slideRight);
</pre>
<p><em>16.</em> At the beginning, we&#8217;ve created a slideTo variable. We&#8217;ll use it to store the number of the image we want to slide to (the one that we see on the left).<br />
In the slideLeft function we want to go 3 (nbDisplayed = 3) images to the left whereas in the slideRight function we want to go 3 images to the right.</p>
<pre class="brush: jscript;">
function slideLeft(e:MouseEvent):void{
	slideTo -= nbDisplayed;
	slideContainer();
}

function slideRight(e:MouseEvent):void{
	slideTo += nbDisplayed;
	slideContainer();
}
</pre>
<p><em>17.</em> The slideContainer() functions checks at first if we can actually move that far to the left or right so that there&#8217;s always 3 images displayed. If not we set the slideTo variable to the appropriate value. Then we use the Tweenlite engine to animate the x property of &#8220;container_mc&#8221;.</p>
<pre class="brush: jscript;">
function slideContainer():void{
	if(totalImages - slideTo &lt; nbDisplayed)
		slideTo = totalImages - nbDisplayed;
	if(slideTo &lt; 0)
		slideTo = 0;

	TweenLite.to(container_mc,.5,{x:-slideTo*imageWidth,ease:Quad.easeIn});
}
</pre>
<p><em>18.</em> Next we add keyboard functionnality to allow the user to navigate with the right and left arrow keys.</p>
<pre class="brush: jscript;">
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);

function keyHandler(evt:KeyboardEvent) {
	if(evt.keyCode == Keyboard.LEFT)  slideLeft(evt);
	else if(evt.keyCode == Keyboard.RIGHT) slideRight(evt);
}
</pre>
<p><em>19.</em> Finally, don&#8217;t forget to call the loadXML function to make all that works.</p>
<pre class="brush: jscript;">
loadXML(&quot;datas.xml&quot;);
</pre>
<p><em>20. </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 xml:XML;
var images:Array = new Array();
var totalImages:Number;
var nbDisplayed:Number = 3;
var imagesLoaded:int = 0;
var slideTo:Number = 0;
var imageWidth = 270; 

var container_mc:MovieClip = new MovieClip();
slider_mc.addChild(container_mc);
container_mc.mask = slider_mc.mask_mc;

function loadXML(file:String):void{
	var xmlLoader:URLLoader = new URLLoader();
	xmlLoader.load(new URLRequest(file));
	xmlLoader.addEventListener(Event.COMPLETE, parseXML);
}

function parseXML(e:Event):void{
	xml = new XML(e.target.data);
	totalImages = xml.children().length();
	loadImages();
}

function loadImages():void{
	for(var i:int = 0; i&lt;totalImages; i++){
		var loader:Loader = new Loader();
		loader.load(new URLRequest(&quot;images/&quot;+String(xml.children()[i].@src)));
		images.push(loader);
		loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,onProgress);
	    loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
	}
}

function onProgress(e:ProgressEvent):void{
	loading_txt.text = &quot;Loading &quot; + imagesLoaded + &quot; / &quot; + totalImages;
}

function onComplete(e:Event):void{
	imagesLoaded++;
	if(imagesLoaded == totalImages){
		loading_txt.text = &quot;&quot;;
		createImages();
	}
}

function createImages():void{
	for(var i:int = 0; i &lt; images.length; i++){
		var bm:Bitmap = new Bitmap();
		bm = Bitmap(images[i].content);
		bm.smoothing = true;
		bm.x = i*imageWidth;
		container_mc.addChild(bm);
	}
}

previous_btn.addEventListener(MouseEvent.CLICK,slideLeft);
next_btn.addEventListener(MouseEvent.CLICK,slideRight);

function slideLeft(e:MouseEvent):void{
	slideTo -= nbDisplayed;
	slideContainer();
}

function slideRight(e:MouseEvent):void{
	slideTo += nbDisplayed;
	slideContainer();
} 

function slideContainer():void{
	if(totalImages - slideTo &lt; nbDisplayed)
		slideTo = totalImages - nbDisplayed;
	if(slideTo &lt; 0)
		slideTo = 0;

	TweenLite.to(container_mc,.5,{x: -slideTo*imageWidth,ease:Quad.easeIn});
}

stage.addEventListener(KeyboardEvent.KEY_DOWN,keyHandler);

function keyHandler(evt:KeyboardEvent) {
	if(evt.keyCode == Keyboard.LEFT)  slideLeft(evt);
	else if(evt.keyCode == Keyboard.RIGHT) slideRight(evt);
}

loadXML(&quot;datas.xml&quot;);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/build-a-driven-xml-horizontal-images-slider/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create a Flower Sprayer with AS3</title>
		<link>http://www.riacodes.com/flash/create-a-flower-sprayer-with-as3/</link>
		<comments>http://www.riacodes.com/flash/create-a-flower-sprayer-with-as3/#comments</comments>
		<pubDate>Thu, 20 May 2010 13:17:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1339</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_flower-sprayer/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this tut, let&#8217;s create a Summer Flower Sprayer with Actionscript 3 and Tweenlite.<br />
<span id="more-1339"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_flower-sprayer/" 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_flower-sprayer/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 spray.fla.</p>
<p><em>2.</em> First, create a movie clip with several frames, each frame containing a different flower.<br />
Export the movie clip for Actionscript and give it a Class name of Flower.</p>
<p><em>3.</em>  We&#8217;ll use the Tweenlite engine, so first go <a href="http://www.greensock.com/tweenlite/" target="_blank">download its AS3 version.</a> Open the actions panel.<br />
First make the following imports in order to use the Twenlite engine and its easing properties.</p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.easing.*;
</pre>
<p><em>4.</em> Next manage the events that interest us that is MOUSE_UP and MOUSE_DOWN.</p>
<pre class="brush: jscript;">
stage.addEventListener(MouseEvent.MOUSE_UP,stopSpray);
stage.addEventListener(MouseEvent.MOUSE_DOWN,startSpray);

function startSpray(e:MouseEvent):void {
	stage.addEventListener(Event.ENTER_FRAME,sprayFlowers);
}

function stopSpray(e:MouseEvent):void {
	stage.removeEventListener(Event.ENTER_FRAME,sprayFlowers);
}
</pre>
<p><em>5.</em> In the sprayFlower function, we create a new Flower object. At first, we choose a random flower by stopping on a random frame, position the flower according to the mouse position and scale it to 0.<br />
Then we use the Tweenlite engine to animate its x, y and rotation properties by setting their values to random numbers, and set the scaleX and scaleY properties to the same random value. Also we set the ease property to make the effect more catchy.</p>
<pre class="brush: jscript;">
function sprayFlowers(e:Event):void {
	var flower:MovieClip = new Flower();
	flower.gotoAndStop(Math.ceil(Math.random()*flower.totalFrames));
	flower.x = mouseX;
	flower.y = mouseY;
	flower.scaleX = flower.scaleY = 0;
	addChild(flower);
	var randomScale:Number = 1 + Math.random()*0.5 - 0.5;
	TweenLite.to(flower, 1,{ x: mouseX + Math.random() * 60 - 30,
							 y: mouseY + Math.random() * 60 - 30,
							 rotation: Math.random() * 90 - 45,
							 scaleX: randomScale, scaleY: randomScale,
							 ease:Bounce.easeOut});
}
</pre>
<p><em>6.</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.*;

stage.addEventListener(MouseEvent.MOUSE_UP,stopSpray);
stage.addEventListener(MouseEvent.MOUSE_DOWN,startSpray);

function startSpray(e:MouseEvent):void {
	stage.addEventListener(Event.ENTER_FRAME,sprayFlowers);
}

function stopSpray(e:MouseEvent):void {
	stage.removeEventListener(Event.ENTER_FRAME,sprayFlowers);
}
function sprayFlowers(e:Event):void {
	var flower:MovieClip = new Flower();
	flower.gotoAndStop(Math.ceil(Math.random()*flower.totalFrames));
	flower.x = mouseX;
	flower.y = mouseY;
	flower.scaleX = flower.scaleY = 0;
	addChild(flower);
	var randomScale:Number = 1 + Math.random()*0.5 - 0.5;
	TweenLite.to(flower, 1,{ x: mouseX + Math.random() * 60 - 30,
							 y: mouseY + Math.random() * 60 - 30,
							 rotation: Math.random() * 90 - 45,
							 scaleX: randomScale, scaleY: randomScale,
							 ease:Bounce.easeOut});
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/create-a-flower-sprayer-with-as3/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Create a Flash Photo Stack Gallery</title>
		<link>http://www.riacodes.com/flash/create-a-flash-photo-stack-gallery/</link>
		<comments>http://www.riacodes.com/flash/create-a-flash-photo-stack-gallery/#comments</comments>
		<pubDate>Thu, 06 May 2010 10:30:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1322</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_stack-gallery/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>Learn how to create an auto-played Photo Stack Gallery inside Flash with Actionscript 3 and Tweenlite.<br />
<span id="more-1322"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_stack-gallery/" 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_stack-gallery/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 stackGallery.fla.</p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;content&#8221;. Import your images on the stage and convert each to a movie clip with registration point at the top left. Arrange them into a stack.<br />
Select all your photos and convert the selection to a movie clip with registration point at the top left. Give it an instance name of &#8220;gallery&#8221;.</p>
<p><em>3.</em> Create a new &#8220;actions&#8221; layer. We&#8217;ll use the Tweenlite engine, so first go <a href="http://www.greensock.com/tweenlite/" target="_blank">download its AS3 version.</a><br />
Open the actions panel.<br />
First make the following imports that in order to use the Twenlite engine and its easing properties.</p>
<pre class="brush: jscript;">
import com.greensock.*;
import com.greensock.easing.*;
</pre>
<p><em>4.</em> Next as we want the gallery to auto-play, we&#8217;ll use a Timer. </p>
<pre class="brush: jscript;">
var timer:Timer = new Timer(4000);
timer.addEventListener(TimerEvent.TIMER,showNext);
timer.start();
</pre>
<p><em>5.</em> The showNext function consists of moving the stack&#8217;s front photo to the right so that the next photo appears.<br />
To do so, retrieve the front photo and use the Tweenlite engine to change its x, y and rotation properties.<br />
When this Tween will be complete, we call the moveBack function.</p>
<pre class="brush: jscript;">
var frontPhoto:MovieClip;

function showNext(e:TimerEvent):void{
	frontPhoto = MovieClip(gallery.getChildAt(gallery.numChildren-1));
	TweenLite.to(frontPhoto, .8,{x:600,y:-200,rotation:45,ease:Quart.easeIn,onComplete:moveBack});
}
</pre>
<p><em>6.</em> The moveBack function is used to put the photo at the back of the stack. To do so, we change its depth to 0 and use Tweenlite to set its x and y properties to random values (near 0) and the rotation property to 0. </p>
<pre class="brush: jscript;">
function moveBack():void{
	gallery.setChildIndex(frontPhoto,0)
	TweenLite.to(frontPhoto, 1,{x:Math.random()*80 -40 , y:Math.random()*40 -20 ,rotation:0});
}
</pre>
<p><em>7.</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 timer:Timer = new Timer(4000);
timer.addEventListener(TimerEvent.TIMER,showNext);
timer.start();

var frontPhoto:MovieClip;

function showNext(e:TimerEvent):void{
	frontPhoto = MovieClip(gallery.getChildAt(gallery.numChildren-1));
	TweenLite.to(frontPhoto, .8,{x:600,y:-200,rotation:45,ease:Quart.easeIn,onComplete:moveBack});
}

function moveBack():void{
	gallery.setChildIndex(frontPhoto,0)
	TweenLite.to(frontPhoto, 1,{x:Math.random()*80 -40 , y:Math.random()*40 -20 ,rotation:0});
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/create-a-flash-photo-stack-gallery/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Using SharedObject to Mute/Unmute Sound according to the User&#8217;s Choice</title>
		<link>http://www.riacodes.com/flash/using-sharedobject-to-muteunmute-sound-according-to-the-users-choice/</link>
		<comments>http://www.riacodes.com/flash/using-sharedobject-to-muteunmute-sound-according-to-the-users-choice/#comments</comments>
		<pubDate>Sun, 02 May 2010 10:46:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1299</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_sharedobject-sound/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this tutorial, we&#8217;ll demonstrate the usage of SharedObject a.k.a Flash Cookies. We&#8217;ll use it to remember whether the user has turned ON or OFF the sound and when he returns to the page the sound will be played or not.</p>
<p><span id="more-1299"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_sharedobject-sound/" 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_sharedobject-sound/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 (AS3) and save it as sharedobject.fla.</p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;Button&#8221;. On this layer create the mute/unmute button which is a movie clip with 2 keyframes, the first for the mute and the 2nd for the unmute. Add stop() action on each frame.</p>
<p><em>3.</em> Back to Scene 1, create an &#8220;actions&#8221; layer. With the first frame selected open the actions panel.</p>
<p>(For more details about SharedObject check the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/SharedObject.html" target="_blank">documentation</a>)</p>
<p>First we call the getLocal() method to create an instance of a SharedObject and retrieve a reference of the shared object which name is &#8220;riacodes_sound&#8221;. Next we retrieve the ismute info from the SharedObject  by accessing the info through the data property.</p>
<pre class="brush: jscript;">
var mySO:SharedObject = SharedObject.getLocal(&quot;riacodes_sound&quot;);
var isMute : Boolean = mySO.data.ismute != null ? mySO.data.ismute : false;
</pre>
<p><em>4.</em> Next we add the script to load the sound and play it and create the toggleMute function.</p>
<pre class="brush: jscript;">
var song:Sound = new Sound();
var channel:SoundChannel = new SoundChannel();
var songPosition : Number = 0;

mute_mc.addEventListener(MouseEvent.CLICK,toggleMute;
mute_mc.buttonMode = true;

song.load(new URLRequest(&quot;sound.mp3&quot;));
if(!isMute)
	channel = song.play();
else
	mute_mc.gotoAndStop(2);

function toggleMute(e:MouseEvent):void{
	if(!isMute){
		songPosition = channel.position;
	        channel.stop();
		isMute = true;
		mute_mc.gotoAndStop(2);
	}
	else {
		channel = song.play(songPosition);
		isMute = false;
		mute_mc.gotoAndStop(1);
	}

}
</pre>
<p><em>5.</em> Last thing that we need to do, is to store the ismute info data each time the user mute or unmute the sound. To do so, at the end of the toggleMute function, we add ismute data to the SharedObject by setting its value to the isMute Boolean variable and call the flush() method to write the data inside the end user&#8217;s machine.</p>
<pre class="brush: jscript; highlight: [14,15];">
function toggleMute(e:MouseEvent):void{
	if(!isMute){
		songPosition = channel.position;
	       channel.stop();
		isMute = true;
		mute_mc.gotoAndStop(2);
	}
	else {
		channel = song.play(songPosition);
		isMute = false;
		mute_mc.gotoAndStop(1);
	}

	mySO.data.ismute = isMute;
	mySO.flush ();
}
</pre>
<p><em>6.</em> Here&#8217;s the final code, test your movie and try playing with the mute button and refresh your page to see the code in action.</p>
<pre class="brush: jscript;">
var mySO:SharedObject = SharedObject.getLocal(&quot;riacodes_sound&quot;);
var isMute : Boolean = mySO.data.ismute != null ? mySO.data.ismute : false;

var song:Sound = new Sound();
var channel:SoundChannel = new SoundChannel();
var songPosition : Number = 0;

mute_mc.addEventListener(MouseEvent.CLICK,toggleMute);
mute_mc.buttonMode = true;

song.load(new URLRequest(&quot;sound.mp3&quot;));
if(!isMute)
	channel = song.play();
else
	mute_mc.gotoAndStop(2);

function toggleMute(e:MouseEvent):void{
	if(!isMute){
		songPosition = channel.position;
	    channel.stop();
		isMute = true;
		mute_mc.gotoAndStop(2);
	}
	else {
		channel = song.play(songPosition);
		isMute = false;
		mute_mc.gotoAndStop(1);
	}

	mySO.data.ismute = isMute;
	mySO.flush ();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/using-sharedobject-to-muteunmute-sound-according-to-the-users-choice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create a Zoomable Photos Panel with Flash</title>
		<link>http://www.riacodes.com/flash/create-a-zoomable-photos-panel-with-flash/</link>
		<comments>http://www.riacodes.com/flash/create-a-zoomable-photos-panel-with-flash/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 12:44:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://www.riacodes.com/?p=1262</guid>
		<description><![CDATA[<img src="http://www.files.riacodes.com/flash_zoom-photos-panel/preview.jpg"/>]]></description>
			<content:encoded><![CDATA[<p>In this new AS3 tutorial, let&#8217;s see how to create a zoomable photos panel with a nice hover effect.<br />
<span id="more-1262"></span></p>
<div class="demosource"><a href="http://www.files.riacodes.com/flash_zoom-photos-panel/" 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_zoom-photos-panel/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 zoompanel.fla.</p>
<p><em>2.</em> Rename &#8220;layer 1&#8243; to &#8220;content&#8221;. Place 4 images on the stage and align them. Convert each one to a movie clip with registration point at the center. Next scale down each movie clip to 0.4 of its actual size so that when  we zoom in a photo it will completely covers the others on the back. As each of our image is 300px height, we set it to 120px and its width proportionnally.</p>
<p><em>3.</em> Select the 4 movie clips and convert the selection to a movie clip with registration point at the center. Give it an instance name of &#8220;content_mc&#8221;.</p>
<p><em>4.</em> Create an &#8220;actions&#8221; layer. We&#8217;ll use the Tweenlite engine, so first go <a href="http://www.greensock.com/tweenlite/" target="_blank">download its AS3 version.</a></p>
<p>Open the actions panel.<br />
First make the following imports that we need to use the Twenlite engine and to create the hover glow effect.</p>
<pre class="brush: jscript;">
import com.greensock.*;
import flash.filters.*;
</pre>
<p><em>5.</em> Create an init() function that loop through all the children of &#8220;content_mc&#8221; to add mouse event listeners and store their initial x and y coordinates.</p>
<pre class="brush: jscript;">
function init():void{
	for(var i:int=0; i&lt; content_mc.numChildren; i++){
		var mc:MovieClip = content_mc.getChildAt(i) as MovieClip;
		mc.buttonMode = true;
		mc.posX = mc.x;
		mc.posY = mc.y;
		mc.addEventListener(MouseEvent.ROLL_OVER, onOver);
		mc.addEventListener(MouseEvent.ROLL_OUT, onOut);
		mc.addEventListener(MouseEvent.CLICK, onClick);
	}
}
</pre>
<p><em>6.</em> For the onOver function we simply add a glow filter and for the onOut function we remove it.</p>
<pre class="brush: jscript;">
var glow:GlowFilter=new GlowFilter(0xffffff, 1, 2, 2, 3, 255, false, false);

function onOver (evt:MouseEvent) {
	evt.target.filters=[glow];
}

function onOut (evt:MouseEvent) {
	evt.target.filters=[];
}
</pre>
<p><em>7.</em> For the onClick function we use the Tweenlite engine to scale up and down the photo clicked.<br />
Outside the function declare a zoom variable that will store the current movie clip that is in front.</p>
<pre class="brush: jscript;">
var zoom : MovieClip;
function onClick (evt:MouseEvent) {

}
</pre>
<p><em>8.</em> When the onClick function is called, we need to know whether it is to zoom in a photo or to zoom out the one which is in front.<br />
To do so, we check whether the zoom variable is equal to the movie clip that has triggered the click event :<br />
- If NO, which means no photo is in front, we set the zoom variable to the movie clip and set the movie clip index to the highest one so that when we zoom it, the photo will be in front of the other three.<br />
Then we use the Tweenlite engine to scale it up and set its x and y coordinates to 0 so that it centers inside the container.<br />
- If YES, which means one photo is in front of the others, we scale it down and set its x and y properties to their original values, and we set the zoom variable to null.</p>
<pre class="brush: jscript;">
var zoom : MovieClip;
function onClick (evt:MouseEvent) {
	var mc = evt.target as MovieClip;

	if(zoom != mc){
		zoom = mc;
		content_mc.setChildIndex(mc, content_mc.numChildren -1);
		TweenLite.to(mc, 0.5,{scaleX:1,scaleY:1,x:0,y:0});
	}
	else {
		TweenLite.to(mc, 0.5,{scaleX:0.4,scaleY:0.4,x:zoom.posX,y:zoom.posY});
		zoom = null;
	}
}
</pre>
<p><em>9.</em> Finally don&#8217;t forget to call the init() function.<br />
Here&#8217;s the final code, test your movie to see it in action.</p>
<pre class="brush: jscript;">
import com.greensock.*;
import flash.filters.*;

var glow:GlowFilter=new GlowFilter(0xffffff, 1, 2, 2, 3, 255, false, false);

function init():void{
	for(var i:int=0; i&lt; content_mc.numChildren; i++){
		var mc:MovieClip = content_mc.getChildAt(i) as MovieClip;
		mc.buttonMode = true;
		mc.posX = mc.x;
		mc.posY = mc.y;
		mc.addEventListener(MouseEvent.ROLL_OVER, onOver);
		mc.addEventListener(MouseEvent.ROLL_OUT, onOut);
		mc.addEventListener(MouseEvent.CLICK, onClick);
	}
}

function onOver (evt:MouseEvent) {
	evt.target.filters=[glow];
}

function onOut (evt:MouseEvent) {
	evt.target.filters=[];
}

var zoom : MovieClip;
function onClick (evt:MouseEvent) {
	var mc = evt.target as MovieClip;

	if(zoom != mc){
		zoom = mc;
		content_mc.setChildIndex(mc, content_mc.numChildren -1);
		TweenLite.to(mc, 0.5,{scaleX:1,scaleY:1,x:0,y:0});
	}
	else {
		TweenLite.to(mc, 0.5,{scaleX:0.4,scaleY:0.4,x:zoom.posX,y:zoom.posY});
		zoom = null;
	}
}

init();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.riacodes.com/flash/create-a-zoomable-photos-panel-with-flash/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
