<?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>Coding Color &#187; Actionscript</title>
	<atom:link href="http://www.codingcolor.com/category/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codingcolor.com</link>
	<description>is Manuel Gonzalez</description>
	<lastBuildDate>Wed, 25 May 2011 06:53:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>AS3 Embed My Font Utility</title>
		<link>http://www.codingcolor.com/as3/as3-embed-my-font-utility/</link>
		<comments>http://www.codingcolor.com/as3/as3-embed-my-font-utility/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 20:09:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[embed]]></category>
		<category><![CDATA[Font]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[TextFormat]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=1367</guid>
		<description><![CDATA[Here&#8217;s a quick ActionScript font utility, that some of you flash devs may find useful. It uses the most popular way of embedding a font, by referencing a font symbol in the library. If you are not familiar with the process, the following are quick directions on how to create a font in the library. [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick ActionScript font utility, that some of you flash devs may find useful. It uses the most popular way of embedding a font, by referencing a font symbol in the library. If you are not familiar with the process, the following are quick directions on how to create a font in the library.</p>
<p>(1) Open up your Library.<br />
(2) Select the upper-right corner of the Library panel pop up menu.<br />
(3) Select New Font.<br />
(4) Enter a name for the font in the Name field.<br />
(5) Select a font from the Font menu.<br />
(6) Select your desired font style (Regular, Italic, Bold, or Bold Italic) from the Style drop-down menu.</p>
<p><strong>*Note:</strong> The Size setting applies only when you use the Bitmap Text option. You&#8217;ll usually set the size of the text in a TextFormat object.</p>
<p>(8) Click the Advanced button<br />
(9) Click Export for ActionScript and enter a class name. </p>
<p><strong>*Note:</strong> I usually place my library items in a lib namespace, you don&#8217;t have to do that.</p>
<p>(10) Click OK.</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2011/02/Picture-1.png" alt="" title="Picture 1" width="578" height="502" class="aligncenter size-full wp-image-3579" /></p>
<p>The font utility simply creates a TextFormat object and sets its fontFamily property to the name of the embedded font, and applies the TextFormat object to a given TextField. </p>
<p>The following is the example swf:</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_FontUtil_503957367"
			class="flashmovie"
			width="550"
			height="400">
	<param name="movie" value="http://www.codingcolor.com/wp-content/uploads/2011/02/FontUtil.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.codingcolor.com/wp-content/uploads/2011/02/FontUtil.swf"
			name="fm_FontUtil_503957367"
			width="550"
			height="400">
	<!--<![endif]-->
		
<p><a href="http://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>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here&#8217;s the document class which displays examples on how to use the font utility.</p>
<p><code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #3f5fbf;">/*******************************<br />
* Author: Manuel Gonzalez &nbsp; &nbsp; &nbsp;*<br />
* www &nbsp; : www.codingcolor.com &nbsp;*<br />
* email : design@stheory.com &nbsp; *<br />
********************************/</span><br />
<span style="color: #9900cc; font-weight: bold;">package</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>TextFields<span style="color: #000066; font-weight: bold;">.</span>EmbedFontUtil<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>lib<span style="color: #000066; font-weight: bold;">.</span>Jazz<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>lib<span style="color: #000066; font-weight: bold;">.</span>Juice<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>lib<span style="color: #000066; font-weight: bold;">.</span>Banco<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>lib<span style="color: #000066; font-weight: bold;">.</span>HelveticaBlack<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormatAlign</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> DocApp <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> embedUtil &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">:</span>EmbedFontUtil<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> exampleString_1 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">'A dynamic TextField displaying the Jazz Font'</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> exampleString_2 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">'A dynamic TextField with a TextFormat displaying the Juice Font.'</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> exampleString_3 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">'The Banco Font, TextFormat and other crap!'</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> exampleString_4 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">'Displaying Helvetica Bold in a text field on stage.'</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> exampleString_5 <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #004993;">String</span> = <span style="color: #990000;">'Press the button to change my font'</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009900; font-style: italic;">//</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> changeFontButton<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> DocApp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp;embedUtil = EmbedFontUtil<span style="color: #000066; font-weight: bold;">.</span>getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009966; font-style: italic;">/******** simple example with a dynamic text field *************/</span> <br />
<span style="color: #6699cc; font-weight: bold;">var</span> testField_1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span> = <span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">.</span>LEFTtestField_1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> JazzFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Jazz<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//make sure to import your font</span><br />
embedUtil<span style="color: #000066; font-weight: bold;">.</span>embedFont<span style="color: #000000;">&#40;</span>testField_1<span style="color: #000066; font-weight: bold;">,</span>JazzFont<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = exampleString_1<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>testField_1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009966; font-style: italic;">/******** simple example with a text field placed manually on stage *********/</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> helveticaBlackFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span> = <span style="color: #0033ff; font-weight: bold;">new</span> HelveticaBlack<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//make sure to import your font</span><br />
embedUtil<span style="color: #000066; font-weight: bold;">.</span>embedFont<span style="color: #000000;">&#40;</span>textFieldOnStage<span style="color: #000066; font-weight: bold;">,</span>helveticaBlackFont<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
textFieldOnStage<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = exampleString_4<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #009966; font-style: italic;">/****************************************************************************/</span><br />
<br />
<span style="color: #009966; font-style: italic;">/******** example with a dynamic text field &amp; TextFormat object ************/</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> testField_2<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span> = <span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> format_1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
format_1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">color</span> = 0xff00ff<span style="color: #000066; font-weight: bold;">;</span><br />
format_1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">TextFormatAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
format_1<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> = <span style="color: #000000; font-weight:bold;">14</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> juiceFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Juice<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//make sure to import your font</span><br />
embedUtil<span style="color: #000066; font-weight: bold;">.</span>embedFont<span style="color: #000000;">&#40;</span>testField_2<span style="color: #000066; font-weight: bold;">,</span>juiceFont<span style="color: #000066; font-weight: bold;">,</span>format_1<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_2<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = &nbsp;exampleString_2<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>testField_2<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #009966; font-style: italic;">/************************************************************************/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #009966; font-style: italic;">/******** example with a dynamic textfield &amp; properties including TextFormat**********/</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> testField_3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">500</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">22</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">background</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">backgroundColor</span> = 0x000000<span style="color: #000066; font-weight: bold;">;</span><br />
testField_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">textColor</span> = 0xffffff<span style="color: #000066; font-weight: bold;">;</span><br />
testField_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">85</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #6699cc; font-weight: bold;">var</span> format_3<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
format_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> = <span style="color: #000000; font-weight:bold;">16</span><span style="color: #000066; font-weight: bold;">;</span><br />
format_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">TextFormatAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CENTER</span><span style="color: #000066; font-weight: bold;">;</span><br />
format_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">url</span> = <span style="color: #990000;">&quot;http://codingcolor.com&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
format_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">underline</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #6699cc; font-weight: bold;">var</span> bancoFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Banco<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//make sure to import your font</span><br />
embedUtil<span style="color: #000066; font-weight: bold;">.</span>embedFont<span style="color: #000000;">&#40;</span>testField_3<span style="color: #000066; font-weight: bold;">,</span>bancoFont<span style="color: #000066; font-weight: bold;">,</span>format_3<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
testField_3<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = &nbsp;exampleString_3<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>testField_3<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #009966; font-style: italic;">/*************** example with a textfield on stage preserve format and string change font ****/</span><br />
createButtonUI<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
changeFontField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = exampleString_5<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #3f5fbf;">/*<br />
Method: createButtonUI<br />
Parameters:<br />
Returns:<br />
*/</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createButtonUI<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
changeFontButton = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
changeFontButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">;</span><br />
changeFontButton<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span>changeFontField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">,</span>changeFontField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">+</span> changeFontField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
changeFontButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;Change Font&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
changeFontButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;textFormat&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Helvetica Black&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
changeFontButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> changeTheFont<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>changeFontButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #3f5fbf;">/*<br />
Method: changeTheFont<br />
Parameters:<br />
evt:MouseEvent<br />
Returns:<br />
*/</span><br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> changeTheFont<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> JazzFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Jazz<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
embedUtil<span style="color: #000066; font-weight: bold;">.</span>embedNewFontPreserveString<span style="color: #000000;">&#40;</span>changeFontField<span style="color: #000066; font-weight: bold;">,</span>JazzFont<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>As you can see it&#8217;s pretty simple to use:<br />
<code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #6699cc; font-weight: bold;">var</span> helveticaBlackFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span> = <span style="color: #0033ff; font-weight: bold;">new</span> HelveticaBlack<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
embedUtil<span style="color: #000066; font-weight: bold;">.</span>embedFont<span style="color: #000000;">&#40;</span>textFieldOnStage<span style="color: #000066; font-weight: bold;">,</span>helveticaBlackFont<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
textFieldOnStage<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = exampleString_4<span style="color: #000066; font-weight: bold;">;</span></span></code></p>
<p>Download the class and files below.<br />
Enjoy!<br />
<a class="downloadlink" href="http://www.codingcolor.com/downloads/Embed_Font.zip" title="Version1.0 downloaded 41 times" >Font Embed Util (41)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/as3/as3-embed-my-font-utility/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What&#8217;s my text string width?</title>
		<link>http://www.codingcolor.com/as3/whats-my-text-string-width-or-height/</link>
		<comments>http://www.codingcolor.com/as3/whats-my-text-string-width-or-height/#comments</comments>
		<pubDate>Mon, 17 Jan 2011 06:44:10 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[combo box component]]></category>
		<category><![CDATA[TextField]]></category>
		<category><![CDATA[TextField.height]]></category>
		<category><![CDATA[TextField.width]]></category>
		<category><![CDATA[textHeight]]></category>
		<category><![CDATA[textWidth]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=3518</guid>
		<description><![CDATA[Here we go again, another snippet into a flash devs mind. Have you&#8217;ve ever been tasked with localizing a flash application? Have you ever had the need to determine the width of a string prior to displaying it in a text field? Just recently I had to localize an application in 4 languages, which meant [...]]]></description>
			<content:encoded><![CDATA[<p>Here we go again, another snippet into a flash devs mind.  Have you&#8217;ve ever been tasked with localizing a flash application? Have you ever had the need to determine the width of a string prior to displaying it in a text field? Just recently I had to localize an application in 4 languages, which meant my user interface/design would have to adjust depending on the language or translated string being displayed. I had an issue where I had a combo box on stage which needed to re-size based on the width of the longest string in its DataProvider. The issue spawned a quick and dirty solution which will be helpful to some.<br />
The idea is to take a string, create a text field, provide the text field with the string and determine the text fields width. In a nut shell that&#8217;s what the class does. It also has a method that will determine the widest string out of an array of strings.</p>
<p>To state the obvious, flash readily allows a few ways to read the width and height of a <a href="http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/flash/text/TextField.htmt" target="blank">TextField</a> display object.<br />
You can use the following properties of the TextField class:</p>
<p>textWidth: The width of the text in pixels.<br />
textHeight: The height of the text in pixels</p>
<p>Or get the width and height using the TextField width and height properties, which will include the invisible frame which surrounds the text field.</p>
<p>TextField.width:  The width of the TextField in pixels.<br />
TextField.height:  The width of the TextField in pixels.</p>
<p>And last but not least you can use the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextLineMetrics.html?filter_flex=4.1&#038;filter_flashplayer=10.1&#038;filter_air=2" target="blank">TextLineMetrics</a> class which will contain information about the text position and pixel measurements of a line of text within a text field.</p>
<p>Anyhow the following example below displays two examples of the the StringUtils.as class in action. The first example takes a string and returns its width and height value which in turn uses the dimensions to display a blue rectangle. The Second examples takes in an array of strings and returns a number which represents the widest string in the array, which in turn uses the width dimension to display a red rectangle.</p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_StringHelper_229347489"
			class="flashmovie"
			width="250"
			height="200">
	<param name="movie" value="http://www.codingcolor.com/wp-content/uploads/2011/01/StringHelper.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.codingcolor.com/wp-content/uploads/2011/01/StringHelper.swf"
			name="fm_StringHelper_229347489"
			width="250"
			height="200">
	<!--<![endif]-->
		
<p><a href="http://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>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>Here&#8217;s the StringUtils.as class in its entirety. </p>
<p><code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #3f5fbf;">/************************************<br />
* @author : Manuel Gonzalez &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* @blog &nbsp; : www.codingcolor.com &nbsp; &nbsp; *<br />
* @email &nbsp;: design@stheory.com &nbsp; &nbsp; &nbsp;*<br />
* @www&nbsp; &nbsp; : www.stheory.com &nbsp; &nbsp; &nbsp; &nbsp; *<br />
************************************/</span><br />
<span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>utils<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">AntiAliasType</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormatAlign</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextLineMetrics</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> StringUtils<br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> StringUtils<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: getTextLineWidth<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; inStr:String<br />
&nbsp; &nbsp; &nbsp; &nbsp; inFont:Font<br />
&nbsp; &nbsp; &nbsp; &nbsp; inTextFormat:TextFormat=null<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Number<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getTextLineWidth<span style="color: #000000;">&#40;</span>inStr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> inFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">,</span>inTextFormat<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> tFormat<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>inTextFormat == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> = <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">TextFormatAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">font</span> = inFont<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">fontName</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rightMargin</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat = inTextFormat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> testField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span> = <span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">multiline</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">wordWrap</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">embedFonts</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">antiAliasType</span> = <span style="color: #004993;">AntiAliasType</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADVANCED</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">defaultTextFormat</span> = tFormat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = inStr<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: getTextLineHeight<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; inStr:String<br />
&nbsp; &nbsp; &nbsp; &nbsp; inFont:Font<br />
&nbsp; &nbsp; &nbsp; &nbsp; inTextFormat:TextFormat=null<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Number<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getTextLineHeight<span style="color: #000000;">&#40;</span>inStr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> inFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">,</span>inTextFormat<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> tFormat<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>inTextFormat == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> = <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">TextFormatAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">font</span> = inFont<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">fontName</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rightMargin</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat = inTextFormat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> testField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span> = <span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">multiline</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">wordWrap</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">embedFonts</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">antiAliasType</span> = <span style="color: #004993;">AntiAliasType</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADVANCED</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">defaultTextFormat</span> = tFormat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = inStr<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: getTextWidthAndHeight<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; inStr:String<br />
&nbsp; &nbsp; &nbsp; &nbsp; inFont:Font<br />
&nbsp; &nbsp; &nbsp; &nbsp; inTextFormat:TextFormat=null<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Object {width:,height:}<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getTextWidthAndHeight<span style="color: #000000;">&#40;</span>inStr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> inFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">,</span>inTextFormat<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span>=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> textObj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> tFormat<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>inTextFormat == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> = <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">TextFormatAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">font</span> = inFont<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">fontName</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rightMargin</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat = inTextFormat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> testField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span> = <span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">multiline</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">wordWrap</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">embedFonts</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">antiAliasType</span> = <span style="color: #004993;">AntiAliasType</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADVANCED</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">defaultTextFormat</span> = tFormat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = inStr<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textObj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; textObj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> textObj<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: getWidthOfLongestStringInArray<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; inArray:Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; inFont<br />
&nbsp; &nbsp; &nbsp; &nbsp; inTextFormat=null<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Number<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> getWidthOfLongestStringInArray<span style="color: #000000;">&#40;</span>inArray<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">,</span>inFont<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Font</span><span style="color: #000066; font-weight: bold;">,</span>inTextFormat=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> wResult<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> tFormat<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>inTextFormat == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> = <span style="color: #000000; font-weight:bold;">12</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">align</span> = <span style="color: #004993;">TextFormatAlign</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">font</span> = inFont<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">fontName</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">rightMargin</span> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><span style="color: #0033ff; font-weight: bold;">else</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tFormat = inTextFormat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> len<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = inArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> =<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> len<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> testField<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">TextField</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextField</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">autoSize</span> = <span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">LEFT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">multiline</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">wordWrap</span> = <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">embedFonts</span> = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">antiAliasType</span> = <span style="color: #004993;">AntiAliasType</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADVANCED</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">defaultTextFormat</span> = tFormat<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = inArray<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> stringWidth<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">Math</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">floor</span><span style="color: #000000;">&#40;</span>testField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>stringWidth <span style="color: #000066; font-weight: bold;">&gt;</span> wResult<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; wResult = stringWidth<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> wResult<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>The download provides the above example including the StringUtils.as class.<br />
Enjoy!</p>
<a class="downloadlink" href="http://www.codingcolor.com/downloads/StringHelper.zip" title="Version1.0 downloaded 27 times" >StringHelper (27)</a>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/as3/whats-my-text-string-width-or-height/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook country list</title>
		<link>http://www.codingcolor.com/as3/facebook-country-list/</link>
		<comments>http://www.codingcolor.com/as3/facebook-country-list/#comments</comments>
		<pubDate>Sun, 19 Dec 2010 21:09:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[countries]]></category>
		<category><![CDATA[country list]]></category>
		<category><![CDATA[Facebook]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[ISO]]></category>
		<category><![CDATA[support]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=3431</guid>
		<description><![CDATA[Facebook, Facebook, Facebook, how I despise thee. I&#8217;m in the middle of developing a Flash based Facebook application, which requires the ability for a user to view particular images in Facebook supported countries. I assumed Facebook had some sort of API which would return the countries they support. But as it turns out, they dont. [...]]]></description>
			<content:encoded><![CDATA[<p>Facebook, Facebook, Facebook, how I despise thee. I&#8217;m in the middle of developing a Flash based Facebook application, which requires the ability for a user to view particular images in Facebook supported countries. I assumed Facebook had some sort of API which would return the countries they support. But as it turns out, they dont. Facebook groups countries by locale and language as demonstrated by Facebook&#8217;s locale xml :  <a href="http://www.facebook.com/translations/FacebookLocales.xml" target="blank"><u> http://www.facebook.com/translations/FacebookLocales.xml</u></a> .<br />
Not really usable in regards to what I need, but I can work with it. The widget below is a tool I created which takes the FacebookLocales.xml and the <a href="http://www.iso.org/iso/country_codes/iso_3166_code_lists.htm" target="blank"><u>ISO 3166 code lists</u></a> and spits out the countries that Facebook supports, in either xml format or an array of objects. I thought this would be useful for you other flash devs out there.<br />

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_fb_934167966"
			class="flashmovie"
			width="500"
			height="600">
	<param name="movie" value="http://www.stheory.com/codingColor/facebook/fb.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.stheory.com/codingColor/facebook/fb.swf"
			name="fm_fb_934167966"
			width="500"
			height="600">
	<!--<![endif]-->
		
<p><a href="http://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>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The code is quite simple :</p>
<p><code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #3f5fbf;">/****************************<br />
* Manuel Gonzalez &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* design@stheory.com &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* www.stheory.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* www.codingcolor.com &nbsp; &nbsp; &nbsp; *<br />
*****************************/</span><br />
<span style="color: #9900cc; font-weight: bold;">package</span> <br />
<span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Security</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.system</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">System</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>TextArea<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>RadioButton<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>RadioButtonGroup<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLLoader</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequest</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Loader</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Dictionary</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> DocApp <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> facebookXml<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;FacebookLocales.xml&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> isoXml<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;iso_3166-1_list_en.xml&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> facebookCountryCodes<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> isoDataArray<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> finalCountriesData<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> outputField<span style="color: #000066; font-weight: bold;">:</span>TextArea<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> printOutputButton<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> clipBoardButton<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> rbg<span style="color: #000066; font-weight: bold;">:</span>RadioButtonGroup<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> DocApp<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">Security</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">loadPolicyFile</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;your_path_to_cross_domain.xml&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createUI<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;loading data&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadXML<span style="color: #000000;">&#40;</span>facebookXml<span style="color: #000066; font-weight: bold;">,</span> fbXMLLoaded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: loadXML<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: <br />
&nbsp; &nbsp; &nbsp; &nbsp; inPath:String<br />
&nbsp; &nbsp; &nbsp; &nbsp; inCallback:Function<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> loadXML<span style="color: #000000;">&#40;</span>inPath<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> inCallback<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Function</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> req<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span>inPath<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> inCallback<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">loader</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>req<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: fbXMLLoaded<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: evt:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> fbXMLLoaded<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> theXml<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parseFbXml<span style="color: #000000;">&#40;</span>theXml<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arrayRemoveDup<span style="color: #000000;">&#40;</span>facebookCountryCodes<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loadXML<span style="color: #000000;">&#40;</span>isoXml<span style="color: #000066; font-weight: bold;">,</span> isoXMLLoaded<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: isoXMLLoaded<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: evt:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> isoXMLLoaded<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> theXml<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parseIsoXml<span style="color: #000000;">&#40;</span>theXml<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; buildCountryData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Data Ready&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: parseIsoXml<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: inXml:XML<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> parseIsoXml<span style="color: #000000;">&#40;</span>inXml<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = inXml <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">XML</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isoDataArray = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> numCountries<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>ISO_3166_1_Entry<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> numCountries<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> current<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>ISO_3166_1_Entry<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> cObj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span> = <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cObj<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span> = current<span style="color: #000066; font-weight: bold;">.</span>ISO_3166_1_Alpha_2_Code_element<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cObj<span style="color: #000066; font-weight: bold;">.</span>label = current<span style="color: #000066; font-weight: bold;">.</span>ISO_3166_1_Country_name<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; isoDataArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>cObj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: parseFbXml<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: inXml:XML<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> parseFbXml<span style="color: #000000;">&#40;</span>inXml<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = inXml <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">XML</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; facebookCountryCodes = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> numLocales<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>locale<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> =<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">&lt;</span> numLocales<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> current<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>locale<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> rep<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = current<span style="color: #000066; font-weight: bold;">.</span>codes<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">code</span><span style="color: #000066; font-weight: bold;">.*.</span>representation<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> pos<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = rep<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;_&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> countryCode<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = rep<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">substr</span><span style="color: #000000;">&#40;</span>pos <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; facebookCountryCodes<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>countryCode<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: buildCountryData<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> buildCountryData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> len<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = facebookCountryCodes<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finalCountriesData = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> len<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> codeStr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = facebookCountryCodes<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> isolen<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = isoDataArray<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> j <span style="color: #000066; font-weight: bold;">&lt;</span> isolen<span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>codeStr<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toLowerCase</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> == isoDataArray<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toLowerCase</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finalCountriesData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span>isoDataArray<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: createUI<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createUI<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField = <span style="color: #0033ff; font-weight: bold;">new</span> TextArea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span>setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">500</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">500</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">40</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>outputField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printOutputButton = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printOutputButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">75</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printOutputButton<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">450</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printOutputButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;Print&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printOutputButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;textFormat&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Arial&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printOutputButton<span style="color: #000066; font-weight: bold;">.</span>toggle = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printOutputButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> printToOutputField<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>printOutputButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clipBoardButton = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clipBoardButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">125</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clipBoardButton<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">225</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">550</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clipBoardButton<span style="color: #000066; font-weight: bold;">.</span>label = <span style="color: #990000;">&quot;Copy To Clipboard&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clipBoardButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;textFormat&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Arial&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clipBoardButton<span style="color: #000066; font-weight: bold;">.</span>toggle = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clipBoardButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> copyData<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>clipBoardButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rbg = <span style="color: #0033ff; font-weight: bold;">new</span> RadioButtonGroup<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;options&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createRadioButton<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Xml&quot;</span><span style="color: #000066; font-weight: bold;">,</span> rbg<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">225</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createRadioButton<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Array of Obj&quot;</span><span style="color: #000066; font-weight: bold;">,</span> rbg<span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">325</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: copyData<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: evt:MouseEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> copyData<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; copyToClipboard<span style="color: #000000;">&#40;</span>outputField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: printToOutputField<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: evt:MouseEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> printToOutputField<span style="color: #000000;">&#40;</span>evt<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rbg<span style="color: #000066; font-weight: bold;">.</span>selection == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>rbg<span style="color: #000066; font-weight: bold;">.</span>selection<span style="color: #000066; font-weight: bold;">.</span>label == <span style="color: #990000;">&quot;Xml&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printXMLToOutput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; printObjArrayToOutput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: createRadioButton<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; rbLabel:String<br />
&nbsp; &nbsp; &nbsp; &nbsp; rbg:RadioButtonGroup<br />
&nbsp; &nbsp; &nbsp; &nbsp; xpos:Number<br />
&nbsp; &nbsp; &nbsp; &nbsp; ypos:Number<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createRadioButton<span style="color: #000000;">&#40;</span>rbLabel<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> rbg<span style="color: #000066; font-weight: bold;">:</span>RadioButtonGroup<span style="color: #000066; font-weight: bold;">,</span>xpos<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span>ypos<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> rb<span style="color: #000066; font-weight: bold;">:</span>RadioButton = <span style="color: #0033ff; font-weight: bold;">new</span> RadioButton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rb<span style="color: #000066; font-weight: bold;">.</span>group = rbg<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rb<span style="color: #000066; font-weight: bold;">.</span>label = rbLabel<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rb<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span>xpos<span style="color: #000066; font-weight: bold;">,</span> ypos<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>rb<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: copyToClipboard<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: inTf:*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> copyToClipboard<span style="color: #000000;">&#40;</span>inTf<span style="color: #000066; font-weight: bold;">:*</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">System</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setClipboard</span><span style="color: #000000;">&#40;</span>inTf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: printObjArrayToOutput<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> printObjArrayToOutput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finalCountriesData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sortOn</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;label&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> len<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = finalCountriesData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">'var facebookCountries:Array = ['</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> len<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>i == len <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'{value:'</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'&quot;'</span><span style="color: #000066; font-weight: bold;">+</span>finalCountriesData<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'&quot;'</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">',label:&quot;'</span><span style="color: #000066; font-weight: bold;">+</span>finalCountriesData<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'&quot;}];'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'{value:&quot;'</span><span style="color: #000066; font-weight: bold;">+</span>finalCountriesData<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'&quot;,label:&quot;'</span><span style="color: #000066; font-weight: bold;">+</span>finalCountriesData<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'&quot;},<span style="">\n</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: printXMLToOutput<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> printXMLToOutput<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">'&lt;facebook_countries_en xml:lang=&quot;en&quot;&gt; <span style="">\n</span>'</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; finalCountriesData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">sortOn</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;label&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> len<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = finalCountriesData<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> len<span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'&lt;country_entry&gt; <span style="">\n</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">' &lt;country_code&gt;'</span><span style="color: #000066; font-weight: bold;">+</span>finalCountriesData<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'&lt;/country_code&gt; <span style="">\n</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">' &lt;country_name&gt;'</span><span style="color: #000066; font-weight: bold;">+</span>finalCountriesData<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">.</span>label<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">'&lt;/country_code&gt; <span style="">\n</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'&lt;/country_entry&gt; <span style="">\n</span>'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; outputField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">appendText</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">'&lt;facebook_countries_en&gt;'</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009966; font-style: italic;">/***************** HELPER METHODS *********************************/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; Method: arrayRemoveDup<br />
&nbsp; &nbsp; &nbsp; &nbsp; Parameters: inArry:Array<br />
&nbsp; &nbsp; &nbsp; &nbsp; Returns:<br />
&nbsp; &nbsp; &nbsp; &nbsp; */</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> arrayRemoveDup<span style="color: #000000;">&#40;</span>inArry<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> i<span style="color: #000066; font-weight: bold;">,</span>j<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">int</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>i = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> i <span style="color: #000066; font-weight: bold;">&lt;</span> inArry<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span> i<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>j = i <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000066; font-weight: bold;">;</span> j <span style="color: #000066; font-weight: bold;">&lt;</span> inArry<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span><span style="color: #000066; font-weight: bold;">;</span> j<span style="color: #000066; font-weight: bold;">++</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>inArry<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> === inArry<span style="color: #000000;">&#91;</span>j<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inArry<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">splice</span><span style="color: #000000;">&#40;</span>j<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>The code loads up FacebookLocale.xml, parses it and creates a facebook country code array. I proceed by removing duplicates in the array. Next, I load up the countries ISO xml , parse it and create a countries ISO data array with objects that contain the country name and country code. Lastly, I build my final country array by taking the Facebook country codes and searching for them in the countries ISO data array. If a country is found the ISO data Object is pushed to the final array. The rest of the code supports the UI.  I&#8217;ve included everything you need in the download below. To keep the country list up to date you should always download the necessary xml files:<br />
<a href="http://www.facebook.com/translations/FacebookLocales.xml" target="blank"><br />
<u>FacebookLocale.xml</u></a><br />
<a href="http://www.iso.org/iso/iso_3166-1_list_en.zip" target="blank"><u>iso_3166-1_list_en.zip</u></a></p>
<p>Also, Flash does not like the dash&#8217;s in the iso_3166-1_list_en.xml. If you download the zip from ISO and compare it with the xml I provided for you in the download, you will notice I replaced the dash with an underscore.<br />
**** NOTE the duplicate function is not efficient, look over your output for doubles. I&#8217;ll release the fix when I get around to it. If you solved it, please post it &#8230;keep ActionScript open source.<br />
Anyhow, enjoy!</p>
<a class="downloadlink" href="http://www.codingcolor.com/downloads/facebook_countries.zip" title="Version0.01 downloaded 36 times" >Facebook country list (36)</a>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/as3/facebook-country-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flash CS4 Test Movie = Blank Screen</title>
		<link>http://www.codingcolor.com/as3/flash-cs4-test-movie-blank-screen/</link>
		<comments>http://www.codingcolor.com/as3/flash-cs4-test-movie-blank-screen/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 20:52:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Blank Screen]]></category>
		<category><![CDATA[fix]]></category>
		<category><![CDATA[Flash CS4]]></category>
		<category><![CDATA[Flash Player]]></category>
		<category><![CDATA[test movie]]></category>
		<category><![CDATA[White Screen]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=3143</guid>
		<description><![CDATA[I&#8217;ve been freelancing at AKQA San Francisco for a few weeks and have experienced an annoying bug in the Flash CS4 IDE. I feel it warrants a posting, since, some of you may be experiencing the same issue with the IDE. As a flash developer you are dependent on testing (CTRL+ENTER) your movie locally versus [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been freelancing at <a href="http://www.akqa.com/" target="blank"><u>AKQA San Francisco</u></a> for a few weeks and have experienced an annoying bug in the Flash CS4 IDE. I feel it warrants a posting, since, some of you may be experiencing the same issue with the IDE. As a flash developer you are dependent on testing (CTRL+ENTER) your movie locally versus in the browser, especially if you are creating animations or pixel pushing and want to see the changes immediately. I started to notice the bug sporadically when compiling my file. The flash player would display the stage and assets for a few seconds then go blank. I thought it was my code, so I started debugging, trying to figure out where the problem stemmed from. As I continued debugging, I noticed the issue becoming progressively worse, until I could no longer test the movie locally. I finally broke down and searched Google for the issue. I came across the Adobe forums where a few developers had reported the bug back in August of &#8217;09. Thanks to the efforts of Adobe&#8217;s <a href="http://flashthusiast.com/" target="blank"><u> Jen Dehaan</u></a> for tracking and elevating the issue within Adobe, they eventually offered a solution. </p>
<p>&#8220;The issue stemmed from creating dynamic bitmaps using ActionScript and tweening.</p>
<p> Whatever the case, we don&#8217;t have to deal with this annoying bug, just download the fix and you will be testing your movies in no time.<br />
<a href="http://download.macromedia.com/pub/flash/updates/10_0_3/Flash_10_0_3_A dobeUpdate.dmg" target="blank"><u>http://download.macromedia.com/pub/flash/updates/10_0_3/Flash_10_0_3_A dobeUpdate.dmg</u></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/as3/flash-cs4-test-movie-blank-screen/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Obscuring network data with base64</title>
		<link>http://www.codingcolor.com/as3/obscuring-network-data-with-base64/</link>
		<comments>http://www.codingcolor.com/as3/obscuring-network-data-with-base64/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 00:18:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[base64]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=2621</guid>
		<description><![CDATA[When meeting with clients and potential employers, I&#8217;m often asked If I have experience working with API&#8217;s (application programming interface). The answer is yes, and then I follow up with, &#8220;Have you reviewed my blog?&#8221; Just recently, I was asked the API question in an interview and a few minutes later the interviewer wrote this [...]]]></description>
			<content:encoded><![CDATA[<p>When meeting with clients and potential employers, I&#8217;m often asked If I have experience working with API&#8217;s (application programming interface). The answer is yes, and then I follow up with, &#8220;Have you reviewed my blog?&#8221;  Just recently, I was asked the API question in an interview and a few minutes later the interviewer wrote this pseudo code on the dry erase board.</p>
<p><code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #6699cc; font-weight: bold;">var</span> _username<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> _password<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> _apiUrl<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> logIn<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
<span style="color: #000000;">&#123;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> path<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = _apiUrl <span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;&amp;&quot;</span><span style="color: #000066; font-weight: bold;">+</span>_username <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;&amp;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> _password<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span>_path<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
_loader = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
_loader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>Then proceeded to ask, &#8220;What&#8217;s wrong with this code?&#8221;  Well, I looked over the method and pointed out that the code wasn&#8217;t complete, but the engineer replied, just assume that the syntax is correct and all variables needed are present. The only thing that came to mind, when dealing with API&#8217;s, is that there is usually some type of security measure, usually in the form of a user token or session variable. I felt like I was being tricked, the only other answer I could provide was to encrypt the string to secure the data  passing over the network, and in short, that&#8217;s the answer they were looking for. They should have asked, &#8220;How would you protect the users login data when submitting it to an API?&#8221;  Thanks for the trick question, guys, but as you know almost every API has a different strategy in handling security.</p>
<p>Creating secure SWF applications is not an easy task. The best way to protect your sensitive data is to leverage the HTTPS protocol for sending encrypted data instead of performing the encryption within ActionScript code. Unfortunately, we cant always hide behind HTTPS and It is not advisable to permit HTTP content to access HTTPS content.</p>
<p>There are several strategies to encrypt data in SWF web applications. The most popular are hashing algorithms and symmetric and asymmetric ciphers. Hashing algorithms is a method for performing non-reversible encryption that transforms the original text into a unique string, or hash. The hash is non-reversible, meaning it can not be decrypted and is usually stored on disk. This method is usually used as password authentication and storage. Symmetric and asymmetric ciphers are useful when you want to create a reversible encryption of data, however, the secret and private keys for these tools are usually stored in the SWF, which can be exposed using a decompiler. You can try to hide the key from a decompiler by using a flash obfuscation software, tho I have never implemented this method, I can not advise doing so.</p>
<p>This post is not about Flash security, because I&#8217;m not a security expert, it&#8217;s about base64 encoding. </p>
<p>Exactly what is Base64 encoding? Base64 encoding is a scheme that encodes arbitrary binary data as a string composed from a set of 64 characters. The exact character set can be any 64 distinct ASCII characters, but by far the most common set is &#8220;A&#8221; through &#8220;Z,&#8221; &#8220;a&#8221; through &#8220;z,&#8221; &#8220;0&#8243; through &#8220;9,&#8221; &#8220;+,&#8221; and &#8220;/.&#8221;  Base64 encoding is used by many applications to &#8220;obscure&#8221; data when it travels across the network. Base64 encoding does not implement a cryptographic algorithm to protect sensitive information, yet is often used in many networks and end-user applications to my amazement.</p>
<p>I recently developed a sweepstakes micro-site for a client, which prerequisite was to obscure users personal data over the network. Since base encoding visually hides otherwise easily recognized information, It satisfied the prerequisite, with an understanding that it was not a secure method and the client signed off on it.</p>
<p>I scripted up a quick little demo app which shows you how to use Base64 encoding. </p>

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="fm_base64example_2045202985"
			class="flashmovie"
			width="400"
			height="250">
	<param name="movie" value="http://www.codingcolor.com/wp-content/uploads/2010/06/base64example.swf" />
	<!--[if !IE]>-->
	<object	type="application/x-shockwave-flash"
			data="http://www.codingcolor.com/wp-content/uploads/2010/06/base64example.swf"
			name="fm_base64example_2045202985"
			width="400"
			height="250">
	<!--<![endif]-->
		
<p><a href="http://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>

	<!--[if !IE]>-->
	</object>
	<!--<![endif]-->
</object>
<p>The demo gathers the users input, encodes it in a JSON object, encodes the object using base64, and passes it to the server where a php script receives it, decodes the base64 JSON object and then passes it back to the flash app. As you noticed, I may have added a complexity by using JSON. JSON is your friend, the JSON format is often used for serializing  and transmitting structured data over a network connection. It is primarily used to transmit data between a server and web application, serving as an alternative to XML. I have become accustomed to using it over the years, so I just left it in my code, just for clarification you can use a simple string.</p>
<p>Lets take a look at the demo. I created this app in CS4 using the UI flash components. As most flash apps start out, I created a Main document class:</p>
<p><strong>Main.as</strong><br />
<code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #3f5fbf;">/****************************<br />
* Manuel Gonzalez &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* design@stheory.com &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* www.stheory.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* www.codingcolor.com &nbsp; &nbsp; &nbsp; *<br />
*****************************/</span><br />
<span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> fl<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>TextArea<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextField</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFieldAutoSize</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">TextFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>stheory<span style="color: #000066; font-weight: bold;">.</span>view<span style="color: #000066; font-weight: bold;">.</span>LoginForm<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>stheory<span style="color: #000066; font-weight: bold;">.</span>business<span style="color: #000066; font-weight: bold;">.</span>LoginProxy<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span><br />
<br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _logInView<span style="color: #000066; font-weight: bold;">:</span>LoginForm<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _logInProxy<span style="color: #000066; font-weight: bold;">:</span>LoginProxy<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _traceField<span style="color: #000066; font-weight: bold;">:</span>TextArea<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _okButton<span style="color: #000066; font-weight: bold;">:</span>Button<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: showLoginView<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> showLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView = <span style="color: #0033ff; font-weight: bold;">new</span> LoginForm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span>=<span style="color: #000000; font-weight:bold;">20</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span>=<span style="color: #000000; font-weight:bold;">50</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>submitData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_logInView<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: removeLoginView<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>submitData<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInView<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>_logInView<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: submitData<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> submitData<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; createTraceField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> loginObj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span>=<span style="color: #000000;">&#123;</span>username<span style="color: #000066; font-weight: bold;">:</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>username<span style="color: #000066; font-weight: bold;">,</span>password<span style="color: #000066; font-weight: bold;">:</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>password<span style="color: #000066; font-weight: bold;">,</span>remember<span style="color: #000066; font-weight: bold;">:</span>event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>rememberMe<span style="color: #000000;">&#125;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy=LoginProxy<span style="color: #000066; font-weight: bold;">.</span>getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>logInComplete<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000066; font-weight: bold;">,</span>logInError<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span>submitFormData<span style="color: #000000;">&#40;</span>loginObj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: logInComplete<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> logInComplete<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> results=event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>scriptResult<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=results<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>logInComplete<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000066; font-weight: bold;">,</span>logInError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> logInError<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> results= event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span><span style="color: #000066; font-weight: bold;">.</span>errorEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span>=results<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span>logInComplete<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _logInProxy<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000066; font-weight: bold;">,</span>logInError<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: createTraceField<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> createTraceField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField = <span style="color: #0033ff; font-weight: bold;">new</span> TextArea<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField<span style="color: #000066; font-weight: bold;">.</span>setSize<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">350</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _traceField<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">25</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">25</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_traceField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton = <span style="color: #0033ff; font-weight: bold;">new</span> Button<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">75</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span>move<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">300</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">135</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span>label=<span style="color: #990000;">&quot;OK&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setStyle</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;textFormat&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">TextFormat</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Arial&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span>toggle=<span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span> okClick<span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">false</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>_okButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: okClick<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:MouseEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> okClick<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeTraceField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; showLoginView<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: removeTraceField<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeTraceField<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _okButton<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">removeEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CLICK</span><span style="color: #000066; font-weight: bold;">,</span>okClick<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>_traceField<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">removeChild</span><span style="color: #000000;">&#40;</span>_okButton<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
<br />
<br />
<br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>The Main.as class simply instantiates a logIn view, logIn proxy and creates a trace/log view to print out the interactions with the server.  I&#8217;m going to skip the logIn view, just assume that all it does is set up the login UI and dispatches an event when the Submit button is pressed. The class that we will focus on is the LogInProxy.as. I utilize <a href="http://dynamicflash.com/goodies/base64/" target="blank"><u>Steve Websters</u></a> base64 encoder/decoder class and the <a href="http://code.google.com/p/as3corelib/" target="blank"><u>AS3CoreLib</u></a> developed by Mike Chambers, Daniel Dura and Christian Cantrell for the JSON encoding.<br />
<strong>LogInProxy.as</strong><br />
<code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #3f5fbf;">/****************************<br />
* Manuel Gonzalez &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* design@stheory.com &nbsp; &nbsp; &nbsp; &nbsp;*<br />
* www.stheory.com &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *<br />
* www.codingcolor.com &nbsp; &nbsp; &nbsp; *<br />
*****************************/</span><br />
<span style="color: #9900cc; font-weight: bold;">package</span> com<span style="color: #000066; font-weight: bold;">.</span>stheory<span style="color: #000066; font-weight: bold;">.</span>business<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">EventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLLoader</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLLoaderDataFormat</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequest</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLRequestMethod</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">URLVariables</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>adobe<span style="color: #000066; font-weight: bold;">.</span>serialization<span style="color: #000066; font-weight: bold;">.</span>json<span style="color: #000066; font-weight: bold;">.</span>JSON<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> com<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>Base64<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
<br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> LoginProxy <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> static &nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> _instance<span style="color: #000066; font-weight: bold;">:</span>LoginProxy<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _loader<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _formObj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _encryption<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _path<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;http://www.stheory.com/stheory/downloads/scripts/securityTest.php&quot;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _errorEvent<span style="color: #000066; font-weight: bold;">:*;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> _testScriptResult<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> LoginProxy<span style="color: #000000;">&#40;</span>singletonEnforcer<span style="color: #000066; font-weight: bold;">:</span>SingletonEnforcer<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: getInstance<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: AppServices <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> static &nbsp;<span style="color: #339966; font-weight: bold;">function</span> getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>LoginProxy <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>_instance == <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _instance=<span style="color: #0033ff; font-weight: bold;">new</span> LoginProxy<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> SingletonEnforcer &nbsp;<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _instance<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">////////////// Getters ///////////////////////</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> scriptResult<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #990000;">&quot;base64 to server :<span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span>_encryption <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span><span style="">\n</span>Results from Server :<span style="">\n</span>&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> _testScriptResult<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> errorEvent<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> _errorEvent<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//////////////////////////////////////////</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: submitFormData<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inObj:Object<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> submitFormData<span style="color: #000000;">&#40;</span>inObj<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _formObj = inObj<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; encodeAndEncryptData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sendData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: encodeAndEncryptData<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> encodeAndEncryptData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> jStr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = JSON<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>_formObj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _encryption &nbsp;= Base64<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>jStr<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: sendData<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> sendData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> dataVars<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLVariables</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLVariables</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataVars<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = &nbsp;_encryption<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">URLRequest</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span>_path<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">method</span> = <span style="color: #004993;">URLRequestMethod</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">POST</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span> = dataVars<span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _loader = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; configureListeners<span style="color: #000000;">&#40;</span>_loader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _loader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span>request<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Unable to load URL&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _errorEvent = <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: configureListeners<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dispatcher:IEventDispatcher<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> configureListeners<span style="color: #000000;">&#40;</span>dispatcher<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> completeHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SECURITY_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> securityErrorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> ioErrorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: removeListeners<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;dispatcher:IEventDispatcher<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> removeListeners<span style="color: #000000;">&#40;</span>dispatcher<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IEventDispatcher</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000066; font-weight: bold;">,</span> completeHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SECURITY_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> securityErrorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dispatcher<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">IO_ERROR</span><span style="color: #000066; font-weight: bold;">,</span> ioErrorHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: completeHandler<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:Event<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> completeHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Event</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> result = _loader<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _testScriptResult = result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">COMPLETE</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _errorEvent = <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; removeListeners<span style="color: #000000;">&#40;</span>_loader<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _loader=<span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: securityErrorHandler<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:SecurityErrorEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> securityErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">SecurityErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot;securityErrorHandler: &quot; + event + &quot; \n\n&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _errorEvent = event<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #3f5fbf;">/*<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Method: ioErrorHandler<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Parameters:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;event:IOErrorEvent<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Returns: &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*/</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> ioErrorHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">IOErrorEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//trace(&quot;ioErrorHandler: &quot; + event + &quot; \n\n&quot;);</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _errorEvent = event<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">dispatchEvent</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Event</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">Event</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CANCEL</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">internal</span> <span style="color: #9900cc; font-weight: bold;">class</span> SingletonEnforcer <span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>I created the LogInProxy class as a<a href="http://en.wikipedia.org/wiki/Singleton_pattern" target="blank"><u> Singleton pattern</u></a>, because I only want to make one object which will handle the data transaction between the client side and the server. LoginProxy is responsible for  the base64 encoding, it also submits the data and reports the results. Review the encodeAndEncryptData() method:</p>
<p><code class="codecolorer actionscript3 mac-classic"><span class="actionscript3">&nbsp;<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> encodeAndEncryptData<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> &nbsp;<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #6699cc; font-weight: bold;">var</span> jStr<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = JSON<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>_formObj<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _encryption &nbsp;= Base64<span style="color: #000066; font-weight: bold;">.</span>encode<span style="color: #000000;">&#40;</span>jStr<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span></span></code></p>
<p>this is where all the magic happens. You can revise this method to meet your needs, for example remove the option of using JSON and just use a simple string. The SendData method, does what it implies, pretty straight forward. Now, lets take a look at the Php.</p>
<p>The Php script is really simple and was created just for this demo:<br />
<code class="codecolorer php mac-classic"><span class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #000088;">$data</span><span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'data'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<span style="color: #000088;">$decoded</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base64_decode</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$decoded</span>&quot;</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></span></code></p>
<p>It receives the base64 encoded data, decodes it and prints it back to Flash.  </p>
<p>Now, for a sanity check, I would recommend using a packet sniffer that captures network traffic, like <a href="http://kevinlangdon.com/serviceCapture/"><u>Service Capture</u></a>. Here&#8217;s a screenshot of the demo app in action:</p>
<p><img src="http://www.codingcolor.com/wp-content/uploads/2010/06/packetSniffer.jpg" alt="" title="packetSniffer" width="500" height="404" class="aligncenter size-full wp-image-2717" /></p>
<p>As you can see, we successfully passed an encoded string to the Php script, which in return passed back a JSON object.<br />
Its really that easy! I could have gone the extra mile and re-encoded a response in base64 and had Flash decode it, but I&#8217;ll leave that up to you.<br />
Enjoy!</p>
<p><strong>Download Source:</strong><br />
<a class="downloadlink" href="http://www.codingcolor.com/downloads/base64.zip" title="Version1.0 downloaded 29 times" >Base64 encoding example (29)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/as3/obscuring-network-data-with-base64/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AS3 load an image from the library</title>
		<link>http://www.codingcolor.com/as3/as3-load-an-image-from-the-library/</link>
		<comments>http://www.codingcolor.com/as3/as3-load-an-image-from-the-library/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 06:23:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[bitmap]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[sprite]]></category>

		<guid isPermaLink="false">http://www.codingcolor.com/?p=2450</guid>
		<description><![CDATA[I&#8217;m essentially posting this, as a response to search terms that people frequently use , which eventually direct them to an old posting on loading images. Unfortunately, the posting does not cover loading an image directly from the flash library, but the method is fairly simple. When you import a bitmap into Flash, you can [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m essentially posting this, as a response to search terms that people frequently use , which eventually direct them to an old <a href="http://www.codingcolor.com/as3/how-do-you-load-an-image-into-an-empty-movieclip-in-as-3-0/" target="blank"><u>posting</u></a> on loading images. Unfortunately, the posting does not cover loading an image directly from the flash library, but the method is fairly simple. When you import a bitmap into Flash, you can modify that bitmap and use it in a variety of ways, the simple usage is to display it via the linkage properties.</p>
<p>Open up the Flash IDE, presumably CS4 but CS3 will do.</p>
<p>Select File->Import->Import to Library..<br />
<img src="http://www.codingcolor.com/wp-content/uploads/2010/06/import.jpg" alt="" title="import" width="550" height="457" class="aligncenter size-full wp-image-2465" /><br />
Select your image to import.<br />
Now navigate to your library.<br />
<img src="http://www.codingcolor.com/wp-content/uploads/2010/06/library.jpg" alt="" title="library" width="550" height="287" class="aligncenter size-full wp-image-2492" /><br />
Double click on the bitmap asset to activate the Bitmap Properties panel:<br />
<img src="http://www.codingcolor.com/wp-content/uploads/2010/06/libraryExport.jpg" alt="" title="libraryExport" width="550" height="507" class="aligncenter size-full wp-image-2470" /></p>
<p>Navigate down to the linkage properties and select Export For ActionScript. You will notice that the Export in frame 1 checkbox will automatically be selected and the Class textfield will be highlighted. Go ahead and add an identifier string of your choice in the Class textfield and Select OK.  Essentially, Flash has generated a linked class by the specified identifier  automatically, which will allow you to have access to the Bitmap. All you have left to do is create a base class for your .fla and display your bitmap.</p>
<p>Open up your text editor and create a class like so:</p>
<p><code class="codecolorer actionscript3 mac-classic"><span class="actionscript3"><span style="color: #9900cc; font-weight: bold;">package</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">Bitmap</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Main <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> imageSprite<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Sprite</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Main<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; imageSprite = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Sprite</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//create an image container</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>imageSprite<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><span style="color: #009900; font-style: italic;">//add it to the display list</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; displayImageFromLibrary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> displayImageFromLibrary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">//instantiate the bitmap in the library by its identifier</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> libraryImage<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Bitmap</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Bitmap</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">new</span> kfc<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900; font-style: italic;">//place the image in the image container</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; imageSprite<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>libraryImage<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span></span></code></p>
<p>Save the class as Main.as and make sure its in the same folder as the fla.<br />
Navigate back to the Flash Ide and open the properties panel. Enter Main in the class textfield.<br />
<img src="http://www.codingcolor.com/wp-content/uploads/2010/06/properties_main.jpg" alt="" title="properties_main" width="550" height="361" class="aligncenter size-full wp-image-2480" /><br />
Once the program’s document class has been associated with the .fla we can now compile the program, Select-Control Test Movie. If all went well the desired results should have been achieved.<br />
<img src="http://www.codingcolor.com/wp-content/uploads/2010/06/imageFromLibrary.jpg" alt="" title="imageFromLibrary" width="550" height="561" class="aligncenter size-full wp-image-2497" /><br />
And there you have it.<br />
Photo by <a href="http://www.unaesthetic.net" target="_blank"><u>Chris Brennan</u></a>.<br />
<strong>Download Source:</strong><br />
<a class="downloadlink" href="http://www.codingcolor.com/downloads/LoadImageFromLibrary.zip" title="Version1.0 downloaded 55 times" >AS3 load Image from library (55)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.codingcolor.com/as3/as3-load-an-image-from-the-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

