<?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>Flassari.is &#187; AS3</title>
	<atom:link href="http://flassari.is/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://flassari.is</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Mon, 19 Jul 2010 16:09:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Re-dispatch an event</title>
		<link>http://flassari.is/2010/07/re-dispatch-an-event/</link>
		<comments>http://flassari.is/2010/07/re-dispatch-an-event/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 16:09:38 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[dispatch]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[re-dispatch]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=331</guid>
		<description><![CDATA[I just stumbled upon a sexy and simple way to forward an Event that I wanted to share with you:
myEventDispatcher.addEventListener("someEvent", dispatchEvent);
]]></description>
			<content:encoded><![CDATA[<p>I just stumbled upon a sexy and simple way to forward an Event that I wanted to share with you:</p>
<pre class="brush: as3">myEventDispatcher.addEventListener("someEvent", dispatchEvent);</pre>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2010/07/re-dispatch-an-event/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AS3 &#8220;with&#8221; keyword and casting</title>
		<link>http://flassari.is/2010/07/as3-with-keyword-and-casting/</link>
		<comments>http://flassari.is/2010/07/as3-with-keyword-and-casting/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 13:40:40 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[cast]]></category>
		<category><![CDATA[casting]]></category>
		<category><![CDATA[keyword]]></category>
		<category><![CDATA[with]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=321</guid>
		<description><![CDATA[I&#8217;ve rarely (if ever) used the &#8220;with&#8221; keyword in as3, but I recently found a neat trick to use it with.
When I quickly need to cast an object to access a few methods/properties I don&#8217;t always want to
create a new casted variable:
var child:DisplayObject = getChildThatMightBeMovieClip();

if (child is MovieClip) {
	var childAsMc:MovieClip = child as MovieClip;
	trace(childAsMc.numChildren);
	trace(childAsMc.currentFrame);
}
or cast [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve rarely (if ever) used the <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/statements.html#with">&#8220;with&#8221; keyword</a> in as3, but I recently found a neat trick to use it with.</p>
<p>When I quickly need to cast an object to access a few methods/properties I don&#8217;t always want to<br />
create a new casted variable:</p>
<pre class="brush: as3">var child:DisplayObject = getChildThatMightBeMovieClip();

if (child is MovieClip) {
	var childAsMc:MovieClip = child as MovieClip;
	trace(childAsMc.numChildren);
	trace(childAsMc.currentFrame);
}</pre>
<p>or cast it every single time:</p>
<pre class="brush: as3">var child:DisplayObject = getChildThatMightBeMovieClip();

if (child is MovieClip) {
	trace((child as MovieClip).numChildren);
	trace((child as MovieClip).currentFrame);
}</pre>
<p>Using the &#8220;with&#8221; keyword, we can temporarily cast it without creating a temporary casted variable or casting it again and again:</p>
<pre class="brush: as3">var child:DisplayObject = getChildThatMightBeMovieClip();

if (child is MovieClip) {
	with (child as MovieClip) {
		trace(numChildren);
		trace(currentFrame);
	}
}</pre>
<p>Elegant =)</p>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2010/07/as3-with-keyword-and-casting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Global error handling with Flash Player 10.1</title>
		<link>http://flassari.is/2010/06/global-error-handling-with-flash-player-10-1/</link>
		<comments>http://flassari.is/2010/06/global-error-handling-with-flash-player-10-1/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 12:25:44 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[10.1]]></category>
		<category><![CDATA[4.1]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[global]]></category>
		<category><![CDATA[handler]]></category>
		<category><![CDATA[handling]]></category>
		<category><![CDATA[player]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[uncaught]]></category>
		<category><![CDATA[uncaughtError]]></category>
		<category><![CDATA[uncaughterrorhandler]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=303</guid>
		<description><![CDATA[Since the official release of Flash Player 10.1 is out, now might be a good time to start implementing the global error handler.

When this is written, flash builder 4 doesn't have a native way that lets you use it, so we have to do a little mix.
The global error handler works by adding an event to the uncaughtErrorEvents property of the loaderInfo of the application.
There are currently two methods of getting it to work [...]]]></description>
			<content:encoded><![CDATA[<p>Since the official release of Flash Player 10.1 is out, now might be a good time to start implementing the global error handler.</p>
<p>When this is written, flash builder 4 doesn&#8217;t have a native way that lets you use it, so we have to do a little mix.<strong> (Update: The update is out.)</strong><br />
The global error handler works by adding an event to the uncaughtErrorEvents property of the loaderInfo of the application.<br />
There are currently two methods of getting it to work.</p>
<h3>Method 1 - The backwards compatible one:</h3>
<p>Here the code doesn&#8217;t crash in flash player 9/10, but the error handling will only work in 10.1.</p>
<pre class="brush: as3">if(loaderInfo.hasOwnProperty("uncaughtErrorEvents")){
	IEventDispatcher(loaderInfo["uncaughtErrorEvents"]) .addEventListener("uncaughtError", uncaughtErrorHandler);
}</pre>
<pre class="brush: as3">private function uncaughtErrorHandler(e:Event):void {
	trace("Global error:", e);
}</pre>
<h3>Method 2 - The type safe one:</h3>
<p>Get the <a href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+4">Flex 4.1 SDK</a> if you haven&#8217;t already and choose that one as your project&#8217;s SDK.</p>
<p>Now you can use the new global error handling like it was meant to be used:</p>
<pre class="brush: as3">import flash.events.UncaughtErrorEvent;

loaderInfo.uncaughtErrorEvents.addEventListener( UncaughtErrorEvent.UNCAUGHT_ERROR, uncaughtErrorHandler);

private function uncaughtErrorHandler( e:UncaughtErrorEvent):void {
	trace("Global error:", e);
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2010/06/global-error-handling-with-flash-player-10-1/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Color.setTint() alternative (AS3)</title>
		<link>http://flassari.is/2010/02/color-settint-alternative/</link>
		<comments>http://flassari.is/2010/02/color-settint-alternative/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 15:49:24 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[alternative]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[color]]></category>
		<category><![CDATA[colortransform]]></category>
		<category><![CDATA[multiplier]]></category>
		<category><![CDATA[setTint]]></category>
		<category><![CDATA[source]]></category>
		<category><![CDATA[tint]]></category>
		<category><![CDATA[transform]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=266</guid>
		<description><![CDATA[I once discovered a really cool feature of the color class that lets you set the tint of an object via its color transform object using the setTint function.
The bad news though is that it is in the fl namespace, so if you're developing outside of the Flash IDE you have no access to that class natively, so here is how to replicate that functionality without the Color class [...]]]></description>
			<content:encoded><![CDATA[<p>I once discovered a really cool feature of the color class that lets you set the tint of an object via its color transform object using the setTint function.<br />
The bad news though is that the Color class is in the <strong>fl</strong> namespace, so if you&#8217;re developing outside of the Flash IDE you have no access to that class natively, so here is how to replicate that functionality without the Color class:</p>
<p>Tinting with the color class:</p>
<pre class="brush: as3">import fl.motion.Color;
// Tint the movie clip 50% with the color 0xFF9933
var c:Color = new Color();
c.setTint(0xFF9933, 0.5);
myMovieClip.transform.colorTransform = c;</pre>
<p>Tinting without the color class:</p>
<pre class="brush: as3">import flash.geom.ColorTransform;

// Tint the movie clip 50% with the color 0xFF9933
var tintColor:uint = 0xFF9933;
var tintMultiplier:Number = 0.5;
setTint(myMovieClip, tintColor, tintMultiplier);

function setTint(displayObject:DisplayObject, tintColor:uint, tintMultiplier:Number):void {
	var colTransform:ColorTransform = new ColorTransform();
	colTransform.redMultiplier = colTransform.greenMultiplier = colTransform.blueMultiplier = 1-tintMultiplier;
	colTransform.redOffset = Math.round(((tintColor &#038; 0xFF0000) >> 16) * tintMultiplier);
	colTransform.greenOffset = Math.round(((tintColor &#038; 0x00FF00) >> 8) * tintMultiplier);
	colTransform.blueOffset = Math.round(((tintColor &#038; 0x0000FF)) * tintMultiplier);
	displayObject.transform.colorTransform = colTransform;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2010/02/color-settint-alternative/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pie mask in AS3</title>
		<link>http://flassari.is/2009/11/pie-mask-in-as3/</link>
		<comments>http://flassari.is/2009/11/pie-mask-in-as3/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 17:02:17 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Math]]></category>
		<category><![CDATA[mask]]></category>
		<category><![CDATA[percentage]]></category>
		<category><![CDATA[pie]]></category>
		<category><![CDATA[progress]]></category>
		<category><![CDATA[timer]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=240</guid>
		<description><![CDATA[Sometimes I have the need for a rotational progress bar that acts like a pie growing bigger (or smaller if that strikes your fancy). As usual, I made my own =) [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I have the need for a rotational progress bar that acts like a pie growing bigger (or smaller if that strikes your fancy). As usual, I made my own =)<br />
The function drawPieMask takes first the <strong>graphics</strong> object of the displayObject instance and draws a part of pie on it, <strong>percentage</strong> set&#8217;s how big the part is.<br />
If you want to offset the rotation of the pie (it starts to the right by default) you can set the <strong>rotation</strong> parameter. Note that rotation is in radians, not degrees, but you can multiply your degrees by (Math.PI/180) to convert to radians.<br />
Lastly, the <strong>sides</strong> property determines how many sides the circle drawn in the mask has. You can see an example of different pie masks after the code.</p>
<p>To make the code as customizable as possible, it does not make a call to beginFill in case you want to set your own fill (or gradientfill even?).<br />
If you just want to use it as a basic mask, just call beginFill(0) before and endFill() after the call to drawPieMask.</p>
<pre class="brush: as3">function drawPieMask(graphics:Graphics, percentage:Number, radius:Number = 50, x:Number = 0, y:Number = 0, rotation:Number = 0, sides:int = 6):void {
	// graphics should have its beginFill function already called by now
	graphics.moveTo(x, y);
	if (sides < 3) sides = 3; // 3 sides minimum
	// Increase the length of the radius to cover the whole target
	radius /= Math.cos(1/sides * Math.PI);
	// Shortcut function
	var lineToRadians:Function = function(rads:Number):void {
		graphics.lineTo(Math.cos(rads) * radius + x, Math.sin(rads) * radius + y);
	};
	// Find how many sides we have to draw
	var sidesToDraw:int = Math.floor(percentage * sides);
	for (var i:int = 0; i <= sidesToDraw; i++)
		lineToRadians((i / sides) * (Math.PI * 2) + rotation);
	// Draw the last fractioned side
	if (percentage * sides != sidesToDraw)
		lineToRadians(percentage * (Math.PI * 2) + rotation);
}</pre>
<p>Example of different sides values. The last circle has a pie with 3 sides as a mask.<br />
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="450" height="310"><param name="movie" value="/wp-content/uploads/2009/11/PieMaskExample.swf" /><!--[if !IE]>--><object type="application/x-shockwave-flash" data="/wp-content/uploads/2009/11/PieMaskExample.swf" width="450" height="310"><!--<![endif]-->
<div>
<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
<p><!--[if !IE]>--></object><!--<![endif]--></object></p>
<p>You can get the <a href='http://flassari.is/wp-content/uploads/2009/11/PieMaskExample.zip'>example fla here.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2009/11/pie-mask-in-as3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Profiling AS3/Flex applications</title>
		<link>http://flassari.is/2009/10/profiling-as3flex-applications/</link>
		<comments>http://flassari.is/2009/10/profiling-as3flex-applications/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 12:22:14 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Adobe TV]]></category>
		<category><![CDATA[builder]]></category>
		<category><![CDATA[Jun Heider]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[profiler]]></category>
		<category><![CDATA[profiling]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=185</guid>
		<description><![CDATA[I'm working on a big project and had some problems with memory leaks. After some google-ing around I found this great video on AdobeTV by Jun Heider where he shows you how to profile memory and performance [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a big project and was having some problems with memory leaks. After some google-ing around I found this great video on <a href="http://tv.adobe.com/watch/360flex-conference/using-the-flex-builder-3-profiler-by-jun-heider/">AdobeTV</a> by <a href="http://www.iheartair.com/">Jun Heider</a> where he shows you how to profile both the memory and performance of your AS3 or Flex application.<br />
It&#8217;s pretty thorough and it is little over one hour in length.</p>
<p><object width="425" height="256"><param name="movie" value="http://images.tv.adobe.com//swf/player.swf"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="FlashVars" value="fileID=2165&#038;context=141&#038;embeded=true&#038;environment=production"></param><embed src="http://images.tv.adobe.com//swf/player.swf" flashvars="fileID=2165&#038;context=141&#038;embeded=true&#038;environment=production" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="256"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2009/10/profiling-as3flex-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Number Format - Thousand Separator in AS3</title>
		<link>http://flassari.is/2009/08/number-format-thousand-separator-in-as3/</link>
		<comments>http://flassari.is/2009/08/number-format-thousand-separator-in-as3/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 21:25:36 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[currency]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[number]]></category>
		<category><![CDATA[quick]]></category>
		<category><![CDATA[separator]]></category>
		<category><![CDATA[short]]></category>
		<category><![CDATA[thousand]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=166</guid>
		<description><![CDATA[I needed a quick function to do some number formatting for me: to seperate thousands by commas. It's unbelievable that there are no short functions out there (easily searchable), so I wrote my own and hope you'll enjoy [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a short number format function I wrote to easily paste in your code when needed. It&#8217;s really handy for currency formatting.<br />
The first parameter (number:*) can be a Number, int, uint or a String class instance.<br />
The last parameter (siStyle:Boolean) specifies whether to use the <a href="http://en.wikipedia.org/wiki/SI" target="_blank">International System of Units</a> or not. <a href="http://en.wikipedia.org/wiki/SI" target="_blank">SI units</a> have points between the thousands and a comma for the seperator (123.456.789,01). Putting siStyle as false reverses that behaviour (123,456,789.01).</p>
<pre class="brush: as">function numberFormat(number:*, maxDecimals:int = 2, forceDecimals:Boolean = false, siStyle:Boolean = true):String {
    var i:int = 0, inc:Number = Math.pow(10, maxDecimals), str:String = String(Math.round(inc * Number(number))/inc);
    var hasSep:Boolean = str.indexOf(".") == -1, sep:int = hasSep ? str.length : str.indexOf(".");
    var ret:String = (hasSep &#038;&#038; !forceDecimals ? "" : (siStyle ? "," : ".")) + str.substr(sep+1);
    if (forceDecimals) for (var j:int = 0; j <= maxDecimals - (str.length - (hasSep ? sep-1 : sep)); j++) ret += "0";
    while (i + 3 < (str.substr(0, 1) == "-" ? sep-1 : sep)) ret = (siStyle ? "." : ",") + str.substr(sep - (i += 3), 3) + ret;
    return str.substr(0, sep - i) + ret;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2009/08/number-format-thousand-separator-in-as3/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Load font dynamically on runtime</title>
		<link>http://flassari.is/2009/05/load-font-dynamically-on-runtime/</link>
		<comments>http://flassari.is/2009/05/load-font-dynamically-on-runtime/#comments</comments>
		<pubDate>Wed, 06 May 2009 15:20:20 +0000</pubDate>
		<dc:creator>Flassari</dc:creator>
				<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[external]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[runtime]]></category>

		<guid isPermaLink="false">http://flassari.is/?p=137</guid>
		<description><![CDATA[Sometimes you want to be able to keep your fonts in a seperate swf file, a "font library" if you will, that you can load dynamically on runtime. Here's how to do that in AS3: [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to be able to keep your fonts in a seperate swf file, a &#8220;font library&#8221; if you will, that you can load dynamically on runtime. Here&#8217;s how to do that in AS3:</p>
<p>The first thing you have to do is create a new flash file to store the font(s). Then, right click the library and select &#8220;New Font&#8230;&#8221;.<br />
<img src="http://flassari.is/wp-content/uploads/2009/05/newfont.png" alt="newfont" title="newfont" width="373" height="296" class="aligncenter size-full wp-image-138" /></p>
<p>Choose the font you want to embed and give it a name. Any name will do here, as this is only the library name and will not affect our code in any way. I prefer to name the font with the same name as the linkage name I plan to give it.<br />
<img src="http://flassari.is/wp-content/uploads/2009/05/myfont.png" alt="myfont" title="myfont" width="417" height="144" class="aligncenter size-full wp-image-141" /></p>
<p>Click ok, and then right click the font in the library and select &#8220;Linkage&#8230;&#8221;. Check the &#8220;Export for ActionScript&#8221; and &#8220;Export in first frame&#8221; options, give your font the linkage name of your own liking and click OK.<br />
<img src="http://flassari.is/wp-content/uploads/2009/05/linkage.png" alt="linkage" title="linkage" width="447" height="231" class="aligncenter size-full wp-image-140" /></p>
<p>And now you&#8217;re ready. Export the file to swf and there&#8217;s your font resource file.</p>
<p>If you want to use that font, you first have to load it into the application domain, and then register it on the global font list using the Font.registerFont function. The textfield can&#8217;t display it until it has the embedFonts property set to true and the font name in its textformat.<br />
You can see an example in the following code, ready to be pasted into your frame:</p>
<pre class="brush: as">var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
l.load(new URLRequest("MyFont.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));

function onLoaded(e:Event):void {
	// Register the font to the global font list
	Font.registerFont( Class( ApplicationDomain.currentDomain.getDefinition("MyFont")));

	myTextField.embedFonts = true;
	// instantiate the font just to get the real font name, or if you know the name before hand you can just hard-code it in here
	var fontName:String = new (ApplicationDomain.currentDomain.getDefinition("MyFont"))().fontName;
	var tf:TextFormat = new TextFormat(fontName);
	// Set the text format for the text already in the text field
	myTextField.setTextFormat(tf);
	// and for future changes
	myTextField.defaultTextFormat = tf;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://flassari.is/2009/05/load-font-dynamically-on-runtime/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
