<?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>Howtos &#187; Actionscript</title>
	<atom:link href="http://howto.isgoodness.com/tag/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://howto.isgoodness.com</link>
	<description>Stuffs that are worth to mention and worth to know</description>
	<lastBuildDate>Sun, 27 Feb 2011 16:19:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>ReferenceError #1065: can not create property 0 on &#8230; (and #1069)</title>
		<link>http://howto.isgoodness.com/2010/02/referenceerror-1065-can-not-create-property-0-on-and-1069/</link>
		<comments>http://howto.isgoodness.com/2010/02/referenceerror-1065-can-not-create-property-0-on-and-1069/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 13:20:44 +0000</pubDate>
		<dc:creator>Van Nhu</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[dynamic class]]></category>
		<category><![CDATA[reference error]]></category>
		<category><![CDATA[shuffle]]></category>

		<guid isPermaLink="false">http://howto.isgoodness.com/?p=422</guid>
		<description><![CDATA[Last week, I was trying to create a shuffle function on my array class which extends the native Array class. I got the ReferenceError when running the code bellow. The reason is that Array is a dynamic class and my is not. Since Array is dynamic, it will try to create new property when you [...]]]></description>
			<content:encoded><![CDATA[<p>Last week, I was trying to create a <a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle">shuffle </a>function on my array class which extends  the native Array class. I got the ReferenceError when running the code bellow. The reason is that Array is a dynamic class and my is not.  Since Array is dynamic, it will try to create new property when you try to assign some value to a nonexistent instance variable but MyArray prevents this. If you try this you will see that reference error #1065 is occurred when the array is constructed. If you remove the constructor you will get reference error #1069 instead and it hapens when you try to swap the elements in shuffle method (trying to access a nonexistent instance variable). So make sure that you declare dynamic if you extend a dynamic class or better if editor or compiler gives a warning if you forget &#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">&nbsp;
<span style="color: #9900cc; font-weight: bold;">package</span> vnmedia.common.lang
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> vnmedia.common.lang.math.Random;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> MyArray extends <span style="color: #004993;">Array</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> MyArray<span style="color: #000000;">&#40;</span>...<span style="color: #004993;">parameters</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">super</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">parameters</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> shuffle<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> a<span style="color: #000000; font-weight: bold;">:*</span>, k<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>, i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>, r<span style="color: #000000; font-weight: bold;">:</span>Random = <span style="color: #0033ff; font-weight: bold;">new</span> Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i = <span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">length</span>; i <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">1</span>; i<span style="color: #000000; font-weight: bold;">--</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
				<span style="color: #009900;">// 0 &lt;= k &lt;= i - 1</span>
				k = r.nextInt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
				a = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span>;
				<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span> = <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>;
				<span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000000;">&#91;</span>i<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> = a;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>However, I think the best way to provide a shuffle function for arrays is  to define a static ArrayUtil.shuffle as bellow</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> vnmedia.common.lang
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> vnmedia.common.lang.math.Random;
&nbsp;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> ArrayUtil
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> ArrayUtil<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> static <span style="color: #339966; font-weight: bold;">function</span> shuffle<span style="color: #000000;">&#40;</span>arr<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> a<span style="color: #000000; font-weight: bold;">:*</span>, k<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>, i<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">int</span>, r<span style="color: #000000; font-weight: bold;">:</span>Random = <span style="color: #0033ff; font-weight: bold;">new</span> Random<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span>i = arr.<span style="color: #004993;">length</span>; i <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">1</span>; i<span style="color: #000000; font-weight: bold;">--</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
				k = r.nextInt<span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span>;
				a = arr<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span>;
				arr<span style="color: #000000;">&#91;</span>k<span style="color: #000000;">&#93;</span> = arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span>;
				arr<span style="color: #000000;">&#91;</span>i<span style="color: #000000; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> = a;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://howto.isgoodness.com/2010/02/referenceerror-1065-can-not-create-property-0-on-and-1069/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Howto use vnkeys with TextField</title>
		<link>http://howto.isgoodness.com/2009/11/howto-use-vnkeys-with-textfield/</link>
		<comments>http://howto.isgoodness.com/2009/11/howto-use-vnkeys-with-textfield/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 21:00:06 +0000</pubDate>
		<dc:creator>Van Nhu</dc:creator>
				<category><![CDATA[vnkeys]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[key converter]]></category>
		<category><![CDATA[textfield]]></category>
		<category><![CDATA[typing vietnamese]]></category>

		<guid isPermaLink="false">http://howto.isgoodness.com/?p=310</guid>
		<description><![CDATA[vnkeys is originally designed to work with flash.text.TextField and you can feel it when typing. The replacement happens smoothly. It is easy to use and the code bellow will explain how to&#8230; package &#123; import flash.display.Sprite; import flash.text.TextField; import flash.text.TextFieldType; &#160; import org.vnmedia.vnkeys.KeyConverter; import org.vnmedia.vnkeys.mapping.VNIMap; // define swf dimension &#91;SWF&#40;width=160, height=60&#41;&#93; // this is an [...]]]></description>
			<content:encoded><![CDATA[<p>vnkeys is originally designed to work with flash.text.TextField and you can feel it when typing. The replacement happens smoothly. It is easy to use and the code bellow will explain how to&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> <span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span>.<span style="color: #004993;">Sprite</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextField</span>;
	<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span>.<span style="color: #004993;">TextFieldType</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.vnmedia.vnkeys.KeyConverter;
	<span style="color: #0033ff; font-weight: bold;">import</span> org.vnmedia.vnkeys.mapping.VNIMap;
	<span style="color: #009900;">// define swf dimension</span>
	<span style="color: #000000;">&#91;</span>SWF<span style="color: #000000;">&#40;</span><span style="color: #004993;">width</span>=<span style="color: #000000; font-weight:bold;">160</span>, <span style="color: #004993;">height</span>=<span style="color: #000000; font-weight:bold;">60</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #009900;">// this is an application class</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> vnmedia_vnkeys extends <span style="color: #004993;">Sprite</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> vnmedia_vnkeys<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> textinput<span style="color: #000000; 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: #009900;">// give this text input a size</span>
			<span style="color: #009900;">// and positioning it</span>
			textinput.<span style="color: #004993;">width</span> = <span style="color: #000000; font-weight:bold;">150</span>;
			textinput.<span style="color: #004993;">height</span> = <span style="color: #000000; font-weight:bold;">50</span>;
			textinput.<span style="color: #004993;">x</span> = <span style="color: #000000; font-weight:bold;">5</span>;
			textinput.<span style="color: #004993;">y</span> = <span style="color: #000000; font-weight:bold;">5</span>;
			<span style="color: #009900;">// use multiline, ie textarea</span>
			textinput.<span style="color: #004993;">multiline</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
			textinput.<span style="color: #004993;">type</span> = <span style="color: #004993;">TextFieldType</span>.<span style="color: #004993;">INPUT</span>;
			<span style="color: #009900;">// give it background white</span>
			<span style="color: #009900;">// so we can see what we are typing</span>
			textinput.<span style="color: #004993;">backgroundColor</span> = 0xFFFFFF;
			textinput.<span style="color: #004993;">background</span> = <span style="color: #0033ff; font-weight: bold;">true</span>;
			<span style="color: #009900;">// NOW create a converter</span>
			<span style="color: #009900;">// for this TextField instance</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> converter<span style="color: #000000; font-weight: bold;">:</span>KeyConverter =
				<span style="color: #0033ff; font-weight: bold;">new</span> KeyConverter<span style="color: #000000;">&#40;</span>textinput,VNIMap.NAME<span style="color: #000000;">&#41;</span>;
			<span style="color: #009900;">// add this text input to application</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>textinput<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The result:<br />
<object style="width: 160px; height: 60px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="160" height="60" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="scale" value="exactfit" /><param name="src" value="http://howto.isgoodness.com/wp-content/uploads/2009/11/vnmedia_vnkeys.swf" /><embed style="width: 160px; height: 60px;" type="application/x-shockwave-flash" width="160" height="60" src="http://howto.isgoodness.com/wp-content/uploads/2009/11/vnmedia_vnkeys.swf" scale="exactfit"></embed></object><br />
Type using <a href="http://howto.isgoodness.com/2009/10/how-to-type-vietnamese-with-vni-input-method-that-implemented-in-vnkeys/">VNI input method</a></p>
]]></content:encoded>
			<wfw:commentRss>http://howto.isgoodness.com/2009/11/howto-use-vnkeys-with-textfield/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to provide users options to switch on/off when using vnkeys</title>
		<link>http://howto.isgoodness.com/2009/10/how-to-provide-use-options-to-switch-onoff-when-using-vnkeys/</link>
		<comments>http://howto.isgoodness.com/2009/10/how-to-provide-use-options-to-switch-onoff-when-using-vnkeys/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 20:50:05 +0000</pubDate>
		<dc:creator>Van Nhu</dc:creator>
				<category><![CDATA[vnkeys]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[key converter]]></category>
		<category><![CDATA[mxml]]></category>
		<category><![CDATA[typing vietnamese]]></category>

		<guid isPermaLink="false">http://howto.isgoodness.com/?p=197</guid>
		<description><![CDATA[The goal of this post is to show how we can create a radio button group so users can switch on and off when using vnkeys as the swf above. To create TextArea and TextInput we use input components that follows vnkeys (see this how to for details). Bellow is our code example where we [...]]]></description>
			<content:encoded><![CDATA[<p><object style="width: 300px; height: 200px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="300" height="200" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://isgoodness.com/swf/vnkeys.swf" /><embed style="width: 300px; height: 200px;" type="application/x-shockwave-flash" width="300" height="200" src="http://isgoodness.com/swf/vnkeys.swf"></embed></object></p>
<p>The goal of this post is to show how we can create a radio button group so users can switch on and off when using vnkeys as the swf above. To create TextArea and TextInput we use input components that follows vnkeys (see <a href="http://howto.isgoodness.com/2009/10/how-to-use-vnkeys-with-flex/" target="_blank">this how to</a> for details). Bellow is our code example where we use flex RadioButtonGroup and RadioButton to create on/off options. We use Repeater to loop through options that we get from KeyConverter.getKeyMapOptions() This is done by calling init function initOptions() which fills element &#8220;options&#8221; with an array of available mapping types. On each option we attach function onMappingTypeChange as listener for onchange event so we can update mapping type on each KeyConverter instance.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span style="color: #000000;">	layout=<span style="color: #ff0000;">&quot;absolute&quot;</span></span>
<span style="color: #000000;">	 xmlns:flex=<span style="color: #ff0000;">&quot;org.vnmedia.flex.*&quot;</span> </span>
<span style="color: #000000;">	 creationComplete=<span style="color: #ff0000;">&quot;initOptions();&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #339933;">&lt;mx:Script&gt;</span>
<span style="color: #339933;">		&lt;![CDATA[</span>
<span style="color: #339933;">		import mx.controls.RadioButton;</span>
<span style="color: #339933;">		public function initOptions():void {</span>
<span style="color: #339933;">			options = area.getKeyConverter()</span>
<span style="color: #339933;">						.getKeyMapOptions();</span>
<span style="color: #339933;">		}</span>
<span style="color: #339933;">		public function onMappingTypeChange(e:Event):void {</span>
<span style="color: #339933;">			var radio:RadioButton = RadioButton(e.currentTarget);</span>
<span style="color: #339933;">			var item:Object = radio.getRepeaterItem();</span>
<span style="color: #339933;">			text.getKeyConverter().setMapType(item.data);</span>
<span style="color: #339933;">			area.getKeyConverter().setMapType(item.data);</span>
<span style="color: #339933;">		}</span>
<span style="color: #339933;">		]]&gt;</span>
<span style="color: #339933;">	&lt;/mx:Script&gt;</span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;flex:FlexTextArea</span> id=<span style="color: #ff0000;">&quot;area&quot;</span> vnkeyType=<span style="color: #ff0000;">&quot;VNI&quot;</span> </span>
<span style="color: #000000;">		height=<span style="color: #ff0000;">&quot;50&quot;</span> width=<span style="color: #ff0000;">&quot;220&quot;</span> x=<span style="color: #ff0000;">&quot;50&quot;</span> y=<span style="color: #ff0000;">&quot;50&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/flex:FlexTextArea</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;flex:FlexTextInput</span> id=<span style="color: #ff0000;">&quot;text&quot;</span> y=<span style="color: #ff0000;">&quot;120&quot;</span></span>
<span style="color: #000000;">		 x=<span style="color: #ff0000;">&quot;50&quot;</span> width=<span style="color: #ff0000;">&quot;220&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/flex:FlexTextInput</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Array</span> id=<span style="color: #ff0000;">&quot;options&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
   	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> id=<span style="color: #ff0000;">&quot;hb&quot;</span> x=<span style="color: #ff0000;">&quot;50&quot;</span> y=<span style="color: #ff0000;">&quot;150&quot;</span><span style="color: #7400FF;">&gt;</span></span>	
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RadioButtonGroup</span> id=<span style="color: #ff0000;">&quot;radioGroup&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Repeater</span> id=<span style="color: #ff0000;">&quot;radioRepeater&quot;</span></span>
<span style="color: #000000;">                dataProvider=<span style="color: #ff0000;">&quot;{options}&quot;</span><span style="color: #7400FF;">&gt;</span></span>
            <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:RadioButton</span> id=<span style="color: #ff0000;">&quot;radioButtons&quot;</span></span>
<span style="color: #000000;">                    label=<span style="color: #ff0000;">&quot;{radioRepeater.currentItem.label}&quot;</span></span>
<span style="color: #000000;">                    group=<span style="color: #ff0000;">&quot;{radioGroup}&quot;</span></span>
<span style="color: #000000;">                    change=<span style="color: #ff0000;">&quot;onMappingTypeChange(event);&quot;</span> <span style="color: #7400FF;">/&gt;</span></span>
        <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Repeater</span><span style="color: #7400FF;">&gt;</span></span>
    <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://howto.isgoodness.com/2009/10/how-to-provide-use-options-to-switch-onoff-when-using-vnkeys/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>how to use vnkeys with flex</title>
		<link>http://howto.isgoodness.com/2009/10/how-to-use-vnkeys-with-flex/</link>
		<comments>http://howto.isgoodness.com/2009/10/how-to-use-vnkeys-with-flex/#comments</comments>
		<pubDate>Sun, 25 Oct 2009 22:27:46 +0000</pubDate>
		<dc:creator>Van Nhu</dc:creator>
				<category><![CDATA[vnkeys]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[key converter]]></category>
		<category><![CDATA[mxml]]></category>
		<category><![CDATA[typing vietnamese]]></category>

		<guid isPermaLink="false">http://howto.isgoodness.com/?p=171</guid>
		<description><![CDATA[In the package org.vnmedia.flex we find two subclasses of Flex controls class. FlexTextInput is extending TextInput and FlexTextArea extending TextArea. Those two inherit all functionalities from their parent. We just added some more code handling the typing since TextInput and TextArea behaves unlike TextField. It is simple to use. You just need to declare namespace [...]]]></description>
			<content:encoded><![CDATA[<p>In the package org.vnmedia.flex we find two subclasses of Flex controls class. <a href="http://code.google.com/p/vnkeys/source/browse/branches/vni_and_flex/code/src/org/vnmedia/flex/FlexTextInput.as" target="_blank">FlexTextInput </a> is extending TextInput and <a href="http://code.google.com/p/vnkeys/source/browse/branches/vni_and_flex/code/src/org/vnmedia/flex/FlexTextArea.as" target="_blank">FlexTextArea </a> extending TextArea. Those two inherit all functionalities from their parent. We just added some more code handling the typing since TextInput and TextArea behaves unlike TextField. It is simple to use. You just need to declare namespace for org.vnmedia.flex, I call it &#8220;flex&#8221; in example bellow.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application xmlns<span style="color: #000000; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> 
	xmlns<span style="color: #000000; font-weight: bold;">:</span>flex=<span style="color: #990000;">&quot;org.vnmedia.flex.*&quot;</span>
	layout=<span style="color: #990000;">&quot;absolute&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>flex<span style="color: #000000; font-weight: bold;">:</span>FlexTextArea id=<span style="color: #990000;">&quot;area&quot;</span> vnkeyType=<span style="color: #990000;">&quot;VNI&quot;</span> 
		<span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;50&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;220&quot;</span> <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;50&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;50&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>flex<span style="color: #000000; font-weight: bold;">:</span>FlexTextArea<span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;</span>flex<span style="color: #000000; font-weight: bold;">:</span>FlexTextInput id=<span style="color: #990000;">&quot;text&quot;</span> <span style="color: #004993;">y</span>=<span style="color: #990000;">&quot;120&quot;</span>
		 <span style="color: #004993;">x</span>=<span style="color: #990000;">&quot;50&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;220&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
	<span style="color: #000000; font-weight: bold;">&lt;/</span>flex<span style="color: #000000; font-weight: bold;">:</span>FlexTextInput<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;/</span>mx<span style="color: #000000; font-weight: bold;">:</span>Application<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>You can type vietnamese using VNI input method (<a href="http://howto.isgoodness.com/2009/10/how-to-type-vietnamese-with-vni-input-method-that-implemented-in-vnkeys/" target="_blank">see</a>)<br />
<object style="width: 300px; height: 200px;" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="300" height="200" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://isgoodness.com/swf/flexvnkeys.swf" /><embed style="width: 300px; height: 200px;" type="application/x-shockwave-flash" width="300" height="200" src="http://isgoodness.com/swf/flexvnkeys.swf"></embed></object></p>
<p>vnkeys was designed to work well with Textfield. I guess that you feel that the replacement is a little bit annoying when using it with Flex TextInput and TextArea. <a href="http://isgoodness.com/swf/vnmedia_vnkeys.swf">Here is an example when using it with TextField</a>. It runs smoothly and you experience a bit faster. This is something that we will try to improve in the future version.</p>
]]></content:encoded>
			<wfw:commentRss>http://howto.isgoodness.com/2009/10/how-to-use-vnkeys-with-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to implement singleton pattern in actionscript 3</title>
		<link>http://howto.isgoodness.com/2009/10/how-to-implement-singleton-pattern-in-actionscript-3/</link>
		<comments>http://howto.isgoodness.com/2009/10/how-to-implement-singleton-pattern-in-actionscript-3/#comments</comments>
		<pubDate>Fri, 23 Oct 2009 20:02:30 +0000</pubDate>
		<dc:creator>Van Nhu</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[singleton]]></category>

		<guid isPermaLink="false">http://howto.isgoodness.com/?p=152</guid>
		<description><![CDATA[In actionscript 3 one can not use private scope for constructor and you need a workaround to implement simgleton pattern. Following is one way that I use package &#123; public class Singleton &#123; private static var instance:Singleton; private static var isAllowedInstance:Boolean; &#160; public function Singleton&#40;&#41; &#123; if &#40;!isAllowedInstance&#41; &#123; throw new Error&#40;&#34;Please use &#34; + [...]]]></description>
			<content:encoded><![CDATA[<p>In actionscript 3 one can not use private scope for constructor and you need a workaround to implement simgleton pattern. Following is one way that I use</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> Singleton
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> instance<span style="color: #000000; font-weight: bold;">:</span>Singleton;
		<span style="color: #0033ff; font-weight: bold;">private</span> static <span style="color: #6699cc; font-weight: bold;">var</span> isAllowedInstance<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Boolean</span>;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> Singleton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight: bold;">!</span>isAllowedInstance<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">throw</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Error</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Please use &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> 
						<span style="color: #990000;">&quot;Singleton.getInstance()&quot;</span> <span style="color: #000000; font-weight: bold;">+</span> 
						<span style="color: #990000;">&quot;instead of new keyword&quot;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;init stuffs&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> static <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: #000000; font-weight: bold;">:</span>Singleton <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">null</span> == instance<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				isAllowedInstance = <span style="color: #0033ff; font-weight: bold;">true</span>;
				instance = <span style="color: #0033ff; font-weight: bold;">new</span> Singleton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
				isAllowedInstance = <span style="color: #0033ff; font-weight: bold;">false</span>;
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> instance;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> singsing<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;singsing&quot;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This will cause an error if someone uses the new keyword</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> singleton<span style="color: #000000; font-weight: bold;">:</span>Singleton = <span style="color: #0033ff; font-weight: bold;">new</span> Singleton<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>It will work fine if you use it like this</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> singleton<span style="color: #000000; font-weight: bold;">:</span>Singleton = Singleton.getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://howto.isgoodness.com/2009/10/how-to-implement-singleton-pattern-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to wrap your actionscript class/application and add it to flex application</title>
		<link>http://howto.isgoodness.com/2009/10/how-to-wrap-your-actionscript-classapplication-and-add-it-to-flex-application/</link>
		<comments>http://howto.isgoodness.com/2009/10/how-to-wrap-your-actionscript-classapplication-and-add-it-to-flex-application/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 20:33:36 +0000</pubDate>
		<dc:creator>Van Nhu</dc:creator>
				<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex application]]></category>
		<category><![CDATA[mxml]]></category>
		<category><![CDATA[noughts and crosses]]></category>

		<guid isPermaLink="false">http://howto.isgoodness.com/?p=26</guid>
		<description><![CDATA[Sometimes ago I started to learn actionscript 3 and the go was to code for the game nought and crosses with a simple AI. To save time I used Flex componnents to create button and other containers. I was running on problem to add my application to flex application. Flex refused to add my objects [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes ago I started to learn actionscript 3 and the go was to code for the game nought and crosses with a simple AI. To save time I used Flex componnents to create button and other containers. I was running on problem to add my application to flex application. Flex refused to add my objects as child in Flex application and the solution was adding my objects in an UIComponent object and added this object to flex application. Bellow is another way to code and is completely equivalent to what mensioned above.</p>
<p>The procedure is simple. You create a &#8220;container&#8221; class by extending Flex UIComponent. Bellow is the container class for my nought and crosses. I guess that you are familar with the code. You don&#8217;t need to pay much attention to create-method. However, newGame, playBack and addStatusListener are worth to notice. And you can find the reason on the next paragraph.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">package</span> vnmedia.games.nac
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.controls.Text;
	<span style="color: #0033ff; font-weight: bold;">import</span> mx.core.UIComponent;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> vnmedia.games.nac.ai.AiComm;
	<span style="color: #0033ff; font-weight: bold;">import</span> vnmedia.games.nac.ai.BaseAi;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">import</span> vnmedia.games.nac.core.CoreComm;
	<span style="color: #0033ff; font-weight: bold;">import</span> vnmedia.games.nac.core.Game;
	<span style="color: #0033ff; font-weight: bold;">import</span> vnmedia.games.nac.gui.Client;
	<span style="color: #0033ff; font-weight: bold;">import</span> vnmedia.games.nac.gui.GuiComm;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #9900cc; font-weight: bold;">class</span> FlexNac extends UIComponent <span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">client</span><span style="color: #000000; font-weight: bold;">:</span>Client;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> game<span style="color: #000000; font-weight: bold;">:</span>Game;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">status</span><span style="color: #000000; font-weight: bold;">:</span>Text;
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> FlexNac<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #009900;">// create client, game and other necessary</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.create<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">try</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">client</span><span style="color: #000000;">&#41;</span>;
				<span style="color: #009900;">// start an new game</span>
				<span style="color: #0033ff; font-weight: bold;">this</span>.game.newGame<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;	
			<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">catch</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Error</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
				<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span>;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> newGame<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.game.newGame<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> playBack<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">client</span>.playBack<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> addStatusListener<span style="color: #000000;">&#40;</span>t<span style="color: #000000; font-weight: bold;">:</span>Text<span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">client</span>.addStatusListener<span style="color: #000000;">&#40;</span>t<span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> create<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span>
			<span style="color: #6699cc; font-weight: bold;">var</span> aiCoreComm<span style="color: #000000; font-weight: bold;">:</span>CoreComm = <span style="color: #0033ff; font-weight: bold;">new</span> CoreComm;
			<span style="color: #6699cc; font-weight: bold;">var</span> guiCoreComm<span style="color: #000000; font-weight: bold;">:</span>CoreComm = <span style="color: #0033ff; font-weight: bold;">new</span> CoreComm;
			<span style="color: #6699cc; font-weight: bold;">var</span> aiComm<span style="color: #000000; font-weight: bold;">:</span>AiComm = AiComm.getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> guiComm<span style="color: #000000; font-weight: bold;">:</span>GuiComm = GuiComm.getInstance<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #6699cc; font-weight: bold;">var</span> Ai<span style="color: #000000; font-weight: bold;">:</span>BaseAi = <span style="color: #0033ff; font-weight: bold;">new</span> BaseAi<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
			aiComm.attach<span style="color: #000000;">&#40;</span>Ai<span style="color: #000000;">&#41;</span>;
&nbsp;
			aiCoreComm.setClientComm<span style="color: #000000;">&#40;</span>aiComm<span style="color: #000000;">&#41;</span>;
			guiCoreComm.setClientComm<span style="color: #000000;">&#40;</span>guiComm<span style="color: #000000;">&#41;</span>;
&nbsp;
			guiComm.setCoreComm<span style="color: #000000;">&#40;</span>guiCoreComm<span style="color: #000000;">&#41;</span>;
			aiComm.setCoreComm<span style="color: #000000;">&#40;</span>aiCoreComm<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">client</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Client<span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">24</span><span style="color: #000000;">&#41;</span>;
			guiComm.attachClient<span style="color: #000000;">&#40;</span><span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">client</span><span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">this</span>.game = <span style="color: #0033ff; font-weight: bold;">new</span> Game<span style="color: #000000;">&#40;</span><span style="color: #990000;">'X'</span><span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.game.aiCoreComm = aiCoreComm;
			<span style="color: #0033ff; font-weight: bold;">this</span>.game.guiCoreComm = guiCoreComm;
			<span style="color: #009900;">// </span>
			aiCoreComm.attachGame<span style="color: #000000;">&#40;</span>game<span style="color: #000000;">&#41;</span>;
			guiCoreComm.attachGame<span style="color: #000000;">&#40;</span>game<span style="color: #000000;">&#41;</span>;
			<span style="color: #0033ff; font-weight: bold;">this</span>.<span style="color: #004993;">client</span>.addStatusListener<span style="color: #000000;">&#40;</span><span style="color: #004993;">status</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now you know how to create a &#8220;container&#8221; class for your application. The next step is to include it in a Flex application. There are two way to add it to Flex application. You can use mx:Script and code with actionscript style (<a href="http://learn.adobe.com/wiki/display/Flex/MXML+vs+ActionScript+3.0" target="_blank">see</a>) or just do as simple mxml example bellow where I use Flex standard box components and button component.</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;">&lt;?xml version=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Application</span> xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span>
<span style="color: #000000;">   xmlns:vn=<span style="color: #ff0000;">&quot;vnmedia.games.nac.*&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Style</span> source=<span style="color: #ff0000;">&quot;beige.css&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/mx:Style</span><span style="color: #7400FF;">&gt;</span></span>
  	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> styleName=<span style="color: #ff0000;">&quot;firstVBox&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> styleName=<span style="color: #ff0000;">&quot;menuHbox&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;newGameButton&quot;</span> </span>
<span style="color: #000000;">  			    click=<span style="color: #ff0000;">&quot;nac.newGame();&quot;</span> </span>
<span style="color: #000000;">  			    label=<span style="color: #ff0000;">&quot;New game&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/mx:Button</span><span style="color: #7400FF;">&gt;</span></span>
			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;playback&quot;</span> </span>
<span style="color: #000000;">			    click=<span style="color: #ff0000;">&quot;nac.playBack();&quot;</span> </span>
<span style="color: #000000;">			    label=<span style="color: #ff0000;">&quot;Playback&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/mx:Button</span><span style="color: #7400FF;">&gt;</span></span>
  		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
  		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> x=<span style="color: #ff0000;">&quot;10&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  			<span style="color: #000000;"><span style="color: #7400FF;">&lt;vn:FlexNac</span> id=<span style="color: #ff0000;">&quot;nac&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/vn:FlexNac</span><span style="color: #7400FF;">&gt;</span></span>
  		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
  	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:VBox</span> styleName=<span style="color: #ff0000;">&quot;secondVBox&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:HBox</span> styleName=<span style="color: #ff0000;">&quot;statusHBox&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> label=<span style="color: #ff0000;">&quot;Status&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/mx:Button</span><span style="color: #7400FF;">&gt;</span></span>
  			<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Text</span> id=<span style="color: #ff0000;">&quot;stat&quot;</span> styleName=<span style="color: #ff0000;">&quot;status&quot;</span> </span>
<span style="color: #000000;">  			    text=<span style="color: #ff0000;">&quot;You: 0 Computer: 0&quot;</span> </span>
<span style="color: #000000;">  			    creationComplete=<span style="color: #ff0000;">&quot;nac.addStatusListener(stat);&quot;</span><span style="color: #7400FF;">&gt;</span></span>
  			  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Text</span><span style="color: #7400FF;">&gt;</span></span>
  		<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:HBox</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:VBox</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:Application</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p> Now when you finished reading the code you should notice that I added my nought and crosses with a tag</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;vn:FlexNac</span> id=<span style="color: #ff0000;">&quot;nac&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/vn:FlexNac</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>What hapened was that I created my own namespace vn. You can find it as an attribute in mx:Application element. You should get a picture how to create your own component for Flex application by now, right?! and of course if you have a reason :-p </p>
<p>Now we go back to those 3 methods mensioned in the beginning. I just created those public methods so I could access from Flex application, no more no less. Another way is that I could make &#8220;game&#8221; and &#8220;client&#8221; accessible. One last thing for those whom do not use mxml. The attribute id refers to the created object and you can see it in the beginning where I used in click event</p>

<div class="wp_syntax"><div class="code"><pre class="mxml" style="font-family:monospace;"><span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:Button</span> id=<span style="color: #ff0000;">&quot;newGameButton&quot;</span> </span>
<span style="color: #000000;">  	click=<span style="color: #ff0000;">&quot;nac.newGame();&quot;</span> </span>
<span style="color: #000000;">  	label=<span style="color: #ff0000;">&quot;New game&quot;</span><span style="color: #7400FF;">&gt;</span><span style="color: #7400FF;">&lt;/mx:Button</span><span style="color: #7400FF;">&gt;</span></span>
...</pre></div></div>

<p>And finally the result<br />
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="420" height="450" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="src" value="http://luffarschack.isgoodness.com/flexnac.swf" /><embed type="application/x-shockwave-flash" width="420" height="450" src="http://luffarschack.isgoodness.com/flexnac.swf"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://howto.isgoodness.com/2009/10/how-to-wrap-your-actionscript-classapplication-and-add-it-to-flex-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

