<?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>Mindfock &#187; ActionScript</title>
	<atom:link href="http://blog.mindfock.com/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.mindfock.com</link>
	<description>Flash and ActionScript for the masses. With a little Python thrown in.</description>
	<lastBuildDate>Wed, 31 Mar 2010 10:07:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Nice source-codes from 25-lines AS contest</title>
		<link>http://blog.mindfock.com/nice-source-codes-from-25-lines-as-contest/</link>
		<comments>http://blog.mindfock.com/nice-source-codes-from-25-lines-as-contest/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 08:12:08 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Source Code]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=57</guid>
		<description><![CDATA[I missed it by a few days, but the 25-Line ActionScript contest has just ended, and 12 finalists and their works have been put up. All of them are very impressive and cool. Check it out and vote for your favorite! I especially liked these: http://www.25lines.com/finalists/0812/073.swf http://www.25lines.com/finalists/0812/043.swf http://www.25lines.com/finalists/0812/037.swf http://www.25lines.com/finalists/0812/034.swf]]></description>
			<content:encoded><![CDATA[<p>I missed it by a few days, but the <a href="http://www.25lines.com/" target="_blank">25-Line ActionScript</a> contest has just ended, and 12 finalists and their works have been put up. All of them are very impressive and cool. <a href="http://www.25lines.com/?page_id=139" target="_blank">Check it out and vote</a> for your favorite!<br />
I especially liked these:<br />
<a href="http://www.25lines.com/finalists/0812/073.swf" target="_blank">http://www.25lines.com/finalists/0812/073.swf</a><br />
<a href="http://www.25lines.com/finalists/0812/043.swf" target="_blank">http://www.25lines.com/finalists/0812/043.swf</a><br />
<a href="http://www.25lines.com/finalists/0812/037.swf" target="_blank">http://www.25lines.com/finalists/0812/037.swf</a><br />
<a href="http://www.25lines.com/finalists/0812/034.swf" target="_blank">http://www.25lines.com/finalists/0812/034.swf</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/nice-source-codes-from-25-lines-as-contest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionSnippet &#8211; AS3 tips and tricks</title>
		<link>http://blog.mindfock.com/actionsnippet-as3-tips-and-tricks/</link>
		<comments>http://blog.mindfock.com/actionsnippet-as3-tips-and-tricks/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 00:42:52 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=56</guid>
		<description><![CDATA[I&#8217;ve bookmarked this site. You should too! There are some very useful and helpful tips in there. Like the latest one, as of this writing, about simplifying multiple method calls to a graphic (or any) object. From this: mc.graphics.lineStyle(0); mc.graphics.moveTo(10, 10); mc.graphics.lineTo(20,10); //... To this: with (mc.graphics) { lineStyle(0); moveTo(10, 10); lineTo(20,10); //... } Much [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve bookmarked this site. You should too! There are some very useful and helpful tips in there. Like the latest one, as of this writing, about simplifying multiple method calls to a graphic (or any) object.</p>
<p>From this:</p>
<pre class="brush: jscript;">
mc.graphics.lineStyle(0);
mc.graphics.moveTo(10, 10);
mc.graphics.lineTo(20,10);
//...
</pre>
<p>To this:</p>
<pre class="brush: jscript;">
with (mc.graphics) {
    lineStyle(0);
    moveTo(10, 10);
    lineTo(20,10);
    //...
}
</pre>
<p>Much more readable and easier to type. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://actionsnippet.com/" target="_blank">Check it out here and bookmark it.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/actionsnippet-as3-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nifty FPS/CPU monitor class</title>
		<link>http://blog.mindfock.com/nifty-fpscpu-monitor-class/</link>
		<comments>http://blog.mindfock.com/nifty-fpscpu-monitor-class/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 04:19:37 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Classes]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=51</guid>
		<description><![CDATA[I found this little class that displays the framerate of the current movie and the total memory usage of the Flash Player on your movie. It also shows the version of the player and the operating system you are on. It even has a graph. Very useful for monitoring your experiments or whatever.  Link. If [...]]]></description>
			<content:encoded><![CDATA[<p>I found this little class that displays the framerate of the current movie and the total memory usage of the Flash Player on your movie. It also shows the version of the player and the operating system you are on. It even has a graph. Very useful for monitoring your experiments or whatever. </p>
<p><a title="FPSMonitor class" href="http://www.flashfuck.it/2008/05/27/fpsmonitor-for-as3-and-flex-projects/#comment-68" target="_blank">Link.</a></p>
<p>If anyone knows something better, please let me know. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/nifty-fpscpu-monitor-class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple TileBG class</title>
		<link>http://blog.mindfock.com/simple-tilebg-class/</link>
		<comments>http://blog.mindfock.com/simple-tilebg-class/#comments</comments>
		<pubDate>Thu, 05 Jun 2008 08:06:59 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=39</guid>
		<description><![CDATA[Here is another class I made for my site&#8230; It&#8217;s nothing fancy, and in fact it could easily be done without this class, but basically, this class creates a rectangular object and fills it with an image from an outside source, tiles it, and you could easily adjust the width and height of the object, [...]]]></description>
			<content:encoded><![CDATA[<p>Here is another class I made for my site&#8230; It&#8217;s nothing fancy, and in fact it could easily be done without this class, but basically, this class creates a rectangular object and fills it with an image from an outside source, tiles it, and you could easily adjust the width and height of the object, and load a new pattern.<br />
Usage:</p>
<pre class="brush: jscript;">
import com.mindfock.display.TiledBG; //import class
...
tiledBG = new TiledBG(&quot;path/to/pattern.gif&quot;, 800, 600);
addChild(tiledBG);

tiledBG.tileWidth = 500 // change width
tiledBG.tileHeight = 500 // change height

tiledBG.newPattern(&quot;path/to/new/pattern.gif&quot;); //changing pattern image
</pre>
<p><a href="http://blog.mindfock.com/wp-content/uploads/files/TiledBG.as">Download here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/simple-tilebg-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Learn] Timer class in AS 3.0</title>
		<link>http://blog.mindfock.com/learn-timer-class-in-as-30/</link>
		<comments>http://blog.mindfock.com/learn-timer-class-in-as-30/#comments</comments>
		<pubDate>Wed, 14 May 2008 15:49:07 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Learn]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=34</guid>
		<description><![CDATA[It&#8217;s been a while since my last post. My connection has been down for a few days, so I haven&#8217;t got the chance to post. But during this downtime, I found some time to create some experiments in Flash/AS3.0 (maybe I&#8217;ll post it soon). I needed to call a method at timed intervals in this [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since my last post. My connection has been down for a few days, so I haven&#8217;t got the chance to post. But during this downtime, I found some time to create some experiments in Flash/AS3.0 (maybe I&#8217;ll post it soon). I needed to call a method at timed intervals in this one experiment, and I thought I was in trouble. I never got around to getting how AS2.0 handled timers, if I did manage to do timers, they end up dirty.</p>
<p>AS3.0 has a much much better Timer class to handle just such events. Now, I&#8217;m not going to bother comparing the AS3 Timer class with AS2&#8242;s timer handling, I&#8217;m just going to give a quick intro to the class.</p>
<p>First, you need to create a new Timer object. The constructor has 2 parameters, delay and repeatCount. delay is the time in milliseconds the intervals will be. repeatCount is the number of times the Timer will run, assigning it 0 will set it to run infinitely.</p>
<pre class="brush: jscript;">
var myTimer:Timer = new Timer(1000, 5);
</pre>
<p>Now, we want to write a function that will get called when an interval is passed (every 1 second), and when the whole timer finishes counting (after 5 seconds). The Timer class dispatches two events, TimerEvent.TIMER is dispatched when an interval is passed, TimerEvent.TIMER_COMPLETE is dispatched when the timer is finished (I love how simple that is).</p>
<pre class="brush: jscript;">
stage.addEventListener(TimerEvent.TIMER, everySecond);
stage.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);

function everySecond(e:TimerEvent):void{
    trace(&quot;tick tock!&quot;);
}
function onComplete(e:TimerEvent):void{
    trace(&quot;Timer finished!&quot;);
}
</pre>
<p>Now, we just need to start the timer. The Timer class has 3 methods, start, stop, and reset. Those are fairly self-explanatory.  We could now add the following lines:</p>
<pre class="brush: jscript;">
myTimer.start();
//modify the onComplete function
function onComplete(e:TimerEvent):void{
    trace(&quot;Timer finished!&quot;);
    myTimer.reset();
    myTimer.start();
}
</pre>
<p>So now, when our timer finishes, it will automatically start all over again. This will trace</p>
<pre class="brush: jscript;">
tick tock!
tick tock!
tick tock!
tick tock!
tick tock!
Timer finished!
tick tock!
tick tock!
...
</pre>
<p>This was just a really quick intro to the Timer class, I just felt like sharing this because I was so relieved at how easy it was to handle timed events now. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/learn-timer-class-in-as-30/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Read the online documentation!</title>
		<link>http://blog.mindfock.com/read-the-online-documentation/</link>
		<comments>http://blog.mindfock.com/read-the-online-documentation/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 02:13:32 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[Random]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://mindfock.wordpress.com/?p=33</guid>
		<description><![CDATA[Adobe&#8217;s ActionScript online docs that is. This has got to be the best resource you will ever find if you have trouble with ActionScript. I only found that out myself yesterday. I always thought that the online docs, or any other documentation/reference/manual, were scary to look at. Just the sight of all those complicated words [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/">Adobe&#8217;s ActionScript online docs</a> that is. This has got to be the best resource you will ever find if you have trouble with ActionScript. I only found that out myself yesterday. I always thought that the online docs, or any other documentation/reference/manual, were scary to look at. Just the sight of all those complicated words that don&#8217;t seem to mesh together terrifies me. But when I was bored the other day, I decided to just read up on the BitmapData class just for kicks, and as I was reading, I surprisingly understood everything I read! I have never used the BitmapData class before, but I think I&#8217;ll be doing a lot of experiments with it soon (I have seen what others could do with it).</p>
<p>It has been laid out so well, everything is explained thouroughly, with simple and understandable examples and it&#8217;s searchable. It&#8217;s basically one giant tutorial about ActionScript! If there is one, I would love to buy a print/book of the online docs, because I hate reading on the monitor for extended periods of time. And yes, I&#8217;ll be reading the online docs for extended periods of time. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/read-the-online-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Learn] AS2 to AS3 Basic Liquid Layout</title>
		<link>http://blog.mindfock.com/learn-as2-to-as3-basic-liquid-layout/</link>
		<comments>http://blog.mindfock.com/learn-as2-to-as3-basic-liquid-layout/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 01:46:38 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Learn]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://mindfock.wordpress.com/?p=29</guid>
		<description><![CDATA[I was just getting the hang of creating liquid layouts in AS2.0 a few months ago, and boy, is it quite a concept to grasp. Now I have to relearn everything I learned using AS3.0.Thankfully, once I understand the concept, all I have to do now is do it with unfamiliar syntax. In this little [...]]]></description>
			<content:encoded><![CDATA[<p>I was just getting the hang of creating liquid layouts in AS2.0 a few months ago, and boy, is it quite a concept to grasp. Now I have to relearn everything I learned using AS3.0.Thankfully, once I understand the concept, all I have to do now is do it with unfamiliar syntax.</p>
<p>In this little tutorial, I&#8217;ll show AS2 and AS3 code showing the same end result. This is just very basic, just showing the differences between the two (which isn&#8217;t much), and to show how to get started with creating liquid layouts.</p>
<p>By the way, liquid layouts are layouts that change dynamically according the stage&#8217;s size. Not unlike liquid in a container, which takes the container&#8217;s size and shape, thus the name. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>The movie shows 4 boxes I drew on four sides of the stage, changing position according to the stage&#8217;s size. Obviously, you could also adjust other properties of the MovieClip, like scale, alpha, rotation, etc.</p>
<p>First, the AS2.0 code:</p>
<pre class="brush: jscript;">Stage.scaleMode = “noScale”;
Stage.align = “TL”;

setStage();

var stageListener:Object = new Object();

Stage.addListener(stageListener);
stageListener.onResize = function() {
setStage();
};

function setStage() {
var WIDTH:Number = Stage.width;
var HEIGHT:Number = Stage.height;

box1._x = WIDTH-box1._width;
box1._y = HEIGHT/2-(box1._height/2);
box2._x = WIDTH/2 - (box2._width/2);
box2._y = 0;
box3._x = 0;
box3._y = box1._y;
box4._x = box2._x;
box4._y = HEIGHT - box4._height;
}</pre>
<p>AS3.0:</p>
<pre class="brush: jscript;">
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

setStage();

stage.addEventListener(Event.RESIZE, stageResize);

function setStage():void{
var WIDTH:Number = stage.stageWidth;
var HEIGHT:Number = stage.stageHeight;
box1.x = WIDTH - box1.width;
box1.y = HEIGHT/2 - (box1.height/2);
box2.x = WIDTH / 2 - (box2.width/2);
box2.y = 0;
box3.x = 0;
box3.y = box1.y;
box4.x = box2.x;
box4.y = HEIGHT - (box4.height);
}

function stageResize(e:Event):void{
setStage();
}
</pre>
<p>So, there isn&#8217;t really much difference between the two. AS3 is easier to understand because of its better event handling methods.</p>
<p>A little explanation for the 2 codes above, since they are quite similar. The first 2 lines are very important. Basically, they are telling the player to not do anything to objects on the stage when the stage is resized, because we want to control everything that happens when the stage is resized by code. Without those lines, the movie won&#8217;t work as expected.</p>
<p>The setStage() function is pretty self explanatory, it is where we do all the positioning of the movieclips. I like to put all of the code that does the positioning, resizing, etc. work in a function (preferably rolled into one), so I could call it at least once anytime I want. This is useful when initializing the movie, where all the movieclips might not be in their right place. And it is easier to put into the listener function too. You could also do it in the listener function, but I don&#8217;t recommend it.</p>
<p>We then call the setStage() function at least once, to position our movieclips where they should be, because when I created them in Flash, they are pretty much all over the place. If we don&#8217;t call that function, then they&#8217;ll only fall into place when we start resizing the stage.</p>
<p>And now to the part where the two codes are most different. Adding listeners to the stage. In AS3, it is quite straightforward. We add a listener, in this case stageResize() and listen to RESIZE events, to the stage object, which does nothing but call setStage(). You could also add other functions in there if you want to do something else when the stage resizes. In AS2, we have to create a listener object, tell that object to listen for the resizing event and execute the setStage() function. Again, you could add other functions in there.</p>
<p>So, there you have it. A basic Flash liquid layout. I hope this helps anyone who is having a hard time understanding this concept (I know I did). Now, this tutorial only showed changing the position of movieclips, by assigning values to them. But you could also change their position and/or size by percentages. Like 30% of the stage (I know this tutorial shows applying 50% of the stage), so you could adjust the visual elements of your movie to fit any size of resolution properly, at a limit of course.</p>
<p>NOTE: Notice the capital &#8216;S&#8217; in Stage in the AS2 code and the small &#8216;s&#8217; in the AS3 code. Don&#8217;t mess those up!</p>
<p>Here are the source files of this tutorial.</p>
<p><a href="http://www.box.net/shared/zlj8vdsg80">AS2 source (Flash 8 )</a></p>
<p><a href="http://www.box.net/shared/z4i4z3bqck">AS3 source (Flash CS3)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/learn-as2-to-as3-basic-liquid-layout/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>ActionScript cheatsheets</title>
		<link>http://blog.mindfock.com/actionscript-cheatsheets/</link>
		<comments>http://blog.mindfock.com/actionscript-cheatsheets/#comments</comments>
		<pubDate>Sun, 20 Apr 2008 00:53:50 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://mindfock.wordpress.com/?p=27</guid>
		<description><![CDATA[Just got back from a 4 day vacation. Now  I have to  continue my  quest to  scour the internet for  everything  ActionScript. I found this site while reading a few things about tweening classes (I&#8217;ll have a post about that soon. I can&#8217;t believe I haven&#8217;t used them.). ActionScriptCheatSheet.com offers exactly what the title says, [...]]]></description>
			<content:encoded><![CDATA[<p>Just got back from a 4 day vacation. Now  I have to  continue my  quest to  scour the internet for  everything  ActionScript.</p>
<p>I found this site while reading a few things about tweening classes (I&#8217;ll have a post about that soon. I can&#8217;t believe I haven&#8217;t used them.). <a href="http://actionscriptcheatsheet.com/">ActionScriptCheatSheet.com</a> offers exactly what the title says, AS cheatsheets in PDF format. There are about 2 which are in JPEG format, which is a shame, but they are still useful.</p>
<p>They have cheatsheets for the Papervision 3D engine, Apollo specific ones, and AS2 to AS3 migration ones as well. Go to the<a href="http://actionscriptcheatsheet.com/blog/quick-referencecheatsheet-for-actionscript-20"> DOWNLOADS</a> page of the blog to choose your sheet of choice.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/actionscript-cheatsheets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Learn] How to load images/swf&#8217;s in AS3</title>
		<link>http://blog.mindfock.com/learn-how-to-load-imagesswfs-in-as3/</link>
		<comments>http://blog.mindfock.com/learn-how-to-load-imagesswfs-in-as3/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 02:28:41 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Learn]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://mindfock.wordpress.com/?p=23</guid>
		<description><![CDATA[I am in the process of converting from AS2 to AS3 right now, so I am going to try my best to post everything I learn in this blog. It might help others out there who are still also in the process of converting. To those who aren&#8217;t, you should. This time it is about [...]]]></description>
			<content:encoded><![CDATA[<p>I am in the process of converting from AS2 to AS3 right now, so I am going to try my best to post everything I learn in this blog. It might help others out there who are still also in the process of converting. To those who aren&#8217;t, you should. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<p>This time it is about loading external images/swf&#8217;s.</p>
<p>In AS3, there are several types of DisplayObjects you could use to display on the stage (thus the name), along with MovieClips, Sprites(simple movieclips), Bitmaps(for bitmap data) and Loaders.<br />
The Loader object is obviously what we would use to load these external visual data.</p>
<p>Basically, the Loader is just like a MovieClip, since they have a common superclass (well actually MovieClip is derived from Sprite, which is a sibling of Loader). It&#8217;s a like a MovieClip that could load objects. So, if you are coming from AS2, it would make things easier to think of it as just a MovieClip.</p>
<p>So, to load an image named &#8220;image.jpg&#8221;, first you need to create the Loader object. In the first frame of your timeline:</p>
<pre class="brush: jscript;">var loader:Loader = new Loader();</pre>
<p>Now you need the url of the image to load it. The Loader object has a load() method that takes a URLRequest parameter. It&#8217;s just a class that handles url&#8217;s very well. Heh, I don&#8217;t really know much about it, you could read more of it in <a title="URLRequest" href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/URLRequest.html">documentation</a>.</p>
<pre class="brush: jscript;">var imageUrl:URLRequest = new URLRequest(&quot;image.jpg&quot;);</pre>
<p>Now that we have our Loader object and our URLRequest, we could now load our image. It&#8217;s just simply calling the load() method of Loader and passing our URLRequest as argument.</p>
<pre class="brush: jscript;">loader.load(imageUrl);
addChild(loader);</pre>
<p>After loading and adding it to the stage, you could do anything with it as you please.</p>
<pre class="brush: jscript;">loader.x = 50;
loader.alpha = .5;</pre>
<p>Of course, you would want to have preloading for this kind of stuff. And yes, the Loader object generates similar events to the MovieClipLoader object we so loved in AS2. But all this happens very differently in AS3. All the information about the object being loaded is being held by a LoaderInfo object inside the Loader object.</p>
<p>So here is the code that traces the amount of kilobytes loaded adds the Loader object to the stage if loading is completed.</p>
<pre class="brush: jscript;">loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);

function loading(e:Event):void{
trace(loader.contentLoaderInfo.bytesLoaded);
}

function loadComplete(e:Event):void{
trace(&quot;loaded&quot;);
addChild(loader);
}</pre>
<p>Hope this post helps others who are still starting to move to AS3. A lot has changed between the two, but AS3 is definitely the better one.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/learn-how-to-load-imagesswfs-in-as3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Learn] AS2 to AS3 EnterFrame events</title>
		<link>http://blog.mindfock.com/learn-as2-to-as3-enterframe-events/</link>
		<comments>http://blog.mindfock.com/learn-as2-to-as3-enterframe-events/#comments</comments>
		<pubDate>Mon, 14 Apr 2008 14:44:33 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Learn]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[AS2]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://mindfock.wordpress.com/?p=6</guid>
		<description><![CDATA[NOTE: This blog post is inaccurate. I am sorry for the error. I have fixed the error following the comments posted. So in this blog, I&#8217;ll be posting things I learn each day (hopefully), about programming, life, etc. The things I post here might not be completely correct or true, but they are what I [...]]]></description>
			<content:encoded><![CDATA[<p><strong>NOTE: This blog post is inaccurate. I am sorry for the error. I have fixed the error following the comments posted. </strong></p>
<p>So in this blog, I&#8217;ll be posting things I learn each day (hopefully), about programming, life, etc. The things I post here might not be completely correct or true, but they are what I learned and I post them as I understand them. Corrections would be very much appreciated.<br />
I&#8217;ll call it the [Learn] series. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>NOTICE: I am telling this as how I understand it from reading other tutorials on the web. This is possibly very inaccurate, but maybe you could understand things you haven&#8217;t understood before by reading how I understand it. :-/</p>
<p>Event handling in AS3.0 is very different from AS2.0. One of my most used events is onEnterFrame events.</p>
<p>In AS2.0, animating a simple box to move to the right every frame would look like this:<br />
(please bear with me and the unformatted code)</p>
<pre class="brush: jscript;">box.onEnterFrame = function(){
this._x += 1;  //execute this code everytime the box movieclip enters a frame.
}</pre>
<p>but in AS3.0, it is a little longer, and I may still have to see the real benefits of this. But already, I am liking how easy it is to understand.</p>
<pre class="brush: jscript;">function moveBox(e:Event):void{
e.target.x += 1;
}
box.addEventListener(Event.ENTER_FRAME, moveBox);</pre>
<p>the addEventListener method tells the box MovieClip to execute the function moveBox, everytime an ENTER_FRAME event is generated(which is all the time).</p>
<p>Notice the moveBox function has an Event parameter. When a function has an Event type parameter, it becomes a listener function. Passing a non-listener function to the addEventListener method causes an error. You could also add the moveBox listener to any other MovieClip you might have on stage, already one of the benefits of the new event handling of AS3.0.</p>
<p>There are a lot more events to discuss, but I hope this helps those who have just started converting to AS3 (like me). I&#8217;ll keep on posting more things I learn.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/learn-as2-to-as3-enterframe-events/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
