<?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>FlashBannerOnline &#187; ActionScript</title>
	<atom:link href="http://blog.flashbanneronline.com/category/tutorials/flash-tutorials/actionscript-flash-tutorials-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.flashbanneronline.com</link>
	<description>Online Flash Banner Generator blog!</description>
	<lastBuildDate>Sun, 26 Jun 2011 11:38:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Extract Swf file from Mochimedia Encrypted file &#8211; MochiDecrypter</title>
		<link>http://blog.flashbanneronline.com/2011/06/extract-swf-file-from-mochimedia-encrypted-file-mochidecrypter/</link>
		<comments>http://blog.flashbanneronline.com/2011/06/extract-swf-file-from-mochimedia-encrypted-file-mochidecrypter/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 11:34:46 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Free Downloads]]></category>
		<category><![CDATA[Air]]></category>
		<category><![CDATA[blog.flashbanneronline.com]]></category>
		<category><![CDATA[Decompile]]></category>
		<category><![CDATA[Encrypted]]></category>
		<category><![CDATA[environment]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[interface]]></category>
		<category><![CDATA[MochiDecrypt]]></category>
		<category><![CDATA[mochidecrypter]]></category>
		<category><![CDATA[Mochimedia]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=569</guid>
		<description><![CDATA[Maybe your website mochimedia and services that meet you and maybe many games by this code, have seen you play, the method mochimedia emissions are primarily a perloader that, along with a symbol lock is&#8230; Perhaps we were already being protected. The software is now like a utility for Decompile files are locked with the [...]]]></description>
			<content:encoded><![CDATA[<p>Maybe  your website mochimedia and services that meet you and maybe many games by  this code, have seen you play, the method mochimedia emissions are primarily a  perloader that, along with a symbol lock is&#8230;<br />
Perhaps we were already being protected.</p>
<p>The software is now like a utility for Decompile files are locked with the above method.<br />
Swf file to your home and provides that any application can Decompile  getting there!</p>
<p>Is a simple GUI interface , Just your files Drag and Drop in your program.<br />
Program to break the lock file and extract the original file, and give you.<br />
The extracted files are saved in the original file.<br />
Meanwhile, right-click and select Browse File, you can also select your desired file.</p>
<p><a href="http://blog.flashbanneronline.com/wp-content/uploads/2011/06/mochi_lock_iflashlord.jpg"><img class="size-full wp-image-575 alignnone" title="mochi_lock_iflashlord" src="http://blog.flashbanneronline.com/wp-content/uploads/2011/06/mochi_lock_iflashlord.jpg" alt="" width="465" height="273" /></a></p>
<blockquote><p>If you find a way to break the locks have security in Flash! you can expand your personal experience to share.</p></blockquote>
<p><strong>Programming environment:</strong></p>
<p><a href="http://blog.flashbanneronline.com/wp-content/uploads/2011/06/mochidecrypt_1.jpg"><img class="alignnone size-full wp-image-576" title="mochidecrypt_1" src="http://blog.flashbanneronline.com/wp-content/uploads/2011/06/mochidecrypt_1.jpg" alt="" width="468" height="310" /></a></p>
<p><a href="http://blog.flashbanneronline.com/wp-content/uploads/2011/06/mochidecrypt_2.jpg"><img class="alignnone size-full wp-image-577" title="mochidecrypt_2" src="http://blog.flashbanneronline.com/wp-content/uploads/2011/06/mochidecrypt_2.jpg" alt="" width="468" height="310" /></a></p>
<p>User Mode program is considered so Both in English and Persian Languages to give enough information to work with.</p>
<p><strong>Program Information:</strong></p>
<p>Version : 1.0.0<br />
Adobe Air Installer : <strong>Adobe Air 2.5 or higher</strong><br />
size: <strong>275 kb</strong><br />
Release date :  <strong>24 June 2011</strong><br />
Powered by :  <strong>Flash CS5.5 , ActionScript 3.o , Adobe Air</strong><br />
Designer and Programmer : <strong>Behrouz Pooladrag</strong></p>
<p><strong>Download:</strong></p>
<p><a title="دانلود آخرین نسخه MochiDecrypt با فرمت AIR" href="http://iflashlord.com/software/MochiDecrypt/MochiDecrypt_v1.air" target="_blank">Latest Release MochiDecrypt by format AIR</a> –Be installed on any system that is Have<a href="http://get.adobe.com/air/" target="_blank"> Adobe Air Installer</a>.</p>
<p><a title="دانلود آخرین نسخه MochiDecrypt با فرمت EXE" href="http://iflashlord.com/software/MochiDecrypt/MochiDecrypt_v1.exe" target="_blank">Latest Release MochiDecrypt by format EXE </a>-Be installed on any system that is Have<a href="http://get.adobe.com/air/" target="_blank"> Adobe Air Installer</a>.</p>
<p><strong>note:</strong></p>
<p>Windows 7 is better to run that program, right click and click Run as administrator option to run the program.</p>
<p><strong>Changes made in new versions</strong></p>
<p><strong>Version : 1.0.0</strong></p>
<p>The first version was created.</p>
<p><strong>Debug:</strong></p>
<p>If you have a problem or see an error in the program. You can be the same for bug fixes and improvements to the program tell me.</p>
<p>be successful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/06/extract-swf-file-from-mochimedia-encrypted-file-mochidecrypter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding OOP &#8211; Introduction</title>
		<link>http://blog.flashbanneronline.com/2011/04/understanding-oop-introduction/</link>
		<comments>http://blog.flashbanneronline.com/2011/04/understanding-oop-introduction/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 20:53:33 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[abstraction]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[get]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[internal]]></category>
		<category><![CDATA[Number]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[properties]]></category>
		<category><![CDATA[protected]]></category>
		<category><![CDATA[public]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[tot]]></category>
		<category><![CDATA[trace]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=543</guid>
		<description><![CDATA[Everything that has an instance name,is an Object. Each object inherits the properties and methods of its class. The Class is basically the &#8220;prototype&#8221; of an Object,and as such,you can have as many objects as you want from a single class. In AS3,we&#8217;ve two ways of creating objects,one is using the &#8220;new&#8221; keyword,and the other [...]]]></description>
			<content:encoded><![CDATA[<p>Everything that has an instance name,is an Object. Each object inherits  the properties and methods of its class. The Class is basically the  &#8220;prototype&#8221; of an Object,and as such,you can have as many objects as you  want from a single class.</p>
<p>In AS3,we&#8217;ve two ways of creating  objects,one is using the &#8220;new&#8221; keyword,and the other is to just declare  the variable typing its datatype(this method only works for top-level  classes like Strings,Arrays,ints,Numbers and so on).</p>
<pre class="brush: as3; title: ; notranslate">

var numberObject:Number = 5; //This is a Number object.
var myOtherNumber:Number = new Number(5); // this is also a Number object.
</pre>
<p>Lets take a look at how a custom Class is structured:</p>
<pre class="brush: as3; title: ; notranslate">

package myPackage
{
class MyClass
{

}
}
</pre>
<p>First we&#8217;ve the Package,which can be used to group classes with similar  functionality or that are meant to work with each other.Using the above  example,we could import that class to use like this,based on its  package:</p>
<pre class="brush: as3; title: ; notranslate">

//This imports only &quot;MyClass&quot;
import myPackage.MyClass;
</pre>
<pre class="brush: as3; title: ; notranslate">

//This imports all the classes inside the package &quot;myPackage&quot;
import myPackage.*;
</pre>
<p>Next,we&#8217;ve the class itself,and inside it is where we put our  variables,properties and function.Its important to note that the class  name should be the same as the file name.In our example,we should name  that file &#8220;MyClass.as&#8221;.</p>
<p>The most important function a class  has,is the constructor.That is what let us create an object based on  that class.Constructor functions are always <span style="color: #3366ff;">public</span>(in AS3).You won&#8217;t need a constructor for static classes(more on another tutorial).</p>
<pre class="brush: as3; title: ; notranslate">

public class MyClass
{
//this is the constructor function
public function MyClass() {

}
}
</pre>
<p>Objects can define how their methods and properties can be accessed by other objects.Those are called &#8220;<span style="color: #3366ff;">access modifiers</span>&#8220;.We&#8217;ve 4 types of access modifiers in AS3:</p>
<p><span style="color: #0000ff;">public</span>: Classes,methods or properties declared public can be accessed by any other object.<br />
<span style="color: #0000ff;">protected</span>: Methods or properties declared protected can be accessed by any subclass object(more on another tutorial).<br />
<span style="color: #0000ff;">private</span>: Methods or properties declared private can be accessed by the object itself only.<br />
<span style="color: #0000ff;">internal</span>: The class,property or method can only be used by classes inside this package.</p>
<p>Access modifiers are another step in providing <a href="http://en.wikipedia.org/wiki/Abstraction_%28computer_science%29" target="_blank">abstraction</a> to programming.It lets you provide an object with methods that are  public(can be accessed anywhere),but the complex functionality is hidden  through the protected,private and internal modifiers.</p>
<p>To create a custom function or variable for your object,is simple:</p>
<pre class="brush: as3; title: ; notranslate">

public var myVar:String = &quot;This is myVar&quot;;

public function myFunction():void {
trace(&quot;This is myFunction&quot;);
}
</pre>
<p>To use our created class,we instantiate it using the &#8220;new&#8221; method</p>
<pre class="brush: as3; title: ; notranslate">

var myObject:MyClass = new MyClass();
</pre>
<p>To access its method or variables:</p>
<pre class="brush: as3; title: ; notranslate">

trace(myObject.myVar);
myObject.myFunction();
</pre>
<p>Classes also have <span style="color: #0000ff;">properties</span>(which differ  abit from variables).They normally are used to set internal variables  and possibly run another internal function. To create a property,you  need to use the special &#8220;<span style="color: #0000ff;">get</span>&#8221; and &#8220;<span style="color: #0000ff;">set</span>&#8221; method.<br />
&#8220;<span style="color: #0000ff;">get</span>&#8221; is used to retrieve the variable,but not allowing you to change its value(it simulates a read-only enviroment).<br />
&#8220;<span style="color: #0000ff;">set</span>&#8221; is used to write the variable,where you can run custom functions after changing its value:</p>
<pre class="brush: as3; title: ; notranslate">

private var _myProperty:String;

public function get myProperty():String {
return _myProperty;
}

public function set myProperty(value:String):void
{
_myProperty = value;
trace(&quot;myProperty value was changed! Value = &quot; + value);
}
</pre>
<p>The property is then handled just like a variable:</p>
<pre class="brush: as3; title: ; notranslate">

myObject.myProperty = &quot;myValue&quot;;
trace(myObject.myProperty);
</pre>
<p><strong>Output :</strong></p>
<p>myProperty value was changed! Value = myValue<br />
myValue</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/04/understanding-oop-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Optimization &#8211; Activate &amp; Deactivate Events</title>
		<link>http://blog.flashbanneronline.com/2011/04/flash-optimization-activate-deactivate-events/</link>
		<comments>http://blog.flashbanneronline.com/2011/04/flash-optimization-activate-deactivate-events/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 01:50:44 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Activate]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Deactivate]]></category>
		<category><![CDATA[Event.ACTIVATE]]></category>
		<category><![CDATA[Event.DEACTIVATE]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[originalFrameRate]]></category>
		<category><![CDATA[stage.frameRate]]></category>
		<category><![CDATA[standbyFrameRate]]></category>
		<category><![CDATA[Tricks]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=533</guid>
		<description><![CDATA[Flash optimization is becoming increasing important &#38; with alternative development tools that developers can use. We all have a responsibility to build Flash elements that are efficient as much as they are groundbreaking. As someone who feels responsible for the future of this great application, I am creating a Flash Optimization series that will help [...]]]></description>
			<content:encoded><![CDATA[<p>Flash optimization is becoming increasing important &amp; with      alternative development tools that developers can use. We all have a      responsibility to build Flash elements that are efficient as much as      they are groundbreaking. As someone who feels responsible for the  future     of this great application, I am creating a Flash Optimization  series     that will help educate the Flash development community on  how to  keep    their Flash elements as lean as possible.</p>
<p>Flash Player 9 introduced two events (<strong>Event.ACTIVATE and Event.DEACTIVATE</strong>) that can assist you in fine-tuning your application so that it uses the fewest CPU cycles possible. These events <strong>allow you to detect when Flash Player gains or loses focus</strong>. As a result, code can be optimized to react to context changes.</p>
<p>Note: <strong>Use Event.ACTIVATE and Event.DEACTIVATE events to detect background inactivity and optimize your<br />
application appropriately.</strong></p>
<p>The following code listens to both events and dynamically changes the  frame rate to zero when the application loses its focus. For example,  the animation can lose focus when the user switches to another tab or  puts the application into the background:</p>
<pre class="brush: as3; title: ; notranslate">

var originalFrameRate:uint = stage.frameRate;
var standbyFrameRate:uint = 0;

stage.addEventListener ( Event.ACTIVATE, onActivate );
stage.addEventListener ( Event.ACTIVATE, onDeactivate );

function onActivate ( e:Event ):void
{
// restore original frame rate
stage.frameRate = originalFrameRate;
}

function onDeactivate ( e:Event ):void
{
// set frame rate to 0
stage.frameRate = standbyFrameRate;
}
</pre>
<p><strong>When the application gains focus again, the frame rate is reset to its original value</strong>.  Instead of changing the frame rate dynamically, you could also consider  making other optimizations, such as freezing and unfreezing objects.  The activate and deactivate events allow you to implement a similar  mechanism to the “Pause and Resume” feature sometimes found on mobile  devices and Net books.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/04/flash-optimization-activate-deactivate-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Optimization &#8211; Freezing And Unfreezing Objects</title>
		<link>http://blog.flashbanneronline.com/2011/04/flash-optimization-freezing-and-unfreezing-objects/</link>
		<comments>http://blog.flashbanneronline.com/2011/04/flash-optimization-freezing-and-unfreezing-objects/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 10:29:24 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[addChild]]></category>
		<category><![CDATA[addEventListener]]></category>
		<category><![CDATA[as3 frame_constructed]]></category>
		<category><![CDATA[contains]]></category>
		<category><![CDATA[currentTarget]]></category>
		<category><![CDATA[ENTER_FRAME]]></category>
		<category><![CDATA[Event.ACTIVATE]]></category>
		<category><![CDATA[Event.DEACTIVATE]]></category>
		<category><![CDATA[EXIT_FRAME]]></category>
		<category><![CDATA[FRAME_CONSTRUCTED]]></category>
		<category><![CDATA[Freezing]]></category>
		<category><![CDATA[freezing a movie clip in flash]]></category>
		<category><![CDATA[Keyboard.LEFT]]></category>
		<category><![CDATA[Keyboard.RIGHT]]></category>
		<category><![CDATA[KeyboardEvent]]></category>
		<category><![CDATA[keyCode]]></category>
		<category><![CDATA[keyIsDown]]></category>
		<category><![CDATA[Loader]]></category>
		<category><![CDATA[loader class as3 stop movie]]></category>
		<category><![CDATA[Objects]]></category>
		<category><![CDATA[play()]]></category>
		<category><![CDATA[removeChild]]></category>
		<category><![CDATA[simply to play the movieclip in flash]]></category>
		<category><![CDATA[Unfreezing]]></category>
		<category><![CDATA[unloadAndStop]]></category>
		<category><![CDATA[URLRequest]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=531</guid>
		<description><![CDATA[Flash optimization is becoming increasing important &#38; with alternative development tools that developers can use. We all have a responsibility to build Flash elements that are efficient as much as they are groundbreaking. As someone who feels responsible for the future of this great application, I am creating a Flash Optimization series that will help [...]]]></description>
			<content:encoded><![CDATA[<p>Flash optimization is becoming increasing important &amp; with     alternative development tools that developers can use. We all have a     responsibility to build Flash elements that are efficient as much as     they are groundbreaking. As someone who feels responsible for the future     of this great application, I am creating a Flash Optimization series     that will help educate the Flash development community on how to  keep    their Flash elements as lean as possible.</p>
<p>To optimize your code, <strong>always freeze and unfreeze your objects</strong>.  Freezing and unfreezing are important for all objects, but are  especially important for display objects. Even if display objects are no  longer in the display list and are waiting to be garbage collected,<strong> they could still be using CPU-intensive code</strong>.</p>
<p>For example, <strong>they can still be using Event.ENTER_FRAME</strong>. As a result, <strong>it is critical to freeze and unfreeze objects properly with the Event.REMOVED_FROM_STAGE and Event.ADDED_TO_STAGE events</strong>. The following example shows a movie clip<br />
playing on stage that interacts with the keyboard:</p>
<pre class="brush: as3; title: ; notranslate">

// Listen to keyboard events
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyIsDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyIsUp);

// Create object to store key states
var keys:Dictionary = new Dictionary(true);

function keyIsDown(e:KeyboardEvent):void
{
// Remember that the key was pressed
keys[e.keyCode] = true;

if (e.keyCode==Keyboard.LEFT || e.keyCode==Keyboard.RIGHT)
{
runningBoy.play();
}
}

function keyIsUp(e:KeyboardEvent):void
{
// Remember that the key was released
keys[e.keyCode] = false;

for each (var value:Boolean in keys)
if ( value ) return;
runningBoy.stop();
}

runningBoy.addEventListener(Event.ENTER_FRAME, handleMovement);
runningBoy.stop();

var currentState:Number = runningBoy.scaleX;
var speed:Number = 15;

function handleMovement(e:Event):void
{
if (keys[Keyboard.RIGHT])
{
e.currentTarget.x += speed;
e.currentTarget.scaleX = currentState;
} else if (keys[Keyboard.LEFT])
{
e.currentTarget.x -= speed;
e.currentTarget.scaleX = -currentState;
}
}
</pre>
<p>When the Remove button is clicked, the movie clip is removed from the display list:</p>
<pre class="brush: as3; title: ; notranslate">

// Show or remove running boy
showBtn.addEventListener (MouseEvent.CLICK,showIt);
removeBtn.addEventListener (MouseEvent.CLICK,removeIt);

function showIt (e:MouseEvent):void
{
addChild (runningBoy);
}

function removeIt(e:MouseEvent):void
{
if (contains(runningBoy)) removeChild(runningBoy);
}
</pre>
<p><strong>Even when removed from the display list, the movie clip still dispatches the Event.ENTER_FRAME event</strong>. The movie<br />
clip still runs, but it is not rendered. To handle this situation correctly, <strong>listen to the proper events and remove event listeners</strong>, to prevent CPU-intensive code from being executed:</p>
<pre class="brush: as3; title: ; notranslate">

// Listen to Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE
runningBoy.addEventListener(Event.ADDED_TO_STAGE,activate);
runningBoy.addEventListener(Event.REMOVED_FROM_STAGE,deactivate);

function activate(e:Event):void
{
// Restart everything
e.currentTarget.addEventListener(Event.ENTER_FRAME,handleMovement);
}

function deactivate(e:Event):void
{
// Freeze the running boy – consumes fewer CPU resources when not shown
e.currentTarget.removeEventListener(Event.ENTER_FRAME,handleMovement);
e.currentTarget.stop();
}
</pre>
<p>When the Show button is pressed, <strong>the movie clip is restarted, it listens to Event.ENTER_FRAME events again</strong>, and the<br />
keyboard correctly controls the movie clip.</p>
<p>Note: If a display object is removed from the display list, setting  its reference to null after removing it does not ensure that the object  is frozen. If the garbage collector doesn’t run, the object continues to  consume memory and CPU processing, even though the object is no longer  displayed. <strong>To make sure that the object consumes the least CPU  processing possible, make sure that you completely freeze it when  removing it from the display list. </strong></p>
<p>Since Flash Player 10, if the playhead encounters an empty frame, the  display object is automatically frozen even if you did not implement  any freezing behavior.</p>
<p>The concept of freezing is also important when loading remote content  with the Loader class. When using the Loader class with Flash Player 9,  it was necessary to manually freeze content by listening to the  Event.UNLOAD event dispatched by the LoaderInfo object. Every object had  to be manually frozen, which was a non-trivial task. Flash Player 10  introduced an important <strong>new method on the Loader class called unloadAndStop()</strong>. This method <strong>allows  you to unload a SWF file, automatically freeze every object in the  loaded SWF file, and force the garbage collector to run</strong>.</p>
<p>In the following code, the <strong>SWF file is loaded and then unloaded using the unload() method</strong>, which requires more processing and manual freezing:</p>
<pre class="brush: as3; title: ; notranslate">

var loader:Loader = new Loader();

loader.load ( new URLRequest ( “content.swf” ) );

addChild ( loader );

stage.addEventListener ( MouseEvent.CLICK, unloadSWF );

function unloadSWF ( e:MouseEvent ):void
{
// Unload the SWF file with no automatic object deactivation
// All deactivation must be processed manually
loader.unload();
}
</pre>
<p>A best practice is to <strong>use the unloadAndStop() method, which handles the freezing natively and forces the garbage<br />
collecting process to run</strong>:</p>
<pre class="brush: as3; title: ; notranslate">

var loader:Loader = new Loader();

loader.load ( new URLRequest ( “content.swf” ) );

addChild ( loader );

stage.addEventListener ( MouseEvent.CLICK, unloadSWF );

function unloadSWF ( e:MouseEvent ):void
{
// Unload the SWF file with automatic object deactivation
// All deactivation is handled automatically
loader.unloadAndStop();
}
</pre>
<p>The following<strong> actions occur when the unloadAndStop()</strong> method is called:<br />
• Sounds are stopped.<br />
• Listeners registered to the SWF file’s main timeline are removed.<br />
• Timer objects are stopped.<br />
• Hardware peripheral devices (such as camera and microphone) are released.<br />
• Every movie clip is stopped.<br />
• Dispatching of Event.ENTER_FRAME, Event.FRAME_CONSTRUCTED, Event.EXIT_FRAME, Event.ACTIVATE and Event.DEACTIVATE is stopped.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/04/flash-optimization-freezing-and-unfreezing-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flash Optimization &#8211; Freeing Memory</title>
		<link>http://blog.flashbanneronline.com/2011/04/flash-optimization-freeing-memory/</link>
		<comments>http://blog.flashbanneronline.com/2011/04/flash-optimization-freeing-memory/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 23:33:57 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Air]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[CPU-intensive]]></category>
		<category><![CDATA[creation of a matching game with flash and as3]]></category>
		<category><![CDATA[dispose();]]></category>
		<category><![CDATA[disposeXML]]></category>
		<category><![CDATA[disposexml air]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[freeing a sprite from memory as3]]></category>
		<category><![CDATA[garbage collection]]></category>
		<category><![CDATA[memory flash banner]]></category>
		<category><![CDATA[null]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[references]]></category>
		<category><![CDATA[Sprite]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[tot]]></category>
		<category><![CDATA[totalMemory]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=525</guid>
		<description><![CDATA[Flash optimization is becoming increasing important &#38; with alternative development tools that developers can use. We all have a responsibility to build Flash elements that are efficient as much as they are groundbreaking. As someone who feels responsible for the future of this great application, I am creating a Flash Optimization series that will help [...]]]></description>
			<content:encoded><![CDATA[<p>Flash optimization is becoming increasing important &amp; with     alternative development tools that developers can use. We all have a     responsibility to build Flash elements that are efficient as much as     they are groundbreaking. As someone who feels responsible for the future     of this great application, I am creating a Flash Optimization series     that will help educate the Flash development community on how to  keep    their Flash elements as lean as possible.</p>
<p>You cannot launch the <strong>garbage collector</strong> directly in the release  version of Flash Player. To make sure that an object is garbage  collected, delete all references to the object. Keep in mind that the  old delete operator used in ActionScript 1.0 and 2.0 behaves differently  in ActionScript 3.0. It can only be used to delete dynamic properties  on a dynamic object.</p>
<p>Note: You can call the garbage collector directly in Adobe® AIR® and in the debug version of Flash Player.</p>
<p>For example, the following code sets a Sprite reference to null:</p>
<pre class="brush: as3; title: ; notranslate">

var mySprite:Sprite = new Sprite();

// Set the reference to null, so that the garbage collector removes it from memory
 mySprite = null;
</pre>
<p>Remember that when an object is set to null, it is not necessarily  removed from memory. Sometimes the garbage collector does not run, if  available memory is not considered low enough. <strong>Garbage collection is not predictable</strong>.</p>
<p><strong>Memory allocation, rather than object deletion, triggers garbage collection</strong>. When the garbage collector runs, it finds graphs of objects that haven’t been collected yet.<strong> It detects inactive objects in the graphs by finding objects that reference each other, but that the application no longer uses</strong>. Inactive objects detected this way are deleted.</p>
<p>In large applications,<strong> this process can be CPU-intensive and can affect performance and generate a noticeable slowdown in the application</strong>. <strong>Try to limit garbage collection passes by reusing objects as much as possible</strong>.</p>
<p>Also,<strong> set references to null</strong>, when possible, <strong>so that the garbage collector spends less processing time finding the objects</strong>. Think of garbage collection as insurance, and always manage object lifetimes explicitly, when possible.</p>
<p>Note: Setting a reference to a display object to null does not ensure  that the object is frozen. The object continues consume CPU cycles  until it is garbage collected. <strong>Make sure that you properly deactivate your object before setting its reference to null</strong>.</p>
<p><strong>The garbage collector can be launched using the System.gc()  method, available in Adobe AIR and in the debug version of Flash Player</strong>.  The profiler bundled with Adobe® Flash® Builder™ allows you to start  the garbage collector manually. Running the garbage collector <strong>allows you to see how your application responds and whether objects are correctly deleted from memory</strong>.</p>
<p>Note: If an object was used as an event listener, another object can reference it. If so, <strong>remove event listeners using the removeEventListener()method before setting the references to null</strong>.</p>
<p>Fortunately, the amount of memory used by bitmaps can be instantly reduced. For example, the <strong>BitmapData class includes a dispose() method</strong>.  The next example creates a BitmapData instance of 1.8 MB. The current  memory in use grows to 1.8 MB, and the System.totalMemory property  returns a smaller value:</p>
<pre class="brush: as3; title: ; notranslate">

trace(System.totalMemory / 1024);
 // output: 43100

// Create a BitmapData instance
 var image:BitmapData = new BitmapData(800, 600);

trace(System.totalMemory / 1024);
 // output: 44964
</pre>
<p>Next, <strong>the BitmapData is manually removed</strong> (disposed) from memory and the memory use is once again checked:</p>
<pre class="brush: as3; title: ; notranslate">

trace(System.totalMemory / 1024);
 // output: 43100

// Create a BitmapData instance
 var image:BitmapData = new BitmapData(800, 600);

trace(System.totalMemory / 1024);
 // output: 44964

image.dispose();
 image = null;

trace(System.totalMemory / 1024);
 // output: 43084
</pre>
<p>Although the dispose()method removes the pixels from memory, the <strong>reference must still be set to null to release it<br />
completely</strong>. Always call the dispose() method and set the reference to null when you no longer need a BitmapData<br />
object, so that memory is freed immediately.</p>
<p>Note: Flash Player 10.1 and AIR 1.5.2 introduce <strong>a new method called disposeXML() on the System class</strong>. This method<br />
<strong>allows you to make an XML object immediately available for garbage collection</strong>, by passing the XML tree as a parameter.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/04/flash-optimization-freeing-memory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Optimization – Object Pooling</title>
		<link>http://blog.flashbanneronline.com/2011/04/flash-optimization-object-pooling/</link>
		<comments>http://blog.flashbanneronline.com/2011/04/flash-optimization-object-pooling/#comments</comments>
		<pubDate>Sun, 10 Apr 2011 04:08:13 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[beginFill]]></category>
		<category><![CDATA[disposeSprite]]></category>
		<category><![CDATA[drawCircle]]></category>
		<category><![CDATA[getSprite]]></category>
		<category><![CDATA[Object Pooling]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[package]]></category>
		<category><![CDATA[remove]]></category>
		<category><![CDATA[removeChildAt]]></category>
		<category><![CDATA[Sprite]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=519</guid>
		<description><![CDATA[Flash optimization is becoming increasing important &#38; with alternative development tools that developers can use. We all have a responsibility to build Flash elements that are efficient as much as they are groundbreaking. As someone who feels responsible for the future of this great application, I am creating a Flash Optimization series that will help [...]]]></description>
			<content:encoded><![CDATA[<p>Flash optimization is becoming increasing important &amp; with    alternative development tools that developers can use. We all have a    responsibility to build Flash elements that are efficient as much as    they are groundbreaking. As someone who feels responsible for the future    of this great application, I am creating a Flash Optimization series    that will help educate the Flash development community on how to keep    their Flash elements as lean as possible.</p>
<p>Another important optimization is called <strong>object pooling, which involves reusing objects over time</strong>.</p>
<p>You create a defined number of objects during the initialization of your application and store them inside a pool, such as an <strong>Array or Vector object</strong>. <strong>Once you are done with an object, you deactivate it so that it does not consume CPU resources, and<br />
you remove all mutual references</strong>.</p>
<p>However, <strong>you DO NOT set the references to null, which would make it eligible for garbage collection</strong>. You just put the object back into the pool, and <strong>retrieve it when you need a new object</strong>. Reusing objects reduces the need to instantiate objects, which can be expensive. It also <strong>reduces the chances of the garbage collector running, which can slow down your application</strong>. The following code illustrates the object pooling technique:</p>
<pre class="brush: as3; title: ; notranslate">

package
 {
 import flash.display.Sprite;

public final class SpritePool
 {
 private static var MAX_VALUE:uint;
 private static var GROWTH_VALUE:uint;
 private static var counter:uint;
 private static var pool:Vector.&lt;Sprite&gt;;
 private static var currentSprite:Sprite;

public static function initialize( maxPoolSize:uint, growthValue:uint ):void
 {
 MAX_VALUE = maxPoolSize;
 GROWTH_VALUE = growthValue;
 counter = maxPoolSize;

var i:uint = maxPoolSize;

pool = new Vector.&lt;Sprite&gt;(MAX_VALUE);
 while( –i &gt; -1 )
 pool[i] = new Sprite();
 }

public static function getSprite():Sprite
 {
 if ( counter &gt; 0 )
 return currentSprite = pool[--counter];

var i:uint = GROWTH_VALUE;
 while( –i &gt; -1 )

pool.unshift ( new Sprite() );
 counter = GROWTH_VALUE;
 return getSprite();
 }

public static function disposeSprite(disposedSprite:Sprite):void
 {
 pool[counter++] = disposedSprite;
 }
 }
 }
</pre>
<p><strong>The SpritePool class creates a pool of new objects at the initialization of the application.</strong><br />
The <strong>getSprite() method returns instances of these objects</strong>, and the <strong>disposeSprite() method releases them</strong>.  The code allows the pool to grow when it has been consumed completely.  It’s also possible to create a fixed-size pool where new objects would  not be allocated when the pool is exhausted. Try to avoid creating new  objects in loops, if possible.</p>
<p>The following code uses the SpritePool class to retrieve new instances:</p>
<pre class="brush: as3; title: ; notranslate">

const MAX_SPRITES:uint = 100;
 const GROWTH_VALUE:uint = MAX_SPRITES &gt;&gt; 1;
 const MAX_NUM:uint = 10;

SpritePool.initialize ( MAX_SPRITES,  GROWTH_VALUE );

var currentSprite:Sprite;
 var container:Sprite = SpritePool.getSprite();

addChild ( container );

for ( var i:int = 0; i&lt; MAX_NUM; i++ )
 {
 for ( var j:int = 0; j&lt; MAX_NUM; j++ )
 {
 currentSprite = SpritePool.getSprite();
 currentSprite.graphics.beginFill ( 0×990000 );
 currentSprite.graphics.drawCircle ( 10, 10, 10 );
 currentSprite.x = j * (currentSprite.width + 5);
 currentSprite.y = i * (currentSprite.width + 5);
 container.addChild ( currentSprite );
 }
 }
</pre>
<p>The following code removes all the display objects from the display list when the mouse is clicked, and reuses them<br />
later for another task:</p>
<pre class="brush: as3; title: ; notranslate">

stage.addEventListener ( MouseEvent.CLICK, removeDots );

function removeDots ( e:MouseEvent ):void
 {
 while (container.numChildren &gt; 0 )
 SpritePool.disposeSprite (container.removeChildAt(0) as Sprite );
 }
</pre>
<p>Note: The pool vector always references the Sprite objects. If you want to remove the object from memory completely, you<br />
would need a dispose() method on the SpritePool class, which would remove all remaining references.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/04/flash-optimization-object-pooling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Optimization – Reusing Objects</title>
		<link>http://blog.flashbanneronline.com/2011/04/flash-optimization-reusing-objects/</link>
		<comments>http://blog.flashbanneronline.com/2011/04/flash-optimization-reusing-objects/#comments</comments>
		<pubDate>Sat, 09 Apr 2011 08:26:13 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[fillRect]]></category>
		<category><![CDATA[height]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[Math.round]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[memory flash banner]]></category>
		<category><![CDATA[Objects]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Reusing]]></category>
		<category><![CDATA[width]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=503</guid>
		<description><![CDATA[Flash optimization is becoming increasing important &#38; with alternative development tools that developers can use. We all have a responsibility to build Flash elements that are efficient as much as they are groundbreaking. As someone who feels responsible for the future of this great application, I am creating a Flash Optimization series that will help [...]]]></description>
			<content:encoded><![CDATA[<p>Flash optimization is becoming increasing important &amp; with   alternative development tools that developers can use. We all have a   responsibility to build Flash elements that are efficient as much as   they are groundbreaking. As someone who feels responsible for the future   of this great application, I am creating a Flash Optimization series   that will help educate the Flash development community on how to keep   their Flash elements as lean as possible.</p>
<p><strong>Another simple way to optimize memory is to reuse objects and avoid recreating them whenever possible.</strong><br />
For example, in a loop, <strong>do not use the following code</strong>:</p>
<pre class="brush: as3; title: ; notranslate">

const MAX_NUM:int = 18;
 const COLOR:uint = 0xCCCCCC;

var area:Rectangle;

for (var:int = 0; i &lt; MAX_NUM; i++)
 {
 // Do not use the following code
 area = new Rectangle(i,0,1,10);
 myBitmapData.fillRect(area,COLOR);
 }
</pre>
<p><strong>Recreating the Rectangle object in each loop iteration uses more memory and is slower because a new object is created<br />
in each iteration</strong>. <strong>Use the following approach</strong>:</p>
<pre class="brush: as3; title: ; notranslate">

const MAX_NUM:int = 18;
 const COLOR:uint = 0xCCCCCC;

// Create the rectangle outside the loop
 var area:Rectangle = new Rectangle(0,0,1,10);

for (var:int = 0; i &lt; MAX_NUM; i++)
 {
 area.x = i;
 myBitmapData.fillRect(area,COLOR);
 }
</pre>
<p>The previous example used an object with a relatively small memory impact. The next example demonstrates larger<br />
memory savings by reusing a BitmapData object. <strong>The following code to create a tiling effect wastes memory: </strong></p>
<pre class="brush: as3; title: ; notranslate">

var myImage:BitmapData;
 var myContainer:Bitmap;
 const MAX_NUM:int = 300;

for (var i:int = 0; i&lt; MAX_NUM; i++)
 {

// Create a 20 x 20 pixel bitmap, non-transparent
 myImage = new BitmapData(20,20,false,0xF0D062);

// Create a container for each BitmapData instance
 myContainer = new Bitmap(myImage);

// Add it to the display list
 addChild(myContainer);

// Place each container
 myContainer.x = (myContainer.width + 8 ) * Math.round(i % 20);
myContainer.y = (myContainer.height + 8 ) * int(i / 20);
 }
</pre>
<p>An optimized version creates a single BitmapData instance referenced by multiple Bitmap instances and produces the same result:</p>
<pre class="brush: as3; title: ; notranslate">

// Create a single 20 x 20 pixel bitmap, non-transparent
 var myImage:BitmapData = new BitmapData(20,20,false,0xF0D062);
 var myContainer:Bitmap;
 const MAX_NUM:int = 300;

for (var i:int = 0; i&lt; MAX_NUM; i++)
 {
 // Create a container referencing the BitmapData instance
 myContainer = new Bitmap(myImage);

// Add it to the display list
 addChild(myContainer);

// Place each container
 myContainer.x = (myContainer.width + 8 ) * Math.round(i % 20);
myContainer.y = (myContainer.height + 8 ) * int(i / 20);
 }
</pre>
<p><strong>This approach saves about 700 KB in memory, which is a significant savings on a traditional mobile device</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/04/flash-optimization-reusing-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash Optimization – Display Objects</title>
		<link>http://blog.flashbanneronline.com/2011/04/flash-optimization-display-objects/</link>
		<comments>http://blog.flashbanneronline.com/2011/04/flash-optimization-display-objects/#comments</comments>
		<pubDate>Wed, 06 Apr 2011 14:40:08 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Adobe AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[getSize]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[MovieClip]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[Optimize]]></category>
		<category><![CDATA[Sprite]]></category>
		<category><![CDATA[timeline]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=498</guid>
		<description><![CDATA[Flash optimization is becoming increasing important &#38; with alternative development tools that developers can use. We all have a responsibility to build Flash elements that are efficient as much as they are groundbreaking. As someone who feels responsible for the future of this great application, I am creating a Flash Optimization series that will help [...]]]></description>
			<content:encoded><![CDATA[<p>Flash optimization is becoming increasing important &amp; with  alternative development tools that developers can use. We all have a  responsibility to build Flash elements that are efficient as much as  they are groundbreaking. As someone who feels responsible for the future  of this great application, I am creating a Flash Optimization series  that will help educate the Flash development community on how to keep  their Flash elements as lean as possible.</p>
<p><span id="more-498"></span></p>
<p>One of the most simple optimization tips to limit memory usage is to use the appropriate type of display object. <strong>For  simple shapes that are not interactive, use Shape objects. For  interactive objects that don’t need a timeline, use Sprite objects. For  animation that uses a timeline, use MovieClip objects. </strong>Always choose the most efficient type of object for your application.</p>
<p>The following code shows memory usage for different display objects:</p>
<pre class="brush: as3; title: ; notranslate">
 trace(getSize(new Shape()));
 // output: 236
</pre>
<pre class="brush: as3; title: ; notranslate">

trace(getSize(new Sprite()));
 // output: 412
</pre>
<pre class="brush: as3; title: ; notranslate">

trace(getSize(new MovieClip()));
 // output: 440
</pre>
<p>The <strong>getSize() </strong>method shows how many bytes an object consumes in memory. You can see that using multiple<br />
MovieClip objects instead of simple Shape objects can waste memory if the capabilities of a MovieClip object are not<br />
needed.</p>
<p>resource : <a href="http://www.rgbeffects.com/blog/actionscript/flash-optimization-actionscript-efficiency/" target="_blank">RGBLog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/04/flash-optimization-display-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding ActionScript3 Manages Depths</title>
		<link>http://blog.flashbanneronline.com/2011/01/understanding-actionscript3-manages-depths/</link>
		<comments>http://blog.flashbanneronline.com/2011/01/understanding-actionscript3-manages-depths/#comments</comments>
		<pubDate>Mon, 24 Jan 2011 21:33:39 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA["as3 describetype"]]></category>
		<category><![CDATA[actionscript getchild]]></category>
		<category><![CDATA[actionscript3 get first child]]></category>
		<category><![CDATA[addChild]]></category>
		<category><![CDATA[addChildAt]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[as3 get child at index]]></category>
		<category><![CDATA[as3 get child by index]]></category>
		<category><![CDATA[as3 get child by name]]></category>
		<category><![CDATA[as3 get child index]]></category>
		<category><![CDATA[as3 get childs index]]></category>
		<category><![CDATA[as3 get index of child]]></category>
		<category><![CDATA[as3 getchild]]></category>
		<category><![CDATA[as3 getchild by occurrence name]]></category>
		<category><![CDATA[as3 getchildby]]></category>
		<category><![CDATA[as3 getchildbydepth]]></category>
		<category><![CDATA[as3 sprite get child by name]]></category>
		<category><![CDATA[Banner]]></category>
		<category><![CDATA[beginFill]]></category>
		<category><![CDATA[blog.flashbanneronline.com]]></category>
		<category><![CDATA[coordinate]]></category>
		<category><![CDATA[drawRect]]></category>
		<category><![CDATA[dynamic actionscript 3 banner for flash website]]></category>
		<category><![CDATA[flash as3 getchildby]]></category>
		<category><![CDATA[flash as3 getchildindex]]></category>
		<category><![CDATA[flash child index name as3]]></category>
		<category><![CDATA[flash getchildindex]]></category>
		<category><![CDATA[FlashBannerOnline.com]]></category>
		<category><![CDATA[get child index as3]]></category>
		<category><![CDATA[get child index by name as3]]></category>
		<category><![CDATA[getchildbydepth]]></category>
		<category><![CDATA[getChildIndex]]></category>
		<category><![CDATA[getchildindex as3]]></category>
		<category><![CDATA[getNextHighestDepth]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[index child as3]]></category>
		<category><![CDATA[lineStyle]]></category>
		<category><![CDATA[MovieClip]]></category>
		<category><![CDATA[setChildIndex]]></category>
		<category><![CDATA[Shape]]></category>
		<category><![CDATA[Sprite]]></category>
		<category><![CDATA[sprite getchild]]></category>
		<category><![CDATA[sprite getchild by name]]></category>
		<category><![CDATA[swapChildren]]></category>
		<category><![CDATA[swapchildren as3]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=476</guid>
		<description><![CDATA[This tutorial will explain you how to manage AS3 sprites and depths, and what’s changed from AS2 to AS3. In every Actionscript version, when two movieclips (or objects, shapes, texts…) overlap, the one with the greater depth stands in front of the other. You can think about depth as a Z coordinate. The first difference [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial will explain you how to manage AS3 sprites and depths, and what’s changed from AS2 to AS3.</p>
<p>In every Actionscript version, when two movieclips (or objects,   shapes, texts…) overlap, the one with the greater depth stands in front   of the other. You can think about depth as a Z coordinate.</p>
<p>The first difference between AS2 and AS3 is that AS2 allows you to leave “holes” in depths.</p>
<p>For example, you can declare the first object with a depth of 2 and   the second one with a depth of 200… no matter if there isn’t any object   with a depth between 3 and 199. In AS3, this is no longer possible.</p>
<p>To add an object to the stage, you must use addChild(object_name).<br />
addChild() assigns the first free depth available, just like AS2 MovieClip.getNextHighestDepth()</p>
<p>So let’s add some objects to a movie:</p>
<pre class="brush: as3; title: ; notranslate">
package {
import flash.display.Shape;
import flash.display.Sprite;
public class depths extends Sprite {
public function depths() {
var blue_box:Shape = new Shape();
var red_box:Shape = new Shape();
blue_box.graphics.lineStyle(1);
blue_box.graphics.beginFill(0x0000FF, 1);
blue_box.graphics.drawRect(200,150,100,100);
red_box.graphics.lineStyle(1);
red_box.graphics.beginFill(0xFF0000, 1);
red_box.graphics.drawRect(220,170,100,100);
addChild(blue_box);
addChild(red_box);
}
}
}
</pre>
<p>This is the result: the red box is in front of the blue box because the red one was the last placed on the screen.</p>
<p><a href="http://blog.flashbanneronline.com/wp-content/uploads/2011/01/depths1.gif"><img class="aligncenter size-full wp-image-477" title="depths1" src="http://blog.flashbanneronline.com/wp-content/uploads/2011/01/depths1.gif" alt="" width="500" height="150" /></a></p>
<p>If you switch <strong>line 14</strong> with <strong>line 15</strong>, the blue one will be the one on the top:</p>
<p><a href="http://blog.flashbanneronline.com/wp-content/uploads/2011/01/depths2.gif"><img class="aligncenter size-full wp-image-478" title="depths2" src="http://blog.flashbanneronline.com/wp-content/uploads/2011/01/depths2.gif" alt="" width="500" height="150" /></a></p>
<p>Sno now we know that the first child added with addChild() is placed at depth 0, the second one is placed at depth 1, and so on.<br />
To know the depth value of an object, you can use getChildIndex(object_name);. So if you add this line:<br />
trace(getChildIndex(red_box));<br />
You will get a 1 in your output window.<br />
To add an object at a specific depth position, you can use addChildAt(object_name, depth)</p>
<p>So let’s try this code:</p>
<pre class="brush: as3; title: ; notranslate">
package {
import flash.display.Shape;
import flash.display.Sprite;
public class depths extends Sprite {
public function depths() {
var blue_box:Shape = new Shape();
var red_box:Shape = new Shape();
blue_box.graphics.lineStyle(1);
blue_box.graphics.beginFill(0x0000FF, 1);
blue_box.graphics.drawRect(200,150,100,100);
red_box.graphics.lineStyle(1);
red_box.graphics.beginFill(0xFF0000, 1);
red_box.graphics.drawRect(220,170,100,100);
addChild(blue_box);
addChildAt(red_box,0);
}
}
}
</pre>
<p>Even if the red box was added after the blue box, it’s the blue one to stay on top because the red one was placed at depth zero.</p>
<p><a href="../wp-content/uploads/2011/01/depths2.gif"><img class="aligncenter size-full wp-image-478" title="depths2" src="../wp-content/uploads/2011/01/depths2.gif" alt="" width="500" height="150" /></a></p>
<p>That’s because if the specified depth is already taken by an existing   object, then the new object is placed behind the existing one, whose   depth is increased by one. So at the end of the script, the red box has   depth zero, while the blue one has depth 1<br />
You may ask: what if I change <strong>line 14</strong> with addChildAt(blue_box,1);<br />
You can’t… you will get an error because as I said at the beginning  of  this post, you can’t leave “holes” in depth. So you can’t place an   object at depth 1 if there isn’t an object at depth 0.Using  getChildIndex in a real life example, you can change <strong>line 15</strong> with addChildAt(red_box,getChildIndex(blue_box));And you will get the same result.</p>
<p>Now, let’s see how to change depths dynamically.</p>
<pre class="brush: as3; title: ; notranslate">
package {
import flash.display.Shape;
import flash.display.Sprite;
public class depths extends Sprite {
public function depths() {
var blue_box:Shape = new Shape();
var red_box:Shape = new Shape();
blue_box.graphics.lineStyle(1);
blue_box.graphics.beginFill(0x0000FF, 1);
blue_box.graphics.drawRect(200,150,100,100);
red_box.graphics.lineStyle(1);
red_box.graphics.beginFill(0xFF0000, 1);
red_box.graphics.drawRect(220,170,100,100);
addChild(blue_box);
addChildAt(red_box,getChildIndex(blue_box));
swapChildren(red_box,blue_box);
}
}
}
</pre>
<p>At <strong>line 16</strong> the swapChildren method swaps red box’s depth with the blue box one.  So we’ll have the red box in front again</p>
<p><a href="../wp-content/uploads/2011/01/depths1.gif"><img class="aligncenter size-full wp-image-477" title="depths1" src="../wp-content/uploads/2011/01/depths1.gif" alt="" width="500" height="150" /></a></p>
<p>Another way to change depths dynamically is changing <strong>line 16</strong> with:</p>
<p>setChildIndex(blue_box,0);</p>
<p>Putting the blue box to depth zero again and make the red one stay on the top of the screen.</p>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow: hidden;">
<p>This tutorial will explain you how to manage AS3 sprites and depths, and what’s changed from AS2 to AS3.</p>
<p>In every Actionscript version, when two movieclips (or objects,   shapes, texts…) overlap, the one with the greater depth stands in front   of the other. You can think about depth as a Z coordinate.</p>
<p>The first difference between AS2 and AS3 is that AS2 allows you to leave “holes” in depths.</p>
<p>For example, you can declare the first object with a depth of 2 and   the second one with a depth of 200… no matter if there isn’t any object   with a depth between 3 and 199. In AS3, this is no longer possible.</p>
<p>To add an object to the stage, you must use addChild(object_name).<br />
addChild() assigns the first free depth available, just like AS2 MovieClip.getNextHighestDepth()</p>
<p>So let’s add some objects to a movie:</p></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/01/understanding-actionscript3-manages-depths/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>with() Statement in Actionscript 3</title>
		<link>http://blog.flashbanneronline.com/2011/01/with-statement-in-actionscript-3/</link>
		<comments>http://blog.flashbanneronline.com/2011/01/with-statement-in-actionscript-3/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 12:43:25 +0000</pubDate>
		<dc:creator>Behrouz Pooladrag</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Actionscript 3]]></category>
		<category><![CDATA[actoinscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Banner]]></category>
		<category><![CDATA[blog.flashbanneronline.com]]></category>
		<category><![CDATA[FlashBannerOnline.com]]></category>
		<category><![CDATA[hide]]></category>
		<category><![CDATA[mouse]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Statement]]></category>
		<category><![CDATA[with]]></category>

		<guid isPermaLink="false">http://blog.flashbanneronline.com/?p=471</guid>
		<description><![CDATA[Often times, you will find yourself assigning many properties to one particular movie clip. Let’s say you have a movie clip instance called data_txt. Adding properties to it could look like this: Notice how you are repeating the word theContent. A better, cleaner method for referencing one particular object would be to use the with() [...]]]></description>
			<content:encoded><![CDATA[<p>Often times, you will find yourself assigning many properties to one  particular movie clip. Let’s say you have a movie clip instance called data_txt. Adding properties to it could look like this:</p>
<pre class="brush: as3; title: ; notranslate">
data_txt.text = &quot;flashbanneronline.com!&quot;;
data_txt.x = 256;
data_txt.y = 145;
data_txt.alpha = 0.3;
</pre>
<p>Notice how you are repeating the word theContent. A  					better,  cleaner method for referencing one particular object  					would be to  use the with() statement.</p>
<p>The with() statement calls an object once and allows you to  					 access all of the object’s properties and methods with only  					one  reference. For example, using the with() statement, the  					above  lines of code can be written as the following:</p>
<pre class="brush: as3; title: ; notranslate">
with(data_txt)
{

text = &quot;flashbanneronline.com!&quot;;
x =256;
y =145;
alpha = 0.3;

}
</pre>
<p>I refer to <strong>data_txt</strong> only once! The with()  			 		statement may not be versatile enough to carry event  					handlers,  but it does the work of referencing almost any  					class or object for  you.</p>
<p>The following is an example of it working with the top  					level class Mouse:</p>
<pre class="brush: as3; title: ; notranslate">
with(Mouse)
{

hide();

}
</pre>
<p>In the above code snippet, I used a top level class and  					called its hide method.</p>
<p>You can also call nested objects inside the original  					object.  Here is a diagram to better help you visualize what  					I am referring  to:</p>
<p><a href="http://blog.flashbanneronline.com/wp-content/uploads/2011/01/diagram.gif"><img class="aligncenter size-full wp-image-472" title="diagram" src="http://blog.flashbanneronline.com/wp-content/uploads/2011/01/diagram.gif" alt="" width="245" height="214" /></a>The code for calling the secondObject object  					using <strong>with()</strong> would be:</p>
<pre class="brush: as3; title: ; notranslate">

with(firstObject)
{

secondObject.x = 110;

}
</pre>
<p>Here, I used a direct path to gain access to the  					properties of the nested secondObject object.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.flashbanneronline.com/2011/01/with-statement-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic (Feed is rejected)
Page Caching using disk: enhanced
Database Caching 51/111 queries in 2.688 seconds using disk: basic
Object Caching 3324/3544 objects using disk: basic

Served from: blog.flashbanneronline.com @ 2012-02-11 14:13:52 -->
