<?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>Thinking in Code &#187; Actionscript</title>
	<atom:link href="http://www.michelboudreau.com/tags/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.michelboudreau.com</link>
	<description>Michel Boudreau&#039;s Personal Blog</description>
	<lastBuildDate>Wed, 25 Apr 2012 20:18:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>An Evening with Mike Chambers and Lee Brimelow</title>
		<link>http://www.michelboudreau.com/2012/04/01/an-evening-with-mike-chambers-and-lee-brimelow/</link>
		<comments>http://www.michelboudreau.com/2012/04/01/an-evening-with-mike-chambers-and-lee-brimelow/#comments</comments>
		<pubDate>Mon, 02 Apr 2012 03:07:11 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[3d]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[avm]]></category>
		<category><![CDATA[flash player]]></category>
		<category><![CDATA[flex meetup]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[lee brimelow]]></category>
		<category><![CDATA[mike chamber]]></category>
		<category><![CDATA[new york]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=880</guid>
		<description><![CDATA[Adobe is doing a North American tour to talk about ...]]></description>
			<content:encoded><![CDATA[<p>Adobe is doing a North American tour to talk about the Flash Player and some of the latest changes to the platform.  Mike Chambers and Lee Brimelow will swing by at our <a href="http://newyorkflexmeetup.eventbrite.com/" target="_blank">usual location on April 12th, so please sign up</a>.  The marketing spiel after the break.</p>
<p><span id="more-880"></span></p>
<p style="padding-left: 30px;">Join us for an evening with Mike Chambers &amp; Lee Brimelow from Adobe.  This will be a good opportunity to speak directly with Adobe, ask questions, and discuss recent changes around the Flash Player.</p>
<p style="padding-left: 30px;"><strong>The Future of Flash – Mike Chambers</strong></p>
<p style="padding-left: 30px;">In this session, Mike will lead a discussion around recent changes and announcements around the Flash Platform. He will then spend some time laying out the roadmap for the Flash Player, and discuss the direction in which the player will evolve, including the general focus of the player and the ActionScript language and AVM (ActionScript Virtual Machine). In addition to discussing the Flash roadmap, we will be showing off the latest Flash and Adobe AIR content, give some sneak peeks on upcoming releases, and setting aside plenty of time for open discussions and Q&amp;A.</p>
<p style="padding-left: 30px;"><strong>Adobe Gaming Technology – Lee Brimelow</strong></p>
<p style="padding-left: 30px;">In this session Gaming Evangelist Lee Brimelow will reveal the latest technologies being worked on by Adobe for game developers. They will show how these technologies allow developers to create casual 2D games in addition to AAA 3D games. Current best practices will also be discussed.</p>
<p>This will also be <a href="http://www.ustream.tv/channel/mike-s-flex-channel" target="_blank">streamed on my ustream channel</a> for those who can&#8217;t attend in person.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2012/04/01/an-evening-with-mike-chambers-and-lee-brimelow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Actionscript Label Statements for Loops</title>
		<link>http://www.michelboudreau.com/2011/08/28/actionscript-label-statements-for-loops/</link>
		<comments>http://www.michelboudreau.com/2011/08/28/actionscript-label-statements-for-loops/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 07:04:59 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[break]]></category>
		<category><![CDATA[label]]></category>
		<category><![CDATA[loops]]></category>
		<category><![CDATA[statement]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=747</guid>
		<description><![CDATA[I have to say that I&#8217;m ashamed that I didn&#8217;t ...]]></description>
			<content:encoded><![CDATA[<p>I have to say that I&#8217;m ashamed that I didn&#8217;t know about this beforehand. I&#8217;ve recently discovered a little feature in Actionscript called <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/statements.html#label">label statements</a>. &nbsp;I always expect to learn new things in the industry since it&#8217;s every-changing, however I did not think I would learn something new about Actionscript since I&#8217;ve used it since AS1 and have thoroughly studied AS3 when it came out.<br />
<span id="more-747"></span></p>
<p>Let&#8217;s give a quick example of a simple problem: You need to find the index of a string within a 2D array and do something with that index. &nbsp;Here&#8217;s how I would do it normally:</p>
<pre class="brush: as3; title: ; notranslate">
private function findIndex(text:String):void
{
	var row:Array;
	var index:Point;
	for(var y:uint = 0, ylen:uint = array.length; y&lt;ylen; y++)
	{
		row = array[y];
		for(var x:uint = 0, xlen:uint = row.length; x&lt;xlen; x++)
		{
			if(row[x] == text)
			{
				index = new Point(x,y);
				break;
			}
		}
		if(index)
		{
			break;
		}
	}
	// Do something with index
}
</pre>
<p>You&#8217;ll notice that within the example, the second I find the index, I break out of the loops to reduce the run time of the function.  The external loop always looks to see if &#8216;index&#8217; is not null and breaks out if it is.  I&#8217;ve never liked this approach because it adds more code than needed and sometimes its not as easy as just checking if a variable is not null.  You could always use &#8216;return&#8217; if your function is done with its purpose, but that&#8217;s not always possible.</p>
<p>The alternative to this is using label statements.  What you can do is simply &#8216;label&#8217; your loops and then when you want to break, you can specify which loop that needs to be broken.  Take our current example and let&#8217;s add label statements in it:</p>
<pre class="brush: as3; title: ; notranslate">
private function findIndex(text:String):void
{
	var row:Array;
	var index:Point;
	outer:for(var y:uint = 0, ylen:uint = array.length; y&lt;ylen; y++)
	{
		row = array[y];
		for(var x:uint = 0, xlen:uint = row.length; x&lt;xlen; x++)
		{
			if(row[x] == text)
			{
				index = new Point(x,y);
				break outer;
			}
		}
	}
	// Do something with index
}
</pre>
<p>That is much better and cleaner.  I&#8217;ve seen this done before in Java, but I have never encountered or read about it for Actionscript.  This method can also be used with the &#8216;continue&#8217; operator so that it skips the rest of the code to the next iteration or with block statements like so:</p>
<pre class="brush: as3; title: ; notranslate">
doSomething: {
	var x:uint = index.x;
	if(x &gt; 100)
	{
		break doSomething;
	}
	trace(x);
}
</pre>
<p>I don&#8217;t think I would ever use it with block statements since these could be simply replaced with &#8216;if&#8217; statements, but knowing about it can be beneficial.  I know I will be using label statements in nested loops from now on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2011/08/28/actionscript-label-statements-for-loops/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>EventDispatcher vs. Signals</title>
		<link>http://www.michelboudreau.com/2010/12/31/eventdispatcher-vs-signals/</link>
		<comments>http://www.michelboudreau.com/2010/12/31/eventdispatcher-vs-signals/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 15:49:35 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[as3signals]]></category>
		<category><![CDATA[benchmark]]></category>
		<category><![CDATA[cons]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[eventdispatcher]]></category>
		<category><![CDATA[lab49]]></category>
		<category><![CDATA[pros]]></category>
		<category><![CDATA[signal]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=628</guid>
		<description><![CDATA[At our last Flex Meetup, Adam Spektor did an overview ...]]></description>
			<content:encoded><![CDATA[<p>At our last <a href="http://www.meetup.com/New-York-Flex-Meetup/" target="_blank">Flex Meetup</a>, Adam Spektor did an overview of <a href="https://github.com/robertpenner/as3-signals" target="_blank">AS3Signals</a> (by <a href="http://flashblog.robertpenner.com/" target="_blank">Robert Penner</a>) which brought up some interesting questions about why developers would use Signals over regular Events.  I decided that I would test it out and benchmark both methods, meanwhile evaluating the pros and cons of each.  To be able to test the results, I created a FlexUnit project that would test the creation and dispatch of one event, and then the dispatch of a thousand events.  In one test case, I would test a single Signal and in the other test case I would just create a central EventDispatcher to try to mimic Signals.  You can find the project <a href="http://www.michelboudreau.com/wp-content/uploads/2010/12/EventBenchmark.zip">here</a>, but the real important part is the execution time of each one.</p>
<p><span id="more-628"></span></p>
<p><strong>Results</strong></p>
<table class="datatable" style="border-collapse: collapse; width: 400px;">
<tbody>
<tr style="text-align: center;">
<td style="border-right: 3px solid white;"></td>
<td style="border-right: 3px solid white;" colspan="2"><strong>Event Dispatcher</strong></td>
<td colspan="2"><strong>Signals</strong></td>
</tr>
<tr style="text-align: center;">
<td style="border-right: 3px solid white;"></td>
<td>1 event</td>
<td style="border-right: 3px solid white;">1000 events</td>
<td>1 event</td>
<td>1000 events</td>
</tr>
<tr style="text-align: center;">
<td style="text-align: left; border-right: 3px solid white;"><strong>Trial 1</strong></td>
<td>26ms</td>
<td style="border-right: 3px solid white;">15ms</td>
<td>9ms</td>
<td>25ms</td>
</tr>
<tr style="text-align: center;">
<td style="text-align: left; border-right: 3px solid white;"><strong>Trial 2</strong></td>
<td>15ms</td>
<td style="border-right: 3px solid white;">55ms</td>
<td>11ms</td>
<td>20ms</td>
</tr>
<tr style="text-align: center;">
<td style="text-align: left; border-right: 3px solid white;"><strong>Trial 3</strong></td>
<td>47ms</td>
<td style="border-right: 3px solid white;">18ms</td>
<td>19ms</td>
<td>16ms</td>
</tr>
<tr style="text-align: center;">
<td style="text-align: left; border-right: 3px solid white;"><strong>Trial 4</strong></td>
<td>51ms</td>
<td style="border-right: 3px solid white;">15ms</td>
<td>15ms</td>
<td>25ms</td>
</tr>
<tr style="text-align: center;">
<td style="text-align: left; border-right: 3px solid white;"><strong>Average<br />
</strong></td>
<td><strong>34.75ms</strong></td>
<td style="border-right: 3px solid white;"><strong>25.75ms</strong></td>
<td><strong>13.5ms</strong></td>
<td><strong>21.5ms</strong></td>
</tr>
<tr>
<td style="border-right: 3px solid white;"><strong>Total</strong></td>
<td style="text-align: center; border-right: 3px solid white;" colspan="2"><strong>60.5ms</strong></td>
<td style="text-align: center;" colspan="2"><strong>35ms<br />
</strong></td>
</tr>
</tbody>
</table>
<p>Now, a few things about this data.  The Signals library was very consistent in the times outputted, however the EventDispatcher was very erratic.  You can see it a little here within the results, but these results were fairly tame.  During testing, I&#8217;ve seen spikes going both high and low.  I&#8217;ve also seen it several times being faster than Signals.  I&#8217;ve tried to find an explanation about why and all I could think of is because the EventDispatcher is so intertwined with Flash Player and that could affect the test somehow but this is all speculation.</p>
<p>Because of this inconsistency, it&#8217;s hard to interpret the data for the EventDispatcher, so instead let&#8217;s concentrate more on the Signals side.  You&#8217;ll notice that the time taken is fairly consistent and would work as expected (one event is faster than a thousand).  When I first heard of Signals, my first thought was that this would be faster than normal events, and the data clearly shows this by 173%.</p>
<p>Signals is fast, there&#8217;s no doubt about it, but will incorporating it in your project actually increase overall speed?  Will it actually benefit development?</p>
<p>Personally, I don&#8217;t think I would personally use it in my project for a few different reasons:</p>
<ol>
<li>It&#8217;s not native to Flash/Flex.  Some may dismiss this point, but when you have a whole system based upon EventDispatcher and Events, it&#8217;s hard to ignore.</li>
<li>Lack of bubbling and capture.  Signals is working on bubbling, but I doubt they will get it working as well as the native implementation.</li>
<li>There is no meta-data possible for Signals.  This severely limits the possibility of using signals in MXML.</li>
<li>Need to recreate all event variables for Signals all over again.  Signals tries to reduce boiler-plate code by dismissing custom Event classes, but you still need to create new variables in the class for the event which essentially cancel each other out.</li>
<li>Keeping two separate standards for events in one system is a maintenance nightmare.</li>
<li>Little speed gain for the amount of extra work needed to get it working in a system.</li>
</ol>
<p>All and all, I think Signals is a very good idea for performance and extra utility, however it seems to me that the concept is Utopian.  If we could swap out the native event mechanism of Flash, then I&#8217;d be all for it, but in my current situation it isn&#8217;t very realistic to replace a current system that works (very well I might add) with another that&#8217;s slightly faster and more convenient.  The pros simply do not outweigh the cons.  If I were to use Signals, it would be in a very small Actionscript only project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2010/12/31/eventdispatcher-vs-signals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex/Actionscript UML Tool: UML4AS</title>
		<link>http://www.michelboudreau.com/2010/08/18/flexactionscript-uml-tool-uml4as/</link>
		<comments>http://www.michelboudreau.com/2010/08/18/flexactionscript-uml-tool-uml4as/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 19:08:39 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Flash Platform]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[as]]></category>
		<category><![CDATA[CodeSync]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[lab49]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[uml]]></category>
		<category><![CDATA[uml4as]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=389</guid>
		<description><![CDATA[Anyone remember Saffron?  I was never certain if this project ...]]></description>
			<content:encoded><![CDATA[<p>Anyone remember <a href="http://www.michelboudreau.com/2010/04/30/saffron-is-still-alive/" target="_blank">Saffron</a>?  I was never certain if this project was ever going to come to fruition, so lately I was thinking excessively about making my own.  I started searching for inspiration in other UML tools so I could design a better user interface.  Low and behold, I stumble across <a href="http://www.uml4as.com" target="_blank">UML4AS</a>, a brand spanking new project that does just what I was planning of doing.</p>
<p>It integrates completely with Eclipse (and Flash Builder) and has this neat feature called CodeSync that makes sure your model and code is always persisted between each other.  In other words, everything works together in an integrated workflow to save you time.</p>
<p>I&#8217;ll have to dig deeper, try this out on projects and do a complete review.  In the meantime, please support this initiative by registering and posting on the forum.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2010/08/18/flexactionscript-uml-tool-uml4as/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RichTextArea Component</title>
		<link>http://www.michelboudreau.com/2010/03/18/richtextarea-component/</link>
		<comments>http://www.michelboudreau.com/2010/03/18/richtextarea-component/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 21:31:09 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[lab49]]></category>
		<category><![CDATA[richtextarea]]></category>
		<category><![CDATA[tag]]></category>
		<category><![CDATA[textarea]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=232</guid>
		<description><![CDATA[A few months ago, I was working on a project ...]]></description>
			<content:encoded><![CDATA[<p>A few months ago, I was working on a project that needed a CMS backend to create content that will be displayed in Flex.  We used a RichTextEditor component to create appropriate HTML so that it would display like we wanted to on the frontend.</p>
<p>The problem with this approach is that we needed our application to be re-themeable between different clients that would be using this product, which meant that we also needed a way to style the html content without having to redo the html itself.</p>
<p><span id="more-232"></span></p>
<p>As much as I looked for it, I couldn&#8217;t find anyone else doing something similar to this, so I created my own.  Essentially, I just extended TextArea which already handles htmlText and added my own html tag styling to it.  I was surprised to see that you can actually set styles to the html within the TextArea, but you can only do it with Actionscript.</p>
<p>I looked at all the possible <a href="http://livedocs.adobe.com/flex/3/html/textcontrols_04.html#437502" target="_blank">html tags</a> that TextArea supports, and created CSS styles for it.  I wanted to stick with the proper CSS convention of separating the words using a dash and used my own kind of standard &#8216;html-&lt;tag&gt;-&lt;property&gt;&#8217;, property being one of &#8216;color&#8217;, &#8216;weight&#8217;, &#8216;decoration&#8217; or &#8216;style&#8217;.  One exception to this rule is for the anchor tag, which can also do pseudo-classes (a:link, a:hover and a:active).  If you need to reference those tags, you just need to use &#8216;alink&#8217;, &#8216;ahover&#8217; and &#8216;aactive&#8217;.  If someone has a better suggestion, I&#8217;m all ears.</p>
<pre class="brush: as3; title: ; notranslate">
package com.lab49.components
{
	import flash.text.StyleSheet;

	import mx.collections.ArrayCollection;
	import mx.controls.TextArea;
	import mx.styles.CSSStyleDeclaration;
	import mx.styles.StyleManager;

	// Set the style metadata - If adding another style/tag, add it here
	// Style names are in the of 'html-&lt;tag&gt;-&lt;property&gt;' exception is for pseudo-classes
	// which is attached directly to the tag name.
	[Style(name=&quot;html-a-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-a-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-a-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-a-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-ahover-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-ahover-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-ahover-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-ahover-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-aactive-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-aactive-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-aactive-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-aactive-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-alink-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-alink-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-alink-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-alink-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-b-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-b-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-b-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-b-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-font-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-font-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-font-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-font-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-i-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-i-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-i-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-i-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-li-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-li-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-li-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-li-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-p-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-p-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-p-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-p-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-span-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-span-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-span-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-span-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-textformat-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-textformat-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-textformat-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-textformat-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-u-style&quot;, type=&quot;String&quot;, enumeration=&quot;italic, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-u-weight&quot;, type=&quot;String&quot;, enumeration=&quot;bold, normal&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-u-decoration&quot;, type=&quot;String&quot;, enumeration=&quot;none, underline&quot;, inherit=&quot;no&quot;)]
	[Style(name=&quot;html-u-color&quot;, type=&quot;uint&quot;, format=&quot;Color&quot;, inherit=&quot;no&quot;)]

	/**
	 * RichTextArea Class, extends TextArea.  Displays html text, but styles them uniformily for
	 * easy theming.
	 **/
	public class RichTextArea extends TextArea
	{
		private var _stypePropChanged:Boolean = false; // Style property change flag.  Set to true when one of the html styles is set
        private static var _classConstructed:Boolean = classConstruct(); // Calls a static initializer function before anything else

        // All possible styles.  If adding a new one, must be added in this ArrayCollection with the proper metadata above.
        private const _styles:ArrayCollection = new ArrayCollection([	&quot;html-a-style&quot;,
														            	&quot;html-a-weight&quot;,
														            	&quot;html-a-decoration&quot;,
														            	&quot;html-a-color&quot;,
														            	&quot;html-ahover-style&quot;,
														            	&quot;html-ahover-weight&quot;,
														            	&quot;html-ahover-decoration&quot;,
														            	&quot;html-ahover-color&quot;,
														            	&quot;html-alink-style&quot;,
														            	&quot;html-alink-weight&quot;,
														            	&quot;html-alink-decoration&quot;,
														            	&quot;html-alink-color&quot;,
														            	&quot;html-aactive-style&quot;,
														            	&quot;html-aactive-weight&quot;,
														            	&quot;html-aactive-decoration&quot;,
														            	&quot;html-aactive-color&quot;,
														            	&quot;html-b-style&quot;,
														            	&quot;html-b-weight&quot;,
														            	&quot;html-b-decoration&quot;,
														            	&quot;html-b-color&quot;,
														            	&quot;html-font-style&quot;,
														            	&quot;html-font-weight&quot;,
														            	&quot;html-font-decoration&quot;,
														            	&quot;html-font-color&quot;,
														            	&quot;html-i-style&quot;,
														            	&quot;html-i-weight&quot;,
														            	&quot;html-i-decoration&quot;,
														            	&quot;html-i-color&quot;,
														            	&quot;html-li-style&quot;,
														            	&quot;html-li-weight&quot;,
														            	&quot;html-li-decoration&quot;,
														            	&quot;html-li-color&quot;,
														            	&quot;html-p-style&quot;,
														            	&quot;html-p-weight&quot;,
														            	&quot;html-p-decoration&quot;,
														            	&quot;html-p-color&quot;,
														            	&quot;html-span-style&quot;,
														            	&quot;html-span-weight&quot;,
														            	&quot;html-span-decoration&quot;,
														            	&quot;html-span-color&quot;,
														            	&quot;html-textformat-style&quot;,
														            	&quot;html-textformat-weight&quot;,
														            	&quot;html-textformat-decoration&quot;,
														            	&quot;html-textformat-color&quot;,
														            	&quot;html-u-style&quot;,
														            	&quot;html-u-weight&quot;,
														            	&quot;html-u-decoration&quot;,
														            	&quot;html-u-color&quot; ]);

		// Sets default properties of RichTextArea
		[Inspectable(category=&quot;General&quot;, defaultValue=&quot;false&quot;)]
		override public function set editable(value:Boolean):void
		{
			super.editable = value;
		}

		[Inspectable(category=&quot;General&quot;, defaultValue=&quot;true&quot;)]
		override public function set selectable(value:Boolean):void
		{
			super.selectable = value;
		}

		[Inspectable(category=&quot;General&quot;, defaultValue=&quot;true&quot;)]
		override public function set condenseWhite(value:Boolean):void
		{
			super.condenseWhite = value;
		}

		// Constructor
		public function RichTextArea()
		{
			super();

			// Removes background, border and focus highlight of the TextArea
			this.setStyle('backgroundAlpha', 0);
			this.setStyle('borderStyle', 'none');
			this.setStyle('focusAlpha', 0);
		}

		/**
		 * This method is called a static initializer since it is called before the
		 * constructor since it's being referenced by a static variable.
		 * If anything needs to be set before the constructor runs, this is the place to do it.
		 *
		 * @return true
		 **/
        private static function classConstruct():Boolean
        {
        	// Check to see if style exists
            if (!StyleManager.getStyleDeclaration(&quot;RichTextArea&quot;))
            {
            	// Set default empty style declaration
                var style:CSSStyleDeclaration = new CSSStyleDeclaration();
                style.defaultFactory = function():void {};
                StyleManager.setStyleDeclaration(&quot;RichTextArea&quot;, style, true);
            }
            return true;
        }

    	/**
    	 * Overrides the htmlText property to set the '_stylePropertyChanged' flag
    	 * since any new text being set will not be styled unless updateDisplayList()
    	 * is called.
    	 *
    	 * @param value:String The html text to be set
    	 **/
    	override public function set htmlText(value:String):void
		{
			super.htmlText = value;
			this._stypePropChanged = true; // Set the flag to style the text
			invalidateDisplayList(); // Call updateDisplayList() on next render
		}

		/**
		 * Override the styleChanged() method to detect changes in your new style.
		 * only set the _stylePropChanged tag to true if one of our custom styles has
		 * been changed.  If a new style is added, it must be added here as well.
		 *
		 * @param styleProp:String The new property name that has been set
		 **/
        override public function styleChanged(styleProp:String):void
        {
            super.styleChanged(styleProp);

            // Check to see if it's one of our custom styles
            if(this._styles.contains(styleProp))
            {
            	// Redo text styling
            	this._stypePropChanged = true;
	            invalidateDisplayList();
            }
        }

		// Override updateDisplayList() to update the component
        // based on the style setting.
        /**
         * Override the drawing function and resets the style on the html text if the _stylePropChanged flag is set to true.
         *
         * @param unscaledWidth:Number the width of the current component
         * @param unscaledHeight:Number the height of the current component
         **/
        override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
        {
            super.updateDisplayList(unscaledWidth, unscaledHeight);

            // Check to see if style changed.
            if (this._stypePropChanged)
            {
            	this._stypePropChanged = false; // set the flag back to false

                /*
				 * Adds new styles to the CSS for specific html content.
				 * More can be added, just add the tag name in the 'tags' array and
				 * add the css property 'html-&lt;tag name&gt;-&lt;text property name&gt;' in your stylesheet
				 * For instance, I can could do 'html-p-weight:bold'.
				 * Possible text property names are 'style', 'weight', 'decoration' and 'color'
				 *
				 * Only exception to the tag name is for the 'a' tag.  You can specify just 'a' or
				 * you can do the pseudo class 'hover', 'link' and 'active', but you need to specify the tag
				 * before, like so 'html-ahover-weight: bold;'.
				 */
				var style:Object, value:Object, tag:String, tagSplit:Array, ss:StyleSheet = new StyleSheet();

				for(var i:int = 0, len:int = this._styles.length; i &lt; len; i++)
				{
					style = {};
					tag = this._styles.getItemAt(i) as String;

					// Convert into AS3 stylename format (camelCase)
					tagSplit = tag.split('-');
					tag = tagSplit[0] + String(tagSplit[1]).charAt(0).toUpperCase() + String(tagSplit[1]).slice(1) +
							String(tagSplit[2]).charAt(0).toUpperCase() + String(tagSplit[2]).slice(1);

					// Get style if there
					value = getStyle(tag);
					if(value)
					{
						style = ss.getStyle(tagSplit[1]); // Get style if one already exists so you don't override the previous one
						// Find the proper style name and save it
						switch(tagSplit[2])
						{
							case 'style':
								style.fontStyle = value;
								break;
							case 'weight':
								style.fontWeight = value;
								break;
							case 'decoration':
								style.textDecoration = value;
								break;
							case 'color':
								style.color = '#'+('00000'+Number(value).toString(16).toUpperCase()).substr(-6);
								break;
						}

						// Do the cases for the pseudo 'a' classes and set the style object
						switch(tagSplit[1])
						{
							case 'ahover':
								ss.setStyle('a:hover', style);
								break;
							case 'alink':
								ss.setStyle('a:link', style);
								break;
							case 'aactive':
								ss.setStyle('a:active', style);
								break;
							default:
								ss.setStyle(tagSplit[1], style);
								break;
						}
					}
				}

				styleSheet = ss; // Save stylesheet
            }
        }
	}
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2010/03/18/richtextarea-component/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
Page Caching using disk: enhanced
Database Caching 1/30 queries in 0.010 seconds using disk: basic
Object Caching 506/594 objects using disk: basic

Served from: www.michelboudreau.com @ 2012-05-21 07:00:18 -->
