<?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>Architect, Engineer, Tech Enthusiast - Hasan Otuome &#187; AS3</title>
	<atom:link href="http://technophi.com/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://technophi.com</link>
	<description>personal weblog of a tech addict</description>
	<lastBuildDate>Wed, 23 Nov 2011 18:04:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Getting Some &#8230;rest</title>
		<link>http://technophi.com/2008/05/08/getting-some-rest/</link>
		<comments>http://technophi.com/2008/05/08/getting-some-rest/#comments</comments>
		<pubDate>Thu, 08 May 2008 17:54:34 +0000</pubDate>
		<dc:creator>Hasan Otuome</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Platform]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Thought I'd blog about this since I haven't seen this posted before and it comes up from time to time. With AS3, we got access to a new function parameter, the <b>...rest</b> parameter, which allows us to pass in a dynamic list of parameters for usage by our functions. Here's an example:

[code]
// Method in SomeClass
public function someMethod(...rest):void
{
    for (var i:uint=0; i < rest.length; i++)
    {
        trace(rest[i]);
    }
}
[/code]

That will trace out each ...rest parameter that you pass to the method call like so:

[code]
// Usage from SomeOtherClass
]]></description>
			<content:encoded><![CDATA[<p>Thought I&#8217;d blog about this since I haven&#8217;t seen this posted before and it comes up from time to time. With AS3, we got access to a new function parameter, the <b>&#8230;rest</b> parameter, which allows us to pass in a dynamic list of parameters for usage by our functions. Here&#8217;s an example:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Method in SomeClass</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> someMethod<span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">...</span>rest<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>
    <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;">uint</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> rest<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</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>
        <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span>rest<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>That will trace out each &#8230;rest parameter that you pass to the method call like so:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Usage from SomeOtherClass</span>
<span style="color: #6699cc; font-weight: bold;">var</span> sc<span style="color: #000066; font-weight: bold;">:</span>SomeClass = <span style="color: #0033ff; font-weight: bold;">new</span> SomeClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
      sc<span style="color: #000066; font-weight: bold;">.</span>someMethod<span style="color: #000000;">&#40;</span>arg1<span style="color: #000066; font-weight: bold;">,</span> arg2<span style="color: #000066; font-weight: bold;">,</span> arg3<span style="color: #000066; font-weight: bold;">,</span> arg4<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>This allows a lot of flexibility because those arguments can be simple (String, Number, etc) or complex (Array, Object, etc). But, what if <b>someMethod()</b> is part of SWC library that you may or may not have access to and you want to capture those &#8230;rest arguments and pass them to SWC class?</p>
<p>Well, the easiest way that I&#8217;ve found is to use the built-in arguments object in your local code and then pass that to the SWC class that&#8217;s expecting the &#8230;rest array. Here&#8217;s what I mean:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">// Usage from LocalClass</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> someMethod<span style="color: #000000;">&#40;</span>arg1<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">arguments</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Object</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: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #6699cc; font-weight: bold;">var</span> sc<span style="color: #000066; font-weight: bold;">:</span>SomeClass = <span style="color: #0033ff; font-weight: bold;">new</span> SomeClass<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
          sc<span style="color: #000066; font-weight: bold;">.</span>someMethod<span style="color: #000000;">&#40;</span><span style="color: #004993;">arguments</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This way you can expose <b>LocalClass.someMethod()</b>, accept the concrete parameters that it expects and pass on the dynamic parameters that <b>SomeClass.someMethod()</b> expects.</p>
<p> <img src='http://technophi.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<div style="float: right; padding: 3px;"><a href="http://bufferapp.com/add" class="buffer-add-button" data-text="Getting Some &#8230;rest" data-url="http://technophi.com/2008/05/08/getting-some-rest/" data-via="bufferapp" data-count="none">Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></div><div id="tweetbutton87" class="tw_button" style="padding: 3px;float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fj.mp%2FkxXeWU&amp;via=heroizm&amp;text=Getting%20Some%20%26%238230%3Brest&amp;related=heroizm&amp;lang=en&amp;count=none&amp;counturl=http%3A%2F%2Ftechnophi.com%2F2008%2F05%2F08%2Fgetting-some-rest%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://technophi.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://technophi.com/2008/05/08/getting-some-rest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex 2 and Flash 9 SWFs</title>
		<link>http://technophi.com/2006/11/08/flex-2-and-flash-9-swfs/</link>
		<comments>http://technophi.com/2006/11/08/flex-2-and-flash-9-swfs/#comments</comments>
		<pubDate>Wed, 08 Nov 2006 08:00:00 +0000</pubDate>
		<dc:creator>Hasan Otuome</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Platform]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[A question popped up on <a href="http://tech.groups.yahoo.com/group/flexcoders/" target="blank">flexcoders</a> recently about whether these two could play together and here's my response. Yes, it's possible using <strong>SWFLoader</strong>. The 9 SWF will be accessible/programmable through the <strong>content</strong> property of the loader. Here's a very basic example:

<strong>Flex</strong>
<strong>=======</strong>
[code lang="Actionscript"]import flash.events.Event;

private function initSWF(event:Event):void{
    loadedSWF.content.addEventListener("clicked",clickHandler);
}

]]></description>
			<content:encoded><![CDATA[<p>A question popped up on <a href="http://tech.groups.yahoo.com/group/flexcoders/" target="blank">flexcoders</a> recently about whether these two could play together and here&#8217;s my response. Yes, it&#8217;s possible using <strong>SWFLoader</strong>. The 9 SWF will be accessible/programmable through the <strong>content</strong> property of the loader. Here&#8217;s a very basic example:</p>
<p><strong>Flex</strong><br />
<strong>=======</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><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>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> initSWF<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>
    loadedSWF<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;clicked&quot;</span><span style="color: #000066; font-weight: bold;">,</span> clickHandler <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</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> clickHandler<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>
    <span style="color: #6699cc; font-weight: bold;">var</span> button<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = loadedSWF<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">content</span><span style="color: #000000;">&#91;</span> <span style="color: #990000;">&quot;clickedButton&quot;</span> <span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
    <span style="color: #009900; font-style: italic;">//do something with the returned data</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>So, the above code can go in a <strong>< mx:Script >< /mx:Script ></strong> block or in an external ActionScript file that&#8217;s the source property of your script block, <strong>< mx:Script source="external.as" /></strong>. First, we import the <strong>Event</strong> class so we can listen for and dispatch events. Next comes <strong>initSWF()</strong>. This method is the event handler for the SWFLoader&#8217;s <strong>complete</strong> event. If that was confusing, it&#8217;s the function that get&#8217;s called when the complete event fires. So, what we&#8217;re doing with this method is adding an event listener to the Flash 9 SWF that we load. And, when the loaded SWF fires the <strong>&#8220;clicked&#8221;</strong> event we want to handle that with <strong>clickHandler()</strong>, which right now is just holding a reference to the name of the button clicked. To get the ball rolling, simply make initSWF() the value of the complete property of your SWFLoader component, <strong>< mx:SWFLoader  id="loadedSWF" complete="initSWF(event)" source="pathToSWF" /></strong>.</p>
<p><strong>Flash<br />
=======</strong></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.*;</span>
&nbsp;
<span style="color: #6699cc; font-weight: bold;">var</span> clickedButton<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #990000;">&quot;&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
someButton<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> clickHandler <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> clickHandler<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>
    clickedButton = event<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;">name</span><span style="color: #000066; font-weight: bold;">;</span>
    <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: #990000;">&quot;clicked&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>OK, on the Flash side we do our import first of course. Next, we instantiate our <strong>clickedButton</strong> variable as an empty string (just to keep from being null/undefined). Now, we add an event listener to the <strong>someButton</strong> instance on the main timeline. This syntax is a much cleaner way of dealing with events IMO because everybody (you, your team, the compiler) knows exactly what you&#8217;re trying to do. Here we want to listen for the <strong>CLICK</strong> event which is a static member of the <strong>MouseEvent Class</strong>. When we hear the event clickHandler() once again jumps into action. Inside this click handler we do (2) things. First, we set the value of our clickedButton variable to the instance name of the button that was clicked. Then finally, we want to dispatch our custom <strong>&#8220;clicked&#8221;</strong> event which, in turn, kicks things in motion on the Flex side.</p>
<p>Again, this is a simple illustration of some of the things you can do using Flex/Flash together. No LocalConnections just pure AS3 conversations. Enjoy&#8230; <img src='http://technophi.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  </p>
<div style="float: right; padding: 3px;"><a href="http://bufferapp.com/add" class="buffer-add-button" data-text="Flex 2 and Flash 9 SWFs" data-url="http://technophi.com/2006/11/08/flex-2-and-flash-9-swfs/" data-via="bufferapp" data-count="none">Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></div><div id="tweetbutton78" class="tw_button" style="padding: 3px;float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fj.mp%2FiYpNRA&amp;via=heroizm&amp;text=Flex%202%20and%20Flash%209%20SWFs&amp;related=heroizm&amp;lang=en&amp;count=none&amp;counturl=http%3A%2F%2Ftechnophi.com%2F2006%2F11%2F08%2Fflex-2-and-flash-9-swfs%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://technophi.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://technophi.com/2006/11/08/flex-2-and-flash-9-swfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>StringUtils Class</title>
		<link>http://technophi.com/2006/10/05/stringutils-class/</link>
		<comments>http://technophi.com/2006/10/05/stringutils-class/#comments</comments>
		<pubDate>Thu, 05 Oct 2006 08:00:00 +0000</pubDate>
		<dc:creator>Hasan Otuome</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Came up with this idea after perusing proto.layer51.com. It's basically a sub-class of String and the 1st method is a reduction method that let's you feed in a string, a limit and a "there's more" indicator. Anyways, here's the code:
[code lang="Actionscript"]class org.thesourcecode.utils.StringUtils extends String{
	public var theString:String;
	
	public function StringUtils(string:String){
		super();
		theString = string;
	}
	
	public function reduce(stringLength,trimIndicator):String{
		var trimmedString:Array = [];
		if (theString.length < = stringLength) {
]]></description>
			<content:encoded><![CDATA[<p>Came up with this idea after perusing proto.layer51.com. It&#8217;s basically a sub-class of String and the 1st method is a reduction method that let&#8217;s you feed in a string, a limit and a &#8220;there&#8217;s more&#8221; indicator. Anyways, here&#8217;s the code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #9900cc; font-weight: bold;">class</span> org<span style="color: #000066; font-weight: bold;">.</span>thesourcecode<span style="color: #000066; font-weight: bold;">.</span>utils<span style="color: #000066; font-weight: bold;">.</span>StringUtils <span style="color: #0033ff; font-weight: bold;">extends</span> <span style="color: #004993;">String</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> theString<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
&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> string<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</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: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		theString = string<span style="color: #000066; font-weight: bold;">;</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> reduce<span style="color: #000000;">&#40;</span> stringLength<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">,</span> trimIndicator<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>=<span style="color: #990000;">&quot;...&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> trimmedString<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>theString<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">length</span> <span style="color: #000066; font-weight: bold;">&lt;</span> = stringLength<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #009900; font-style: italic;">//just return the string if it's within the &quot;limit&quot;</span>
			<span style="color: #0033ff; font-weight: bold;">return</span> theString<span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #6699cc; font-weight: bold;">var</span> words<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = theString<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">split</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>
 		<span style="color: #6699cc; font-weight: bold;">var</span> numWords<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = words<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: #6699cc; font-weight: bold;">var</span> ol<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>
		<span style="color: #6699cc; font-weight: bold;">var</span> cWord<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #6699cc; font-weight: bold;">var</span> w<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
 		<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #000000;">&#40;</span>w=<span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">;</span> w<span style="color: #000066; font-weight: bold;">&lt;</span>numWords<span style="color: #000066; font-weight: bold;">;</span> <span style="color: #000066; font-weight: bold;">++</span>w<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		   cWord=words<span style="color: #000000;">&#91;</span>w<span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
		   <span style="color: #6699cc; font-weight: bold;">var</span> cwl=cWord<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: #009900; font-style: italic;">//check each words length before adding it the output string</span>
		   <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>ol<span style="color: #000066; font-weight: bold;">+</span>cwl<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">&lt;</span>=stringLength<span style="color: #000000;">&#41;</span>
		   <span style="color: #000000;">&#123;</span>
		      trimmedString<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">push</span><span style="color: #000000;">&#40;</span> cWord <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
		      ol<span style="color: #000066; font-weight: bold;">+</span>=cwl<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>
		   <span style="color: #000000;">&#125;</span>
		   <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0033ff; font-weight: bold;">return</span> trimmedString<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">join</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>trimIndicator<span style="color: #000066; font-weight: bold;">;</span>
        <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The easy-install extension can be downloaded <a href="http://thesourcecode.org/code/StringUtils.zip">here</a>.<br />
Documentation can be found <a href="http://thesourcecode.org/docs/StringUtils.html">here</a>.</p>
<div style="float: right; padding: 3px;"><a href="http://bufferapp.com/add" class="buffer-add-button" data-text="StringUtils Class" data-url="http://technophi.com/2006/10/05/stringutils-class/" data-via="bufferapp" data-count="none">Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></div><div id="tweetbutton77" class="tw_button" style="padding: 3px;float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fj.mp%2FjnlNg9&amp;via=heroizm&amp;text=StringUtils%20Class&amp;related=heroizm&amp;lang=en&amp;count=none&amp;counturl=http%3A%2F%2Ftechnophi.com%2F2006%2F10%2F05%2Fstringutils-class%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://technophi.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://technophi.com/2006/10/05/stringutils-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get to Know Your Sanitation Worker!!</title>
		<link>http://technophi.com/2006/09/26/get-to-know-your-sanitation-worker/</link>
		<comments>http://technophi.com/2006/09/26/get-to-know-your-sanitation-worker/#comments</comments>
		<pubDate>Tue, 26 Sep 2006 21:48:35 +0000</pubDate>
		<dc:creator>Hasan Otuome</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Platform]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[If you plan on doing any serious AS3 development for Flash or Flex, make sure you become intimate with the <a href="http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html" target="blank">Garbage Collector</a> (GC). In previous Flash Player versions, the GC worked silently and intuitively behind the scenes. With AS3 though, you have to put more thought into resource management. The genius that he is, Grant Skinner has <a href="http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html" target="blank">a series of cool articles</a> that will get you up to speed on the GC.]]></description>
			<content:encoded><![CDATA[<p>If you plan on doing any serious AS3 development for Flash or Flex, make sure you become intimate with the <a href="http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html" target="blank">Garbage Collector</a> (GC). In previous Flash Player versions, the GC worked silently and intuitively behind the scenes. With AS3 though, you have to put more thought into resource management. The genius that he is, Grant Skinner has <a href="http://www.gskinner.com/blog/archives/2006/06/as3_resource_ma.html" target="blank">a series of cool articles</a> that will get you up to speed on the GC.</p>
<div style="float: right; padding: 3px;"><a href="http://bufferapp.com/add" class="buffer-add-button" data-text="Get to Know Your Sanitation Worker!!" data-url="http://technophi.com/2006/09/26/get-to-know-your-sanitation-worker/" data-via="bufferapp" data-count="none">Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></div><div id="tweetbutton15" class="tw_button" style="padding: 3px;float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fj.mp%2FmkMsk9&amp;via=heroizm&amp;text=Get%20to%20Know%20Your%20Sanitation%20Worker%21%21&amp;related=heroizm&amp;lang=en&amp;count=none&amp;counturl=http%3A%2F%2Ftechnophi.com%2F2006%2F09%2F26%2Fget-to-know-your-sanitation-worker%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://technophi.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://technophi.com/2006/09/26/get-to-know-your-sanitation-worker/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex :: Custom ComboBox Part 2</title>
		<link>http://technophi.com/2006/08/23/flex-custom-combobox-part-2/</link>
		<comments>http://technophi.com/2006/08/23/flex-custom-combobox-part-2/#comments</comments>
		<pubDate>Wed, 23 Aug 2006 08:00:00 +0000</pubDate>
		<dc:creator>Hasan Otuome</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[<a href="http://thesourcecode.org/?p=15">Last time</a> we looked @ creating a custom ComboBox that could be reused for displaying states/countries. This time will wrap up by looking @ how that ComboBox can be used as an itemRenderer in a DataGrid. Since DataGrids use TextInputs as their default renderers when the grid is editable, we have to tell the grid we want to use our ComboBox for a particular column or columns. So, here's an example of an editable grid that's making use of the custom component:
]]></description>
			<content:encoded><![CDATA[<p><a href="http://thesourcecode.org/?p=15">Last time</a> we looked @ creating a custom ComboBox that could be reused for displaying states/countries. This time will wrap up by looking @ how that ComboBox can be used as an itemRenderer in a DataGrid. Since DataGrids use TextInputs as their default renderers when the grid is editable, we have to tell the grid we want to use our ComboBox for a particular column or columns. So, here&#8217;s an example of an editable grid that&#8217;s making use of the custom component:</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:DataGrid</span> </span>
<span style="color: #000000;">      x=<span style="color: #ff0000;">&quot;10&quot;</span> y=<span style="color: #ff0000;">&quot;40&quot;</span> </span>
<span style="color: #000000;">      width=<span style="color: #ff0000;">&quot;769&quot;</span> height=<span style="color: #ff0000;">&quot;145&quot;</span> </span>
<span style="color: #000000;">      id=<span style="color: #ff0000;">&quot;dgGigs&quot;</span> </span>
<span style="color: #000000;">      dataProvider=<span style="color: #ff0000;">&quot;{dp}&quot;</span> </span>
<span style="color: #000000;">      editable=<span style="color: #ff0000;">&quot;true&quot;</span> </span>
<span style="color: #000000;">      itemEditEnd=<span style="color: #ff0000;">&quot;editedGig(event)&quot;</span></span>
<span style="color: #000000;">      <span style="color: #7400FF;">&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> headerText=<span style="color: #ff0000;">&quot;Gig ID&quot;</span> dataField=<span style="color: #ff0000;">&quot;gid&quot;</span> width=<span style="color: #ff0000;">&quot;50&quot;</span> editable=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> headerText=<span style="color: #ff0000;">&quot;Date&quot;</span> dataField=<span style="color: #ff0000;">&quot;date&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> headerText=<span style="color: #ff0000;">&quot;Event&quot;</span> dataField=<span style="color: #ff0000;">&quot;event&quot;</span> width=<span style="color: #ff0000;">&quot;200&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> headerText=<span style="color: #ff0000;">&quot;Venue&quot;</span> dataField=<span style="color: #ff0000;">&quot;venue&quot;</span> width=<span style="color: #ff0000;">&quot;180&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> headerText=<span style="color: #ff0000;">&quot;City&quot;</span> dataField=<span style="color: #ff0000;">&quot;city&quot;</span> width=<span style="color: #ff0000;">&quot;100&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> headerText=<span style="color: #ff0000;">&quot;State&quot;</span> dataField=<span style="color: #ff0000;">&quot;state&quot;</span> width=<span style="color: #ff0000;">&quot;65&quot;</span> itemEditor=<span style="color: #ff0000;">&quot;components.StatesCombo&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;"><span style="color: #7400FF;">&lt;mx:DataGridColumn</span> headerText=<span style="color: #ff0000;">&quot;Time&quot;</span> dataField=<span style="color: #ff0000;">&quot;gtime&quot;</span> width=<span style="color: #ff0000;">&quot;65&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
  <span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:columns</span><span style="color: #7400FF;">&gt;</span></span>
<span style="color: #000000;"><span style="color: #7400FF;">&lt;/mx:DataGrid</span><span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>Here we tell the grid that for the <strong>state</strong> column we want to use our custom ComboBox as the itemEditor for that column. In other words, use a TextField for static display of the data, but once a user clicks the cell to edit it use StatesCombo. Now, to wrap up we&#8217;ll look briefly @ the actual editing process. Check out itemEditEnd in the code above. Think of it as an Event Listener that says when the user is finished making an edit to the grid call the editedGig() method and pass the edit event as an argument. So, here&#8217;s the ActionScript to process those edits:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//gig variables</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> gigsDate<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> gigsName<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> gigsLoc<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> gigsCity<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> gigsState<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> gigsTime<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">String</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//gig itemEditor</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> editedGig<span style="color: #000000;">&#40;</span> event<span style="color: #000066; font-weight: bold;">:</span> DataGridEvent <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>
	<span style="color: #6699cc; font-weight: bold;">var</span> gigID<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>gid<span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #0033ff; font-weight: bold;">switch</span> <span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">.</span>dataField<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;date&quot;</span><span style="color: #000066; font-weight: bold;">:</span>
			<span style="color: #009900; font-style: italic;">//code for this case</span>
			<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;event&quot;</span><span style="color: #000066; font-weight: bold;">:</span>
			<span style="color: #009900; font-style: italic;">//code for this case</span>
			<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;venue&quot;</span><span style="color: #000066; font-weight: bold;">:</span>
			<span style="color: #009900; font-style: italic;">//code for this case</span>
			<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;city&quot;</span><span style="color: #000066; font-weight: bold;">:</span>
			<span style="color: #009900; font-style: italic;">//code for this case</span>
			<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;state&quot;</span><span style="color: #000066; font-weight: bold;">:</span>
			dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>state = components<span style="color: #000066; font-weight: bold;">.</span>StatesCombo<span style="color: #000000;">&#40;</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span><span style="color: #000066; font-weight: bold;">.</span>itemEditorInstance <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>selectedItem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span>
			gigsDate = dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">date</span><span style="color: #000066; font-weight: bold;">;</span>
			gigsName = dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>event<span style="color: #000066; font-weight: bold;">;</span>
			gigsLoc = dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>venue<span style="color: #000066; font-weight: bold;">;</span>
			gigsCity = dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>city<span style="color: #000066; font-weight: bold;">;</span>
			gigsState = dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>state<span style="color: #000066; font-weight: bold;">;</span>
			gigsTime = dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>gtime<span style="color: #000066; font-weight: bold;">;</span>
			updateData<span style="color: #000000;">&#40;</span> <span style="color: #990000;">'client.manager.updateGig'</span><span style="color: #000066; font-weight: bold;">,</span><span style="color: #000000;">&#91;</span>gigID<span style="color: #000066; font-weight: bold;">,</span>gigsDate<span style="color: #000066; font-weight: bold;">,</span>gigsName<span style="color: #000066; font-weight: bold;">,</span>gigsLoc<span style="color: #000066; font-weight: bold;">,</span>gigsCity<span style="color: #000066; font-weight: bold;">,</span>gigsState<span style="color: #000066; font-weight: bold;">,</span>gigsTime<span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
			<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
		<span style="color: #0033ff; font-weight: bold;">case</span> <span style="color: #990000;">&quot;gtime&quot;</span><span style="color: #000066; font-weight: bold;">:</span>
			<span style="color: #009900; font-style: italic;">//code for this case</span>
			<span style="color: #0033ff; font-weight: bold;">break</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The key line here is</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">dgGigs<span style="color: #000066; font-weight: bold;">.</span>editedItemRenderer<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">.</span>state = components<span style="color: #000066; font-weight: bold;">.</span>StatesCombo<span style="color: #000000;">&#40;</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">currentTarget</span><span style="color: #000066; font-weight: bold;">.</span>itemEditorInstance <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>selectedItem<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">data</span></pre></div></div>

<p>We must first set the itemRenderer for the state column equal to the list item the user selected with our component. Then, we assign the itemRenderer value to the gigsState variable and pass the data to our grid updating mechanism so that we can see the changes reflected. I&#8217;m just kinda scratchin&#8217; the surface to keep it as simple and easy to understand as possible. You can check out the <a href="http://livedocs.macromedia.com/flex/2/langref/mx/controls/DataGrid.html" target="blank">LiveDocs</a> for more detailed info on renderers. If you missed it, you can catch part 1 <a href="http://thesourcecode.org/?p=15">here</a>.</p>
<div style="float: right; padding: 3px;"><a href="http://bufferapp.com/add" class="buffer-add-button" data-text="Flex :: Custom ComboBox Part 2" data-url="http://technophi.com/2006/08/23/flex-custom-combobox-part-2/" data-via="bufferapp" data-count="none">Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></div><div id="tweetbutton76" class="tw_button" style="padding: 3px;float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fj.mp%2Fm1FPEw&amp;via=heroizm&amp;text=Flex%20%3A%3A%20Custom%20ComboBox%20Part%202&amp;related=heroizm&amp;lang=en&amp;count=none&amp;counturl=http%3A%2F%2Ftechnophi.com%2F2006%2F08%2F23%2Fflex-custom-combobox-part-2%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://technophi.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://technophi.com/2006/08/23/flex-custom-combobox-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex :: AMFPHP Login</title>
		<link>http://technophi.com/2006/07/10/flex-amfphp-login/</link>
		<comments>http://technophi.com/2006/07/10/flex-amfphp-login/#comments</comments>
		<pubDate>Mon, 10 Jul 2006 08:00:00 +0000</pubDate>
		<dc:creator>Hasan Otuome</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[The subject pops up a lot about reusable Flex components. Here's one to handle multi-user logins via AMFPHP / MySQL:

[code lang="Actionscript"]< ?xml version="1.0" encoding="utf-8"?>
<mx :Canvas xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*" width="355" height="213">
	</mx><mx :Script>
		< ![CDATA[
			import flash.net.Responder;
			
			public var gateway:RemotingConnection;
			
			public function checkLogin(service:String,params:Array):void{
				gateway = new RemotingConnection("http://yourwebserver.com/flashservices/gateway.php");
]]></description>
			<content:encoded><![CDATA[<p>The subject pops up a lot about reusable Flex components. Here&#8217;s one to handle multi-user logins via AMFPHP / MySQL:</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;">&lt;mx :Canvas xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> xmlns=<span style="color: #ff0000;">&quot;*&quot;</span> width=<span style="color: #ff0000;">&quot;355&quot;</span> height=<span style="color: #ff0000;">&quot;213&quot;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;">&lt;/mx<span style="color: #7400FF;">&gt;</span>&lt;mx :Script<span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt; !<span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span></span>
<span style="color: #000000;">			import flash.net.Responder;</span>
&nbsp;
<span style="color: #000000;">			public var gateway:RemotingConnection;</span>
&nbsp;
<span style="color: #000000;">			public function checkLogin<span style="color: #66cc66;">&#40;</span> service:String, params:Array <span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				gateway = new RemotingConnection<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;http://yourwebserver.com/flashservices/gateway.php&quot;</span> <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				gateway.call<span style="color: #66cc66;">&#40;</span> service,new Responder<span style="color: #66cc66;">&#40;</span>onResult,onFault<span style="color: #66cc66;">&#41;</span>,params <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			public function onResult<span style="color: #66cc66;">&#40;</span> result:Array <span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				if <span style="color: #66cc66;">&#40;</span>result<span style="color: #66cc66;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#93;</span>!=<span style="color: #ff0000;">&quot;VALID&quot;</span><span style="color: #66cc66;">&#41;</span></span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					lResponse.text = result<span style="color: #66cc66;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#93;</span>;</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span> </span>
<span style="color: #000000;">				else </span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					lResponse.text = result<span style="color: #66cc66;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">&#93;</span>;</span>
<span style="color: #000000;">					parentDocument.currentState=<span style="color: #ff0000;">'Main'</span>;</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			public function onFault<span style="color: #66cc66;">&#40;</span> fault:String <span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				lResponse.text = <span style="color: #ff0000;">&quot;Service Error: &quot;</span>+fault;</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
&nbsp;
<span style="color: #000000;">			private function checkInput<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:void</span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">				if <span style="color: #66cc66;">&#40;</span>tUser.text == <span style="color: #ff0000;">&quot;&quot;</span> || tPass.text == <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span></span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					lResponse.text = <span style="color: #ff0000;">&quot;Please complete all fields&quot;</span>;</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span> </span>
<span style="color: #000000;">				else </span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#123;</span></span>
<span style="color: #000000;">					lResponse.text = <span style="color: #ff0000;">&quot;Logging in...&quot;</span>;</span>
<span style="color: #000000;">					checkLogin<span style="color: #66cc66;">&#40;</span> <span style="color: #ff0000;">&quot;login.Verify.validate&quot;</span>,<span style="color: #66cc66;">&#91;</span>tUser.text,tPass.text<span style="color: #66cc66;">&#93;</span> <span style="color: #66cc66;">&#41;</span>;</span>
<span style="color: #000000;">				<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">			<span style="color: #66cc66;">&#125;</span></span>
<span style="color: #000000;">		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;">&lt;/mx<span style="color: #7400FF;">&gt;</span></span>
	<span style="color: #000000;">&lt;mx : Panel height=<span style="color: #ff0000;">&quot;200&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> title=<span style="color: #ff0000;">&quot;Admin Login&quot;</span> left=<span style="color: #ff0000;">&quot;0&quot;</span> right=<span style="color: #ff0000;">&quot;5&quot;</span> bottom=<span style="color: #ff0000;">&quot;13&quot;</span><span style="color: #7400FF;">&gt;</span></span>
		<span style="color: #000000;">&lt;mx :Label x=<span style="color: #ff0000;">&quot;33&quot;</span> y=<span style="color: #ff0000;">&quot;45&quot;</span> text=<span style="color: #ff0000;">&quot;Username:&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;">&lt;mx :Label x=<span style="color: #ff0000;">&quot;33&quot;</span> y=<span style="color: #ff0000;">&quot;85&quot;</span> text=<span style="color: #ff0000;">&quot;Password:&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;">&lt;mx :Button x=<span style="color: #ff0000;">&quot;178&quot;</span> y=<span style="color: #ff0000;">&quot;118&quot;</span> label=<span style="color: #ff0000;">&quot;Login&quot;</span> id=<span style="color: #ff0000;">&quot;bLogin&quot;</span> tabIndex=<span style="color: #ff0000;">&quot;3&quot;</span> click=<span style="color: #ff0000;">&quot;checkInput()&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;">&lt;mx :TextInput x=<span style="color: #ff0000;">&quot;113&quot;</span> y=<span style="color: #ff0000;">&quot;83&quot;</span> id=<span style="color: #ff0000;">&quot;tPass&quot;</span> tabIndex=<span style="color: #ff0000;">&quot;2&quot;</span> displayAsPassword=<span style="color: #ff0000;">&quot;true&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;">&lt;mx :TextInput x=<span style="color: #ff0000;">&quot;113&quot;</span> y=<span style="color: #ff0000;">&quot;43&quot;</span> id=<span style="color: #ff0000;">&quot;tUser&quot;</span> tabIndex=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
		<span style="color: #000000;">&lt;mx :Label x=<span style="color: #ff0000;">&quot;113&quot;</span> y=<span style="color: #ff0000;">&quot;10&quot;</span> id=<span style="color: #ff0000;">&quot;lResponse&quot;</span><span style="color: #7400FF;">/&gt;</span></span>
	<span style="color: #000000;">&lt;/mx<span style="color: #7400FF;">&gt;</span></span></pre></div></div>

<p>And here&#8217;s the AMFPHP service that the component connects to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #000000; font-weight: bold;">class</span> Verify 
<span style="color: #009900;">&#123;</span>	
	<span style="color: #000000; font-weight: bold;">function</span> Verify<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">methodTable</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">&quot;validate&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">&quot;access&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;remote&quot;</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">&quot;description&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Return the login results&quot;</span>
			<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> validate<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$nfo</span> <span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$dbc</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_connect</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;localhost&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;username&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;password&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">mysql_select_db</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;yourdatabase&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$user</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$nfo</span><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$pass</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$nfo</span><span style="color: #009900;">&#91;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT DISTINCT * FROM admin WHERE aname = '<span style="color: #006699; font-weight: bold;">$user</span>' AND acode = '<span style="color: #006699; font-weight: bold;">$pass</span>'&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$rs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$query</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_assoc</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$rs</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$u</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">&quot;aname&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$p</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span> <span style="color: #0000ff;">&quot;acode&quot;</span> <span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$pass</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$p</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INVALID&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Invalid username and/or password&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> 
		<span style="color: #b1b100;">else</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;VALID&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$response</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Welcome <span style="color: #006699; font-weight: bold;">$u</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Download a ZIP with all the necessary files <a href="http://thesourcecode.org/flex/login/login.zip">here</a>.</p>
<div style="float: right; padding: 3px;"><a href="http://bufferapp.com/add" class="buffer-add-button" data-text="Flex :: AMFPHP Login" data-url="http://technophi.com/2006/07/10/flex-amfphp-login/" data-via="bufferapp" data-count="none">Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></div><div id="tweetbutton70" class="tw_button" style="padding: 3px;float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fj.mp%2Fj057Cb&amp;via=heroizm&amp;text=Flex%20%3A%3A%20AMFPHP%20Login&amp;related=heroizm&amp;lang=en&amp;count=none&amp;counturl=http%3A%2F%2Ftechnophi.com%2F2006%2F07%2F10%2Fflex-amfphp-login%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://technophi.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://technophi.com/2006/07/10/flex-amfphp-login/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Joy of E4X!</title>
		<link>http://technophi.com/2006/07/03/the-joy-of-e4x/</link>
		<comments>http://technophi.com/2006/07/03/the-joy-of-e4x/#comments</comments>
		<pubDate>Mon, 03 Jul 2006 14:40:00 +0000</pubDate>
		<dc:creator>Hasan Otuome</dc:creator>
				<category><![CDATA[Adobe]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Platform]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Prior to AS3, working with XML was a drag. The semantics of manipulating an XML object definitely left much to be desired. Well, AS3 changed all that by bringing us E4X. If you don't already know, E4X stands for ECMAScript for XML and it introduces some new functionality that makes working with XML a lot easier. 
Here's an example working with some inline XML:
[code lang="Actionscript"]//create a new XML object
var company:XML = 
	<employees>
		<employee id="1"><name>John</name><dept>IT</dept></employee>
		<employee id="2"><name>Susan</name><dept>Marketing</dept></employee>
]]></description>
			<content:encoded><![CDATA[<p>Prior to AS3, working with XML was a drag. The semantics of manipulating an XML object definitely left much to be desired. Well, AS3 changed all that by bringing us E4X. If you don&#8217;t already know, E4X stands for ECMAScript for XML and it introduces some new functionality that makes working with XML a lot easier.<br />
Here&#8217;s an example working with some inline XML:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//create a new XML object</span>
<span style="color: #6699cc; font-weight: bold;">var</span> company<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = 
	<span style="color: #000066; font-weight: bold;">&lt;</span>employees<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>employee id=<span style="color: #990000;">&quot;1&quot;</span><span style="color: #000066; font-weight: bold;">&gt;&lt;</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>John<span style="color: #000066; font-weight: bold;">&lt;/</span>name<span style="color: #000066; font-weight: bold;">&gt;&lt;</span>dept<span style="color: #000066; font-weight: bold;">&gt;</span>IT<span style="color: #000066; font-weight: bold;">&lt;/</span>dept<span style="color: #000066; font-weight: bold;">&gt;&lt;/</span>employee<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;</span>employee id=<span style="color: #990000;">&quot;2&quot;</span><span style="color: #000066; font-weight: bold;">&gt;&lt;</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>Susan<span style="color: #000066; font-weight: bold;">&lt;/</span>name<span style="color: #000066; font-weight: bold;">&gt;&lt;</span>dept<span style="color: #000066; font-weight: bold;">&gt;</span>Marketing<span style="color: #000066; font-weight: bold;">&lt;/</span>dept<span style="color: #000066; font-weight: bold;">&gt;&lt;/</span>employee<span style="color: #000066; font-weight: bold;">&gt;</span>
   <span style="color: #000066; font-weight: bold;">&lt;/</span>employees<span style="color: #000066; font-weight: bold;">&gt;;</span></pre></div></div>

<p>Pretty simple right? Next, let&#8217;s create a function for some reusable code to help illustrate:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//create a printer function since we'll be reusing this routine</span>
<span style="color: #339966; font-weight: bold;">function</span> echo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #009900; font-style: italic;">//print the data to the output panel</span>
	<span style="color: #0033ff; font-weight: bold;">for</span> <span style="color: #0033ff; font-weight: bold;">each</span> <span style="color: #000000;">&#40;</span><span style="color: #6699cc; font-weight: bold;">var</span> e <span style="color: #0033ff; font-weight: bold;">in</span> company<span style="color: #000066; font-weight: bold;">.</span>employee<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Employee: &quot;</span><span style="color: #000066; font-weight: bold;">+</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">name</span><span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot; works in the &quot;</span><span style="color: #000066; font-weight: bold;">+</span>e<span style="color: #000066; font-weight: bold;">.</span>dept<span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot; Dept.&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//print the results</span>
echo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>We&#8217;re just using a for..each loop to iterate through our XML and give us the info we want. The important thing to note is that we can just use the node names. No more ambiguous firstChild, nextSibling, lastChild, etc.<br />
Let&#8217;s add a new employee&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//to add a new employee</span>
company<span style="color: #000066; font-weight: bold;">.</span>employee <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #000066; font-weight: bold;">&lt;</span>employee id=<span style="color: #990000;">&quot;3&quot;</span><span style="color: #000066; font-weight: bold;">&gt;&lt;</span>name<span style="color: #000066; font-weight: bold;">&gt;</span>Carl<span style="color: #000066; font-weight: bold;">&lt;/</span>name<span style="color: #000066; font-weight: bold;">&gt;&lt;/</span>employee<span style="color: #000066; font-weight: bold;">&gt;;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//print the results</span>
echo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Now, say we wanted to search the XML for that specific employee and assign them to a department. Here&#8217;s one way that could work:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #009900; font-style: italic;">//assign Carl to a department</span>
company<span style="color: #000066; font-weight: bold;">.</span>employee<span style="color: #000066; font-weight: bold;">.</span><span style="color: #000000;">&#40;</span>@id==<span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>dept = <span style="color: #990000;">&quot;Research&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #009900; font-style: italic;">//print the results</span>
echo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></pre></div></div>

<p>Here we used what&#8217;s called a filter predicate (a/k/a &#8211; the condition to match) and it&#8217;s just like the WHERE clause in a SQL statement&#8230;<em>&#8220;SELECT employee FROM company WHERE id = 3&#8243;</em>. So, we&#8217;re grabbing the employee element(node) from the company XML tree where the employee attribute, id (@id) is equal to 3.<br />
Now that we&#8217;re cooking, what about external XML? Well, that&#8217;s no biggie. It&#8217;s only slightly different than it was in AS2. To do it, we&#8217;ll need to use (2) new AS3 classes: <strong>URLLoader</strong> and <strong>URLReques</strong>t. <strong>URLRequest</strong> replaces <strong>getURL()</strong> and you can think of <strong>URLLoader</strong> like <strong>MovieClipLoader</strong> which allows us to monitor loading and do stuff in response to it. Ok, so with that in mind:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> company<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">XML</span><span style="color: #000066; font-weight: bold;">;</span>
<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>
<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> <span style="color: #990000;">&quot;company.xml&quot;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&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> request <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<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> onComplete <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #339966; font-weight: bold;">function</span> onComplete<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>
   <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: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span> event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
   company = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">loader</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>
   <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> company<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toXMLString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>And we&#8217;re just scratching the surface of what E4X has to offer. That alone is worth the price of admission to the world of AS3&#8230;</p>
<div style="float: right; padding: 3px;"><a href="http://bufferapp.com/add" class="buffer-add-button" data-text="The Joy of E4X!" data-url="http://technophi.com/2006/07/03/the-joy-of-e4x/" data-via="bufferapp" data-count="none">Buffer</a><script type="text/javascript" src="http://static.bufferapp.com/js/button.js"></script></div><div id="tweetbutton62" class="tw_button" style="padding: 3px;float:right;margin-left:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Fj.mp%2FiMzdt9&amp;via=heroizm&amp;text=The%20Joy%20of%20E4X%21&amp;related=heroizm&amp;lang=en&amp;count=none&amp;counturl=http%3A%2F%2Ftechnophi.com%2F2006%2F07%2F03%2Fthe-joy-of-e4x%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://technophi.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://technophi.com/2006/07/03/the-joy-of-e4x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

