<?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>Flash, Flex and ActionScript tutorials - flashadvanced &#187; Advanced ActionScript 3</title>
	<atom:link href="http://flashadvanced.com/category/advanced-actionscript-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://flashadvanced.com</link>
	<description>Become an advanced actionscript developer</description>
	<lastBuildDate>Sun, 30 Jan 2011 21:10:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AS3 Currency Converter</title>
		<link>http://flashadvanced.com/as3-currency-converter/</link>
		<comments>http://flashadvanced.com/as3-currency-converter/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 14:16:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[components]]></category>
		<category><![CDATA[currency converter]]></category>
		<category><![CDATA[DataProvider]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[list component]]></category>
		<category><![CDATA[TextInput]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=410</guid>
		<description><![CDATA[In this tutorial I will show you how to create a Currency Converter using ActionScript 3 and Flash Components. The calculations are made in runtime, no button clicks needed! 1. Open a new Flash document and save it under &#8220;CurrencyConverter.fla&#8221;. Set the document size to 400 x 250 pixels and for color choose #CCCCCC. 2. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=410"><br />
<img src="http://flashadvanced.com/wp-content/upload/converter/converter.jpg" /><br />
</a></p>
<p>In this tutorial I will show you how to create a Currency Converter using ActionScript 3 and Flash Components. The calculations are made in runtime, <strong>no button clicks needed</strong>!</p>
<p><span id="more-410"></span></p>
<p><span style="color: #ff0000;">1.</span> Open a new Flash document and save it under &#8220;CurrencyConverter.fla&#8221;. Set the document size to 400 x 250 pixels and for color choose #CCCCCC.</p>
<p><span style="color: #ff0000;">2.</span> Open the Components Panel by clicking Window -> Copmponents and drag two <strong>List Components</strong>. Make them 145px wide by 100px high. Give the first List component instance name &#8220;fromList&#8221; and the second &#8220;toList&#8221;.</p>
<p><span style="color: #ff0000;">3.</span> Go to the Components Panel again and drag a <strong>TextInput</strong> component. For instance name type &#8220;input_txt&#8221;. Position the TextInput somewhere over the first List component.</p>
<p><span style="color: #ff0000;">4.</span> Take the <strong>Text Tool</strong> and create a dynamic text field somewhere over the second List component. Give the text field instance name &#8220;result_txt&#8221;. Set its properties like this:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/converter/text.jpg" /></p>
<p>I think you got the idea. The user types the amount in the TextInput and selects the currency that he would like to convert from. The result appears in the &#8220;result_txt&#8221; text field.</p>
<p><img src="http://flashadvanced.com/wp-content/upload/converter/structure.jpg" /></p>
<p><span style="color: #ff0000;">5.</span> We are now ready and have to go to ActionScript. Create a new layer called &#8220;actions&#8221; and open the Actions Panel.</p>
<pre><code>
//importing DataProvider class
import fl.data.DataProvider;

//creating a new data provider object
var dp:DataProvider = new DataProvider();
//first we create a variable to store the first value
var fromVal:Number;
//then we create a variable for the second value
var toVal:Number;
//here we store what the user inputs
var inputVal:Number
//the result value
var calculatedVal:Number;
//the user can enter only numbers in the TextInput
input_txt.restrict = "0-9";

//adding items to the Data Provider. The user sees the "label" property.
//For data we set the currency weight. US dollar has weight 1.
//The others are in proportion to US Dollar
dp.addItem( { label: "U.S. Dollars", data:1 });
dp.addItem( { label: "Australian Dollars", data: 0.832114 });
dp.addItem( { label: "Canada Dollars", data: 0.926215 } );
dp.addItem( { label: "Euro", data:1.42643 });
dp.addItem( { label: "United Kingdom Pounds", data:1.65151 });
dp.addItem( { label: "India Rupees", data:0.0207573 });
dp.addItem( { label: "Poland Zlotych", data:0.341955 });
dp.addItem( { label: "Russia Rubles", data:0.0325614 });
dp.addItem( { label: "Philippines Pesos", data:0.02079 });
dp.addItem( { label: "Bulgarian Leva", data:0.729733 });
dp.addItem( { label: "Brazil Reais", data:0.531719 });

//populating the lists
fromList.dataProvider = dp;
toList.dataProvider = dp;

//adding Event Change listeners to all of the components
fromList.addEventListener(Event.CHANGE, calculateResult);
toList.addEventListener(Event.CHANGE, calculateResult);
input_txt.addEventListener(Event.CHANGE, calculateResult);
//we set items that are set by default
fromList.selectedIndex = 0;
toList.selectedIndex = 3;

//initializing "fromVal" and "toVal"
fromVal = fromList.selectedItem.data;
toVal = toList.selectedItem.data;

function calculateResult(e:Event):void{
	fromVal = fromList.selectedItem.data;
	toVal = toList.selectedItem.data;
	//casting String to Number
	inputVal = Number(input_txt.text);
	//calculating the result
	calculatedVal = inputVal * (fromVal / toVal);
	//adding the result to the text field
	result_txt.text = calculatedVal.toString();
}
</pre>
<p></code></p>
<h4>Here is the final result:</h4>
<p><object width="400" height="250"><param name="movie" value="http://flashadvanced.com/wp-content/upload/converter/CurrencyConverter.swf"><embed src="http://flashadvanced.com/wp-content/upload/converter/CurrencyConverter.swf" width="400" height="250"></embed></object></p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/converter/converter.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/as3-currency-converter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Preloader following mouse</title>
		<link>http://flashadvanced.com/preloader-following-mouse/</link>
		<comments>http://flashadvanced.com/preloader-following-mouse/#comments</comments>
		<pubDate>Mon, 27 Jul 2009 19:26:54 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[easing]]></category>
		<category><![CDATA[mouse follower]]></category>
		<category><![CDATA[preloader]]></category>
		<category><![CDATA[Tooltip]]></category>
		<category><![CDATA[tween]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=385</guid>
		<description><![CDATA[In this tutorial I will show you how to create a nice tooltip preloader with easing using Flash and ActionScript 3. We&#8217;ll be loading an external SWF file. Note: In order to complete this tutorial you need to download TweenMax library. Do it by clicking here. Unzip the downloaded file in the same directory as [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=385"><br />
<img src="http://flashadvanced.com/wp-content/upload/preloader/preloader.jpg" alt="" /><br />
</a></p>
<p>In this tutorial I will show you how to create a nice <strong>tooltip preloader with easing</strong> using Flash and ActionScript 3. We&#8217;ll be loading an external SWF file.</p>
<p><span id="more-385"></span></p>
<h4>Note: In order to complete this tutorial you need to download TweenMax library. Do it by clicking <a href="http://blog.greensock.com/tweenmaxas3/">here</a>. Unzip the downloaded file in the same directory as the Flash files!</h4>
<p><span style="color: #ff0000;">1.</span> Open a new Flash document and save it under &#8220;preloader.fla&#8221;.</p>
<p><span style="color: #ff0000;">2.</span> Now we have to create our tooltip. If you don&#8217;t know how to draw a tooltip, see the &#8220;Tooltip&#8221; tutorial by clicking <a href="http://flashadvanced.com/?p=1" target="_blank">here</a>.<br />
If you are ready with the tooltip, select it and convert it to movie clip with instance name &#8220;tooltip_mc&#8221;. Set its registration point to <strong>bottom center</strong>:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/preloader/regpoint.jpg" alt="" /></p>
<p>Now, go inside &#8220;tooltip_mc&#8221; and create a dynamic text field on the top of the tooltip. For font select &#8220;Arial Black&#8221;, choose 9 for size and #FFFFFF for color. Type &#8220;percent_txt&#8221; for instance name. Don&#8217;t forget to embed the font:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/preloader/embed.jpg" alt="" /></p>
<p><span style="color: #ff0000;">3.</span> We are ready with the tooltip. Before we move to ActionScript we need to create another movie that we&#8217;ll be loading. <strong>Open a new flash document</strong> and import a photo that is larger than 100 Kb or you can drag several components to the stage. The idea is to make the compiled SWF file larger. Save this file under &#8220;content.fla&#8221; in the same directory as &#8220;preloader.fla&#8221; and compile it. We are going to <strong>load</strong> &#8220;content.swf&#8221;.</p>
<p><span style="color: #ff0000;">4.</span> Go back to &#8220;preloader.fla&#8221;, create a new layer called &#8220;actions&#8221; and open the actions panel:</p>
<pre><code>
//we hide the cursor
Mouse.hide();

//importing TweenMax classes
import gs.*;

//by default our tooltip should follow the mouse
TweenMax.to(tooltip_mc, 0.5 ,{x :mouseX, y: mouseY});

 //adding mouse move event handler
stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);

function mouseMoveHandler(e:Event):void {
	//the tooltip follows the mouse when it is moved
	TweenMax.to(tooltip_mc, 0.5, {x :mouseX, y: mouseY});
}

//creating a loader
var loader:Loader = new Loader();
//adding progress event handler to our loader
loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,
                                                     loadContent);
//calling "contentLoaded" function if loading is over
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, contentLoaded);
//loading the content
loader.load(new URLRequest("content.swf"));

function loadContent(e:ProgressEvent):void{
	//calculating the percentage loaded
	var pcent:Number = (e.bytesLoaded / e.bytesTotal) * 100;
	//adding the percentage to the text field
	tooltip_mc.percent_txt.text = int(pcent)+"%";
}

function contentLoaded(e:Event):void{
	//when the movie is loaded we remove the preloader
	removeChild(tooltip_mc);
	//then we add the loader
	addChild(loader);
	//and finally we show the cursor again
	Mouse.show();
}
</code></pre>
<h4>Here is the final result. Move your mouse over the movie:</h4>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="500" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://flashadvanced.com/wp-content/upload/preloader/sitever.swf" /><embed type="application/x-shockwave-flash" width="500" height="350" src="http://flashadvanced.com/wp-content/upload/preloader/sitever.swf"></embed></object></p>
<h4>You can test your preloader by compiling the movie and then going to View -&gt; Simulate Download</h4>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/preloader/preloader.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" alt="" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/preloader-following-mouse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a small shooting game in AS3</title>
		<link>http://flashadvanced.com/creating-small-shooting-game-as3/</link>
		<comments>http://flashadvanced.com/creating-small-shooting-game-as3/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 13:04:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[game]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=371</guid>
		<description><![CDATA[In this tutorial you will learn how to create a small &#8220;shooting stars&#8221; game using Flash and ActionScript 3. Let&#8217;s get started! 1. Open a new Flash document and save it under &#8220;ShootingGame.fla&#8221;. Set its size to 500 x 300 pixels. 2. First of all we need to draw the sight of our weapon. So [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=371"><br />
<img src="http://flashadvanced.com/wp-content/upload/shooting/shooting.jpg" /><br />
</a></p>
<p>In this tutorial you will learn how to create a small <strong>&#8220;shooting stars&#8221;</strong> game using Flash and ActionScript 3. Let&#8217;s get started!</p>
<p><span id="more-371"></span></p>
<p><span style="color: #ff0000;">1.</span> Open a new Flash document and save it under &#8220;ShootingGame.fla&#8221;. Set its size to 500 x 300 pixels.</p>
<p><span style="color: #ff0000;">2.</span> First of all we need to draw the sight of our weapon. So rename the first layer to &#8220;sight&#8221;. Take the <strong>Oval Tool</strong> and from the properties panel set its properties to Solid, Disabled Fill, Stroke height should be set to 3.<br />
Then take the Selection tool, select a part of the circle and cut it like this:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/shooting/steps.jpg" /></p>
<p>The final step is to take the Line tool and to draw a cross. Just change the Stroke height value to 1.5. Select the whole sight and convert it to Movie Clip with instance name &#8220;sight&#8221; and <strong>registration point center</strong>.</p>
<p><span style="color: #ff0000;">3.</span> Now our sight is ready and we need to draw a star. Take the <strong>PolyStar Tool</strong> and set it properties like this:</p>
<p><img src="http://flashadvanced.com/wp-content/upload/shooting/properties.jpg" /></p>
<p>If your star is ready, select it and convert it to Movie Clip with <strong>registration point center</strong>. <strong>Linkage</strong> the star to class Star by going to the Library panel (Ctrl + L), right-clicking the Star movie clip and then setting the class name. Remove the star from the stage.</p>
<p><img src="http://flashadvanced.com/wp-content/upload/shooting/linkage.jpg" /></p>
<p><span style="color: #ff0000;">4.</span> Take the text tool and first create a Static text field and type &#8220;Score:&#8221;. Then create a <strong>dynamic</strong> text field with instance name &#8220;points_txt&#8221; and position it next to the static text field. Embed the Numeral values for the font and for color choose #FF0000. Align the text fields to the bottom right part of the stage.</p>
<p><span style="color: #ff0000;">5.</span> Create a new layer called &#8220;actions&#8221;, open Actions Panel and type this:</p>
<pre><code>
//importing tween classes
import fl.transitions.easing.*;
import fl.transitions.Tween;

//hiding the cursor
Mouse.hide();

//creating a new Star instance
var star:Star = new Star();
//creating the timer
var timer:Timer = new Timer(1000);
//we create variables for random X and Y positions
var randomX:Number;
var randomY:Number;
//variable for the alpha tween effect
var tween:Tween;
//we check if a star instance is already added to the stage
var starAdded:Boolean = false;
//we count the points
var points:int = 0;

//adding event handler on mouse move
stage.addEventListener(MouseEvent.MOUSE_MOVE, cursorMoveHandler);
//adding event handler to the timer
timer.addEventListener(TimerEvent.TIMER, timerHandler);
//starting the timer
timer.start();

function cursorMoveHandler(e:Event):void{
	//sight position matches the mouse position
	sight.x = mouseX;
	sight.y = mouseY;
}

function timerHandler(e:TimerEvent):void{
	//first we need to remove the star from the stage if already added
	if(starAdded){
		removeChild(star);
	}

	//positioning the star on a random position
	randomX = Math.random()*500;
	randomY = Math.random()*300;
	star.x = randomX;
	star.y = randomY;
	//adding the star to the stage
	addChild(star);
	//changing our boolean value to true
	starAdded = true;
	//adding a mouse click handler to the star
	star.addEventListener(MouseEvent.CLICK, clickHandler);
	//animating the star's appearance
	tween = new Tween(star, "alpha", Strong.easeOut, 0, 1, 3, true);
}

function clickHandler(e:Event):void{
	//when we click/shoot a star we increment the points
	points ++;
	//showing the result in the text field
	points_txt.text = points.toString();
}
</code></pre>
<h4>Here is the final result:</h4>
<p><object width="500" height="300"><param name="movie" value="http://flashadvanced.com/wp-content/upload/shooting/ShootingGame.swf"><embed src="http://flashadvanced.com/wp-content/upload/shooting/ShootingGame.swf" width="500" height="300"></embed></object></p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/shooting/shooting.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/creating-small-shooting-game-as3/feed/</wfw:commentRss>
		<slash:comments>80</slash:comments>
		</item>
		<item>
		<title>XML random quotes rotator</title>
		<link>http://flashadvanced.com/xml-random-quotes-rotator/</link>
		<comments>http://flashadvanced.com/xml-random-quotes-rotator/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 10:37:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[random]]></category>
		<category><![CDATA[timer]]></category>
		<category><![CDATA[tween]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=169</guid>
		<description><![CDATA[Today I will show you how to use XML and ActionScript 3 to create a small application that changes your favourite quotes after some time interval. We will be using also the AS3 Tween Class to animate the quotes&#8217; appearance. At first this was just an experiment but i thought it might be useful for [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=169"><br />
<img src="http://www.flashadvanced.com/wp-content/upload/quotes/quotes.jpg" alt="" /><br />
</a></p>
<p>Today I will show you how to use <strong>XML</strong> and ActionScript 3 to create a small application that changes your favourite quotes after some time interval. We will be using also the AS3 <strong>Tween Class</strong> to animate the quotes&#8217; appearance.</p>
<p><span id="more-169"></span></p>
<p>At first this was just an experiment but i thought it might be useful for some of you. What the rotator does is to choose a <strong>random</strong> quote from an XML file and then shows it for several seconds. Then it chooses another random quote and so on. You can use it for header of your blog or whatever you want. So, let&#8217;s get started.</p>
<p><span style="color: #ff0000;"><strong>1.</strong></span> Create a new Flash CS3 document with size 600 x 100 and background color #000000.<br />
<span style="color: #ff0000;"><strong>2.</strong></span> Create two dynamic text fields. The first one should be about 580px wide and the second one &#8211; about 200px. For the long text field choose #ffffff for color, size 14, bold. I have used &#8220;Verdana&#8221; for font. If you don&#8217;t like it choose another font. Align the text inside the text field to center. Give it an instance name &#8220;quoteTxt&#8221;. Embed the font like this:</p>
<p><img src="http://www.flashadvanced.com/wp-content/upload/quotes/embed.jpg" alt="" /></p>
<p>Now repeat this step for the other text field but only change the color to #00CCFF and give it an instance name &#8220;authorTxt&#8221;.<br />
<span style="color: #ff0000;"><strong>3.</strong></span> Convert the text fields to movie clips. Select the long text field and convert it to movie clip with instance name &#8220;quoteMC&#8221;. Repeat the same for the other text field and put &#8220;authorMC&#8221; for instance name.<br />
<span style="color: #ff0000;"><strong>4.</strong></span> Now let&#8217;s create the <strong>XML</strong> file we will be using. You can simply download it from <a href="http://www.flashadvanced.com/wp-content/upload/quotes/quotes.xml">here</a>. So after downloading put the file into directory named &#8220;data&#8221;.<br />
<span style="color: #ff0000;"><strong>5.</strong></span> Create a new layer called &#8220;actions&#8221;, open the actions panel and paste this code:</p>
<pre><code>
//importing tween classes
import fl.transitions.Tween;
import fl.transitions.easing.*;

//we create a variable to store the loaded XML
var xml:XML;
//the path to the xml file
var xmlPath:String = "http://www.flashadvanced.com/wp-content/upload/quotes/quotes.xml";
//we create a loader and when the loading is over we call the xmlComplete function
var loader:URLLoader = new URLLoader();
//a url request for our loader
var req:URLRequest = new URLRequest(xmlPath);
loader.addEventListener(Event.COMPLETE, xmlComplete);
loader.load(req);
//a variable for our tween
var myTween:Tween;
//we need to set a timer
var timer:Timer = new Timer(5000);
timer.addEventListener(TimerEvent.TIMER, changeQuotes);
timer.start();

function xmlComplete(e:Event):void{
	xml = new XML(e.target.data);
	addQuotes();
	randomQuoteTween();
}

//we create arrays to store the quotes and the authors
var quotesArray:Array = new Array();
var authorsArray:Array = new Array();
//we need a random quote number
var randomNumber:Number;

function addQuotes(){
	//we loop through the "quote" element of our XML
	for each(var item:XML in xml.quotes.quote){
		//we fill the arrays with quotes and authors
		quotesArray.push(item.content);
		authorsArray.push(item.author);
	}
}

function randomQuoteTween():void{
	//calculating the random number
	randomNumber = Math.round(Math.random() * (quotesArray.length - 1));
	//filling the text fields
	quoteMC.quoteTxt.text = quotesArray[randomNumber];
	authorMC.authorTxt.text = authorsArray[randomNumber];
	//creating tween effects
	myTween = new Tween(quoteMC, "alpha", Strong.easeOut, 0, 1, 3, true);
	myTween = new Tween(authorMC, "x", Strong.easeOut, 550, 500, 3, true);
}

function changeQuotes(e:TimerEvent){
	randomQuoteTween();
}
</code></pre>
<h4>Here is the final result:</h4>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="100" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://www.flashadvanced.com/wp-content/upload/quotes/Quotes.swf" /><embed type="application/x-shockwave-flash" width="600" height="100" src="http://www.flashadvanced.com/wp-content/upload/quotes/Quotes.swf"></embed></object></p>
<p style="text-align: left; margin: 40px 40px 40px 0;"><a href="http://www.flashadvanced.com/wp-content/upload/quotes/quotes.zip"><img src="http://flashadvanced.com/wp-content/upload/other/download.jpg" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/xml-random-quotes-rotator/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>ActionScript 3 optimization tips</title>
		<link>http://flashadvanced.com/actionscript-3-optimization-tips/</link>
		<comments>http://flashadvanced.com/actionscript-3-optimization-tips/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 12:39:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Advanced ActionScript 3]]></category>
		<category><![CDATA[actionscript 3]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://flashadvanced.com/?p=69</guid>
		<description><![CDATA[This article will show you a collection of optimization tips for ActionScrip 3 that you can use to speed up your application&#8217;s performance. Let&#8217;s begin with the first rule in AS 3 optimization tehniques: 1. Use integers for iterations. Int type performs faster than Number when looping through the items of an array. This is [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://flashadvanced.com/?p=69"><br />
<img src="http://www.flashadvanced.com/wp-content/upload/optimization/optimization.jpg" alt="" /><br />
</a></p>
<p>This article will show you a collection of optimization tips for ActionScrip 3 that you can use to speed up your application&#8217;s <strong>performance</strong>.</p>
<p>Let&#8217;s begin with the first rule in AS 3 optimization tehniques:</p>
<p><span id="more-69"></span></p>
<p><span style="color: #ff0000;">1.</span> Use integers for <strong>iterations</strong>. Int type performs faster than Number when looping through the items of an array. This is because array indexing is faster with ints.</p>
<pre><code>for(var i:int = 0; i < 1000000; i++);</code></pre>
<p><span style="color: #ff0000;">2.</span> Use shorthand operators whenever possible</p>
<p>Incrementing is faster using the "++" operator than using "i = i + 1". It is the same situation with "a += b" which is faster than "a = a + b";</p>
<p><span style="color: #ff0000;">3.</span> Use <strong>multiplication</strong> instead of division when dividing by 2.</p>
<p>In this case it is better to use multiplication with .5 than division by 2.</p>
<p>Slow:</p>
<pre><code>var a:Number = b / 2;</code></pre>
<p>Fast:</p>
<pre><code>var a:Number = b*.5;</code></pre>
<p><span style="color: #ff0000;">4.</span> Use bitwise shift operators for even faster performance.</p>
<p>Slow:</p>
<pre><code>
var a:int = 10;
a = a * 2; //returns 20
a = a * 4; //returns 40
a = a / 2; //returns 5;</code></pre>
<p>Fast:</p>
<pre><code>
var a:int = 10;
a = a << 1; //returns 20
a = a << 2; //returns 40
a = a >> 1; //returns 5</code></pre>
<p><span style="color: #ff0000;">5.</span> Use single line variable declaration</p>
<p>Slow:</p>
<pre><code>
var a:int = 1;
var b:int = 2;
var c:int = 3;</code></pre>
<p>Fast:</p>
<p>First use the "var" keyword and then declare the variables on a single line.</p>
<pre><code>var a:int = 1, b:int = 2, c:int = 3;</code></pre>
<p><span style="color: #ff0000;">6.</span> Use "null" intead of "try .. catch" if possible:</p>
<pre><code>var myArray:Array;
if(myArray != null)
	myArray.pop();
else
	trace("its null");
</code></pre>
<p>is way <strong>faster</strong> than:</p>
<pre><code>try{
	myArray.pop();
}catch(e:Error){
	trace(e.message);
}</code></pre>
<p><span style="color: #ff0000;">7.</span>Use <strong>int(a)</strong> instead of <strong>Math.floor(a)</strong>. Math.floor(a) is 10 times slower than int(a).<br />
Slow:</p>
<pre><code>
for(var i:int=0; i<1000000; i++){
	var a:int = Math.floor(1.5);
}
</code></pre>
<p>Fast:</p>
<pre><code>
for(var i:int=0; i<1000000; i++){
	var a:int = int(1.5);
}
</code></pre>
<h4>This is how you can test your code performance:</h4>
<pre><code>
for(var i:int=0; i<1000000; i++){
	var a:int = 4 << 1;
	var b:int = 4 << 2;
	var c:int = 4 >> 1;
}
trace(getTimer());
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://flashadvanced.com/actionscript-3-optimization-tips/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

