<?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; AS3</title>
	<atom:link href="http://blog.mindfock.com/tag/as3/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>Color Mixer Flex App Updated</title>
		<link>http://blog.mindfock.com/color-mixer-flex-app-updated/</link>
		<comments>http://blog.mindfock.com/color-mixer-flex-app-updated/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 10:14:00 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Art and Design]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Apps]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=68</guid>
		<description><![CDATA[I’ve updated my Color Mixer application. Right now it is as good as done. It’s not the best looking, but all the functionality is working fine. If there are any suggestions on how to improve it, I’d be glad to hear them. I am still working on the AIR version. It’s taking a while figuring [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mindfock.com/experiments/ColorManipulation/ColorMixer.html"><img title="colormixer" style="border-right: 0px; border-top: 0px; display: block; float: none; margin-left: auto; border-left: 0px; margin-right: auto; border-bottom: 0px" height="320" alt="colormixer" src="http://www.mindfock.com/images/001b899971c0_FC7B/colormixer_thumb.jpg" width="320" border="0" /></a> </p>
<p> I’ve updated my Color Mixer application. Right now it is as good as done. It’s not the best looking, but all the functionality is working fine. If there are any suggestions on how to improve it, I’d be glad to hear them. </p>
<p>I am still working on the AIR version. It’s taking a while figuring out how to skin components properly (the gradient sliders clearly show this).&#160; And it seems that taking a screenshot of the desktop is not possible on AIR, which is a shame because I was really looking forward for the feature to take any color on screen. Unless I find a workaround for this, I’m going to have to leave that feature out. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>I hope someone finds this useful, as I know I do. <a title="John&#39;s Color Mixer" href="http://www.mindfock.com/experiments/ColorManipulation/ColorMixer.html">Here it is</a>.</p>
<p>On different note, this post was posted from <a title="Windows Live Writer" href="http://get.live.com/writer/overview" target="_blank">Windows Live Writer</a>. I’m liking it very much. I hope everything displays fine. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/color-mixer-flex-app-updated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RGB to Hexadecimal to HSV conversion in AS3</title>
		<link>http://blog.mindfock.com/rgb-to-hexadecimal-to-hsv-conversion-in-as3/</link>
		<comments>http://blog.mindfock.com/rgb-to-hexadecimal-to-hsv-conversion-in-as3/#comments</comments>
		<pubDate>Sun, 12 Apr 2009 23:19:07 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=65</guid>
		<description><![CDATA[In my previous post, I needed to do a lot of conversion between different representations of color. I think a post on how to convert color would be useful. private function RGBToHex(r:uint, g:uint, b:uint):uint{ var hex:uint = (r &#60;&#60; 16 &#124; g &#60;&#60; 8 &#124; b); return hex; } private function HexToRGB(hex:uint):Array{ var rgb:Array = [...]]]></description>
			<content:encoded><![CDATA[<p>In my previous post, I needed to do a lot of conversion between different representations of color. I think a post on how to convert color would be useful.</p>
<pre class="brush: jscript;">
private function RGBToHex(r:uint, g:uint, b:uint):uint{
    var hex:uint = (r &lt;&lt; 16 | g &lt;&lt; 8 | b);
    return hex;
}

private function HexToRGB(hex:uint):Array{
    var rgb:Array = [];

    var r:uint = hex &gt;&gt; 16 &amp; 0xFF;
    var g:uint = hex &gt;&gt; 8 &amp; 0xFF;
    var b:uint = hex &amp; 0xFF;

    rgb.push(r, g, b);
    return rgb;
}

private function RGBtoHSV(r:uint, g:uint, b:uint):Array{
    var max:uint = Math.max(r, g, b);
    var min:uint = Math.min(r, g, b);

    var hue:Number = 0;
    var saturation:Number = 0;
    var value:Number = 0;

    var hsv:Array = [];

    //get Hue
    if(max == min){
        hue = 0;
    }else if(max == r){
        hue = (60 * (g-b) / (max-min) + 360) % 360;
    }else if(max == g){
        hue = (60 * (b-r) / (max-min) + 120);
    }else if(max == b){
        hue = (60 * (r-g) / (max-min) + 240);
    }

    //get Value
    value = max;

    //get Saturation
    if(max == 0){
        saturation = 0;
    }else{
        saturation = (max - min) / max;
    }

    hsv = [Math.round(hue), Math.round(saturation * 100), Math.round(value / 255 * 100)];
    return hsv;

}

private function HSVtoRGB(h:Number, s:Number, v:Number):Array{
    var r:Number = 0;
    var g:Number = 0;
    var b:Number = 0;
    var rgb:Array = [];

    var tempS:Number = s / 100;
    var tempV:Number = v / 100;

    var hi:int = Math.floor(h/60) % 6;
    var f:Number = h/60 - Math.floor(h/60);
    var p:Number = (tempV * (1 - tempS));
    var q:Number = (tempV * (1 - f * tempS));
    var t:Number = (tempV * (1 - (1 - f) * tempS));

    switch(hi){
        case 0: r = tempV; g = t; b = p; break;
        case 1: r = q; g = tempV; b = p; break;
        case 2: r = p; g = tempV; b = t; break;
        case 3: r = p; g = q; b = tempV; break;
        case 4: r = t; g = p; b = tempV; break;
        case 5: r = tempV; g = p; b = q; break;
    }

    rgb = [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
    return rgb;
}
</pre>
<p>The code above requires and returns:</p>
<ul>
<li>RGB values between 0 to 255</li>
<li>Hexadecimal in RRGGBB format</li>
<li>Hue values between 0 to 360</li>
<li>Saturation and Value between 0 to 100</li>
</ul>
<p>Notice that the &#8220;middleman&#8221; is RGB. </p>
<p>And, just in case you only have the Hexadecimal string to work with, here is the code to convert that string into a usable decimal value.</p>
<pre class="brush: jscript;">
private function HexToDeci(hex:String):uint{
	var deci:uint = 0;
	var power:uint = hex.length - 1;
	for(var i:uint = 0; i &lt; hex.length; i++){
		var char:String = hex.charAt(i);
		if(parseInt(char) &gt;= 0 &amp;&amp;  parseInt(char) &lt;= 9){
			deci += parseInt(char) * Math.pow(16, power);
		}else{
			switch(char){
				case &quot;A&quot;: case &quot;a&quot;:	deci += 10 * Math.pow(16, power); break;
				case &quot;B&quot;: case &quot;b&quot;:	deci += 11 * Math.pow(16, power); break;
				case &quot;C&quot;: case &quot;c&quot;:	deci += 12 * Math.pow(16, power); break;
				case &quot;D&quot;: case &quot;d&quot;:	deci += 13 * Math.pow(16, power); break;
				case &quot;E&quot;: case &quot;e&quot;:	deci += 14 * Math.pow(16, power); break;
				case &quot;F&quot;: case &quot;f&quot;:	deci += 15 * Math.pow(16, power); break;
			}
		}

		power --;
	}
	return deci;
}
</pre>
<p>EDIT: I&#8217;ve just gathered that there is a much much simpler way to convert a Hexadecimal string into a usable number. I feel kind of stupid right now. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  </p>
<pre class="brush: jscript;">
private function HexToDeci(hex:String):uint{
        if (hex.substr(0, 2) != &quot;0x&quot;) {
                hex = &quot;0x&quot; + hex;
        }
        return new uint(hex);
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/rgb-to-hexadecimal-to-hsv-conversion-in-as3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Metaballs update</title>
		<link>http://blog.mindfock.com/metaballs-update/</link>
		<comments>http://blog.mindfock.com/metaballs-update/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 01:32:46 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=61</guid>
		<description><![CDATA[Still delving into metaballs. I implemented the suggestions in this page for optimizing, and the results are good. I could even animate it &#8211; just barely though, at ~15 FPS on my browser.  Again, most of this is just copy &#38; paste from the source provided in the tutorial. Metaballs &#8211; move your mouse around. [...]]]></description>
			<content:encoded><![CDATA[<p>Still delving into metaballs. I implemented the suggestions in this <a href="http://www.gamedev.net/reference/programming/features/isometa2d/page4.asp" target="_blank">page</a> for optimizing, and the results are good. I could even animate it &#8211; just barely though, at ~15 FPS on my browser. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   Again, most of this is just copy &amp; paste from the <a href="http://www.gamedev.net/reference/programming/features/isometa2d/page5.asp" target="_blank">source</a> provided in the <a href="http://www.gamedev.net/reference/programming/features/isometa2d/" target="_blank">tutorial</a>.</p>
<p><a href="http://www.mindfock.com/experiments/Metaballs/bin/Metaballs-updated.html" target="_self">Metaballs</a> &#8211; move your mouse around.  Click to change the target ball.</p>
<p>Still looking for a more elegant solution for Flash. This is done on a very small stage size, with only 4 balls. I want to do a full screen version, with at least 10 balls moving around. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/metaballs-update/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RGB seperation test</title>
		<link>http://blog.mindfock.com/rgb-seperation-test/</link>
		<comments>http://blog.mindfock.com/rgb-seperation-test/#comments</comments>
		<pubDate>Sat, 27 Dec 2008 08:51:37 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Experiments]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=58</guid>
		<description><![CDATA[After seeing a cool demo from the ClockMaker blog, I was inspired to try and recreate the effect. My attempt is not very impressive, but I did manage to figure out how he did it. Although much of this is from his sourcecode, I just thought I&#8217;d post a simplified version and put little comments [...]]]></description>
			<content:encoded><![CDATA[<p>After seeing a <a href="http://clockmaker.jp/blog-en/2008/11/rgb-image-separater-with-papervision3d/#more-111" target="_blank">cool demo</a> from the <a href="http://clockmaker.jp/blog-en/" target="_blank">ClockMaker blog</a>, I was inspired to try and recreate the effect. My attempt is not very impressive, but I did manage to figure out how he did it. Although much of this is from his sourcecode, I just thought I&#8217;d post a simplified version and put little comments and stuff.</p>
<p>And oh, Merry Christmas to all! <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Click the image to see the movie.</p>
<p><a href="http://www.mindfock.com/experiments/ColorSeperate/bin/ColorSeperate.html"><img src="http://www.mindfock.com/experiments/ColorSeperate/turtle.png" alt="" width="320" height="240" /></a></p>
<p><a href="http://www.mindfock.com/experiments/ColorSeperate/src/Main.as">Source.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/rgb-seperation-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Learn] A &#8220;pixelating&#8221; effect on a Bitmap</title>
		<link>http://blog.mindfock.com/learn-a-pixelating-effect-on-a-bitmap/</link>
		<comments>http://blog.mindfock.com/learn-a-pixelating-effect-on-a-bitmap/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 14:19:03 +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[AS3]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=44</guid>
		<description><![CDATA[I did a little experimenting with the BitmapData class, and came up with this. I found this effect from a gallery somewhere, and thought it would be cool to try my hand at it, for learning purposes. Click on the image below to see the effect. 
<object	type="application/x-shockwave-flash"
			data="http://www.mindfock.com/blog/wp-content/uploads/2008/06/pixelate.swf"
			width="300"
			height="225">
	<param name="movie" value="http://www.mindfock.com/blog/wp-content/uploads/2008/06/pixelate.swf" />
</object> What&#8217;s happening is, I [...]]]></description>
			<content:encoded><![CDATA[<p>I did a little experimenting with the BitmapData class, and came up with this.<br />
I found this effect from a gallery somewhere, and thought it would be cool to try my hand at it, for learning purposes.</p>
<p>Click on the image below to see the effect.</p>

<object	type="application/x-shockwave-flash"
			data="http://www.mindfock.com/blog/wp-content/uploads/2008/06/pixelate.swf"
			width="300"
			height="225">
	<param name="movie" value="http://www.mindfock.com/blog/wp-content/uploads/2008/06/pixelate.swf" />
</object>
<p>What&#8217;s happening is, I get the size of the image, divide it by the size of the &#8220;pixels&#8221; I want, then create an array of Rectangles positioned in a grid over the image.<br />
I then fill each Rectangle with the color of the pixel in it&#8217;s center by using the getPixel() and fillRect() methods of the BitmapData class.<br />
Here is the central function doing the pixelating.</p>
<pre class="brush: jscript;">
private function pixelate(bitmap:Bitmap, strength:Number):void {
var _x:int = 0; // position of the rectangle
var _y:int = 0;
if (strength &gt; 1){
_strength = 1;
}
var _strength:Number = strength; // multiplier for size of &quot;pixels&quot;

var _w:Number = bitmap.bitmapData.width * _strength; //size of &quot;pixels&quot;
var _h:Number = bitmap.bitmapData.height * _strength;

var nH:int = Math.ceil(bitmap.bitmapData.width / _w); // number of rectangles needed horizontally
var nV:int = Math.ceil(bitmap.bitmapData.height / _h);// number of rectangles needed vertically

var rectangles:Array = []; // Rectangles array

//create rectangles
for (var i:int = 0; i &lt; nV; i ++){
var targH:Number = _h;
if (i &gt;= nV - 1){
targH = bitmap.bitmapData.height - _y;
}
for (var j:int = 0; j &lt; nH; j ++){
var targW:Number = _w;
if (j &gt;= nH - 1){
targW = bitmap.bitmapData.width - _x;
}
rectangles.push(new Rectangle(_x, _y, targW, targH));
_x += _w;
}
_x = 0;
_y += _h;

}
//fill in rectangles
for (i = 0; i &lt; rectangles.length; i++){

var rect:Rectangle = rectangles[i];
var pix:uint = _states[0].getPixel((rect.x + rect.width / 2), (rect.y + rect.height / 2));
bitmap.bitmapData.fillRect(rect, pix);
}

saveCurrentState(bitmap.bitmapData);

}
</pre>
<p>Now for the reverting to the original image part, I had to improvise. Since I overwrote the BitmapData with a bunch of filled rectangles, I couldn&#8217;t do much with it.<br />
So I used an array which stores each &#8220;state&#8221; the BitmapData is in. And I could just retrieve the BitmapData in the array and copy it into the original BitmapData.</p>
<pre class="brush: jscript;">
private function saveCurrentState(bitmapData:BitmapData):void {
_states.push(bitmapData.clone());
}
private function revertToState(stage:int):void {
try{
bmData.copyPixels(_states[stage], bmData.rect, new Point(bmData.rect.x, bmData.rect.y));
}catch (e:Error){
throw new Error(&quot;Invalid state. &quot;);
}
}
</pre>
<p>To create the animation, I just called the pixelate() function through a Timer at 300 milliseconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/learn-a-pixelating-effect-on-a-bitmap/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Slideshow on ActionScript 3</title>
		<link>http://blog.mindfock.com/slideshow-on-actionscript-3/</link>
		<comments>http://blog.mindfock.com/slideshow-on-actionscript-3/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 00:53:11 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=43</guid>
		<description><![CDATA[Just found this great resource for learning AS3. It is a slideshow created by Grant Skinner showing the basics of the language and some optimization tips. Each page worth an article itself, all 167 of them. It not only sounds good, it looks good. http://gskinner.com/talks/as3workshop/]]></description>
			<content:encoded><![CDATA[<p>Just found this great resource for learning AS3. It is a slideshow created by <a title="gskinner blog" href="http://gskinner.com/blog/">Grant Skinner</a> showing the basics of the language and some optimization tips. Each page worth an article itself, all 167 of them. It not only sounds good, it looks good. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>http://gskinner.com/talks/as3workshop/</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/slideshow-on-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A little heads-up about the Flash Player 9 Garbage Collector</title>
		<link>http://blog.mindfock.com/a-little-heads-up-about-the-flash-player-9-garbage-collector/</link>
		<comments>http://blog.mindfock.com/a-little-heads-up-about-the-flash-player-9-garbage-collector/#comments</comments>
		<pubDate>Fri, 27 Jun 2008 13:01:22 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Programming and Development]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=42</guid>
		<description><![CDATA[I want to give a heads-up to all those just beginning with AS3 about how it handles memory. I had to find out about this the hard way, and now have to redo a lot of stuff. Flash Player 9 introduced a new system management feature called a garbage collector (GC). Basically, what it does [...]]]></description>
			<content:encoded><![CDATA[<p>I want to give a heads-up to all those just beginning with AS3 about how it handles memory. I had to find out about this the hard way, and now have to redo a lot of stuff.</p>
<p>Flash Player 9 introduced a new system management feature called a garbage collector (GC). Basically, what it does is &#8220;sweep&#8221; for objects that can not be used/accessed anymore, and delete them, freeing memory. Until those &#8216;null&#8217; objects are removed by the GC, they will sit in memory until the Player is closed.</p>
<p>So, whenever you want something to be deleted (escpecially with CPU intensive particle systems), you must be aware of what and where you are referencing your objects, so you could easily remove them.  You have to do this by hand. One method is to set all objects you want to delete, and all references to it,  to null. Even then, you have to wait for the GC to do its &#8220;sweeping motion&#8221; for those objects to be deleted.</p>
<p>Another thing to watch out for are event listeners. Make sure you remove any listeners (by calling removeEventListener()) from objects you want to delete, since they also hold a reference to your objects.</p>
<p>Check this <a href="http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html">article series for more details and info about the GC and resource management in Flash Player 9/AS3.</a></p>
<p>And lastly, it is about unloading external swf&#8217;s through Loader. You might think that using unload() from a Loader would remove that swf completely, but that isn&#8217;t the case.  In fact, unload() does a pretty poor job at &#8220;unloading&#8221; swfs. Here is a quote from another <a href="http://www.gskinner.com/blog/archives/2008/04/failure_to_unlo.html">article</a> that explains this in great detail:</p>
<blockquote><p>In AS3, calling Loader.unload() simply removes the reference to the loaded movie. If any other references exist to the loaded content, it will not be unloaded.</p></blockquote>
<p>My site has been delayed by almost a month now, trying to figure out and fix my memory leak problem. I finally have an idea of what&#8217;s wrong, now I have to figure out a solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/a-little-heads-up-about-the-flash-player-9-garbage-collector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Learn] Using TweenLite</title>
		<link>http://blog.mindfock.com/learn-using-tweenlite/</link>
		<comments>http://blog.mindfock.com/learn-using-tweenlite/#comments</comments>
		<pubDate>Sat, 14 Jun 2008 15:18:12 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Engines]]></category>
		<category><![CDATA[Learn]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=41</guid>
		<description><![CDATA[TweenLite is a light-weight tweening engine for AS2 and AS3. Tweening engines make animating objects through code a breeze. Instead of figuring out how to get to a certain point or value of an object&#8217;s property, all you need to do is figure out where you want that property to be (or where you want [...]]]></description>
			<content:encoded><![CDATA[<p><a title="TweenLite for AS2" href="http://www.tweenlite.com/" target="_blank">TweenLite</a> is a light-weight tweening engine for AS2 and AS3.</p>
<p>Tweening engines make animating objects through code a breeze. Instead of figuring out how to get to a certain point or value of an object&#8217;s property, all you need to do is figure out where you want that property to be (or where you want it to come from), the time it takes to get there, and you have movement.</p>
<p>There are a lot of tweening engines out there, but I prefer TweenLite because it is light (only 3kb), it is easy to use, does what I want it to do, and if I want more functionality, it has two older brothers*.</p>
<p>To get started, first you need to download TweenLite (I&#8217;ll be discussing the <a title="TweenLite for AS3" href="http://blog.greensock.com/tweenfilterliteas3/" target="_blank">AS3 version</a> here), and save it into your classpath.</p>
<p>There are 2 static methods you need to know, TweenLite.to() and TweenLite.from().</p>
<p>Those two methods take in three arguments:</p>
<ul>
<li>The object you want to animate</li>
<li>The time, in seconds, the animation will span</li>
<li>A dynamic Object instance target with predefined properties (this is where you put the values you want to reach)</li>
</ul>
<p>So, to animate a box, it only takes one line to make it do some crazy stuff.</p>
<pre class="brush: jscript;">
import gs.TweenLite; // import TweenLite

box_mc.x = 0;
box_mc.y = 100;

TweenLite.to(box_mc, 2, {x: stage.stageWidth, y: 200, rotation: 360, scaleX: 2, scaleY:2, alpha: .5});
//this will move the box to the edge of the stage, move it down 100 px, rotate it, scale it to 2x its
//size, and make it transparent, for 2 seconds.
</pre>
<p>Note that the TweenLite.from() method does the exact opposite of TweenLite.to(). It transforms your object to your third argument properties, and animates them towards the state the object has on the stage (very useful).<br />
There are comments in the .as file itself, and explains some important things. This was to show how useful and indispensible tweening engines are. I can&#8217;t beleive how long I&#8217;ve strayed away from them, but now, I can&#8217;t live without them. </p>
<p>*<a href="http://www.tweenfilterlite.com/">TweenFilterLite</a> &#8211; TweenLite + filtering capabilities<br />
 <a href="http://blog.greensock.com/tweenmaxas3/">TweenMax</a> &#8211; TweenFilterLite + bezier curves</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/learn-using-tweenlite/feed/</wfw:commentRss>
		<slash:comments>4</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>Shuffler class</title>
		<link>http://blog.mindfock.com/shuffler-class/</link>
		<comments>http://blog.mindfock.com/shuffler-class/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 10:52:30 +0000</pubDate>
		<dc:creator>John del Rosario</dc:creator>
				<category><![CDATA[AS 3.0]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Classes]]></category>
		<category><![CDATA[Experiments]]></category>

		<guid isPermaLink="false">http://blog.mindfock.com/?p=38</guid>
		<description><![CDATA[I&#8217;ve been working on my site for a few weeks now, and I have developed a class that will handle how I display assets on my site. Basically, it &#8220;throws&#8221; in items into the stage, and you could shuffle them around or you could stack them up. I&#8217;ve made it very easy to use, and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on my site for a few weeks now, and I have developed a class that will handle how I display assets on my site.</p>
<p>Basically, it &#8220;throws&#8221; in items into the stage, and you could shuffle them around or you could stack them up. I&#8217;ve made it very easy to use, and it&#8217;s still under development, but I think it&#8217;s ready to be used by others. This is my first class I&#8217;ve ever shared, and though it&#8217;s not much, I hope someone likes it or maybe even use it. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>You can use any DisplayObject as the &#8216;items&#8217; of the Shuffler.<br />
There are explanations in the code, but here are some important points</p>
<ul>
<li> shuffle() &#8211; shuffles the items</li>
<li>stack() &#8211; stacks the items</li>
<li>setFocusOn(item:DisplayObject) &#8211; sets the item param as the focused item</li>
<li>addItem(item:DisplayObject) &#8211; adds item param to the shuffler</li>
<li>deleteItem(index:int) &#8211; deletes the item at index</li>
<li>has max property for maximum number of boxes allowed. 0 for infinite.</li>
</ul>
<ul></ul>
<p>Here is an example:<br />

<object	type="application/x-shockwave-flash"
			data="http://www.mindfock.com/experiments/TestShuffler.swf"
			width="400"
			height="300">
	<param name="movie" value="http://www.mindfock.com/experiments/TestShuffler.swf" />
</object>
<p>Sample usage in code:</p>
<pre class="brush: jscript;">
package{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.*;
	import flash.text.TextField;
	import com.mindfock.ui.Shuffler;

	public class TestShuffler extends Sprite{
		private var boxes:Array;
		private var shuffler:Shuffler;
		private var stacker:TextField;
		private var shuffle:TextField;
		private var adder:TextField;

		public function TestShuffler(){
			init();
		}
		public function init():void{
			shuffler = new Shuffler(400, 300, 6);
			createBoxes(6);
			createButtons();
			addChild(shuffler);
		}
		private function createBoxes(num:int):void{
			boxes = new Array();
			for (var i:int = 0; i &lt; num; i++)
			{
				trace(&quot;created&quot;);
				var box:Sprite = drawBox(50, 50) as Sprite;

				boxes.push(box);

				shuffler.addItem(box);
			}
		}
		private function drawBox(w:Number, h:Number):DisplayObject{
			var box:Sprite = new Sprite();
			box.graphics.lineStyle(2, 0x000000);
			box.graphics.beginFill(Math.random() * 16000000);
			box.graphics.drawRect(0, 0, 100, 100);
			box.graphics.endFill();

			return box;
		}
		private function createButtons():void
		{
			// I've left out the drawing of the buttons
			square.addEventListener(MouseEvent.CLICK, shuffleHandler);
			square2.addEventListener(MouseEvent.CLICK, stackHandler);
			square3.addEventListener(MouseEvent.CLICK, addHandler);
		}
		private function shuffleHandler(event:MouseEvent):void{
			shuffler.shuffle();
		}
		private function stackHandler(event:MouseEvent):void{
			shuffler.stack();
		}
		private function addHandler(event:MouseEvent):void{
			var newBox:Sprite = drawBox(50, 50) as Sprite;
			shuffler.addItem(newBox);
		}
	}
}
</pre>
<p><a title="Shuffler class" href="http://www.mindfock.com/classes/Shuffler.as">Download source</a></p>
<p>Just save it in your classpath, under com/mindfock/ui</p>
<p>You need <a title="TweenLite" href="http://blog.greensock.com/tweenliteas3/">TweenLite</a> for the tweening animations&#8230; If you don&#8217;t know what it is, you should look into tweening engines. They will save you a lot of hard work.</p>
<p>Now that I&#8217;ve got the main bulk of my site done, I hope I can finish it before classes start. <img src='http://blog.mindfock.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.mindfock.com/shuffler-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
