<?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>Daniel Eneström &#187; AS3</title>
	<atom:link href="http://blog.enestrom.com/tag/as3/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.enestrom.com</link>
	<description>Ramblings of a web developer</description>
	<lastBuildDate>Wed, 27 Jan 2010 19:49:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Create iPhone apps using Flash</title>
		<link>http://blog.enestrom.com/20091021/create-iphone-apps-using-flash/</link>
		<comments>http://blog.enestrom.com/20091021/create-iphone-apps-using-flash/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 04:43:24 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flash]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=109</guid>
		<description><![CDATA[I&#8217;m so excited about the upcoming Flash Pro CS5. It will let you create native iPhone applications by exporting your ActionScript 3 movie from Flash. The app will, when it&#8217;s been exported, behave as any other app and can be uploaded to the AppStore etc.
Read more on Adobe Labs

]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m so excited about the upcoming Flash Pro CS5. It will let you create native iPhone applications by exporting your ActionScript 3 movie from Flash. The app will, when it&#8217;s been exported, behave as any other app and can be uploaded to the AppStore etc.<br />
<a href="http://labs.adobe.com/technologies/flashcs5/appsfor_iphone/">Read more on Adobe Labs</a></p>
<p><!-- Smart Youtube --><span class="youtube"><object width="496" height="305"><param name="movie" value="http://www.youtube.com/v/M7SK5ZKAaio&amp;rel=1&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" /><param name="allowFullScreen" value="true" /><embed wmode="transparent" src="http://www.youtube.com/v/M7SK5ZKAaio&amp;rel=1&amp;color1=d6d6d6&amp;color2=f0f0f0&amp;border=0&amp;fs=1&amp;hl=en&amp;autoplay=0&amp;showinfo=0&amp;iv_load_policy=3&amp;showsearch=0" type="application/x-shockwave-flash" allowfullscreen="true" width="496" height="305" ></embed><param name="wmode" value="transparent" /></object></span><a href="http://www.youtube.com/watch?v=M7SK5ZKAaio"><img src="http://img.youtube.com/vi/M7SK5ZKAaio/default.jpg" width="130" height="97" border=0></a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20091021%2Fcreate-iphone-apps-using-flash%2F&amp;linkname=Create%20iPhone%20apps%20using%20Flash"><img src="http://blog.enestrom.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.enestrom.com/20091021/create-iphone-apps-using-flash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintaining state on Tree Component while updating remote data</title>
		<link>http://blog.enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/</link>
		<comments>http://blog.enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 15:29:01 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Remoting]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=80</guid>
		<description><![CDATA[I suppose I&#8217;m not the only one who&#8217;s had problems with maintaining the state of a flex tree component upon updating the data. Recently I encountered the problem again and decided to crack this nut once and for all. As it turned out it was a lot easier than I had anticipated.
The Scenario
In this particular [...]]]></description>
			<content:encoded><![CDATA[<p>I suppose I&#8217;m not the only one who&#8217;s had problems with maintaining the state of a flex tree component upon updating the data. Recently I encountered the problem again and decided to crack this nut once and for all. As it turned out it was a lot easier than I had anticipated.</p>
<p><strong>The Scenario<br />
</strong>In this particular case I had a tree component displaying a hierarchical view of the pages of a web site. Upon making some certain changes, like dragging and dropping pages to reorder them I felt the need to change the order server-side and reload the data, rather than changing the order inside the dataProvider. I just like it that way better.</p>
<p><strong>The Problem<br />
</strong>So before I reloaded the data I saved the tree&#8217;s open items in a variable called openTreeItems and when I received the new data I tried to reset it by using <em>tree.openItems = openTreeItems</em>.<br />
Nothing happened.</p>
<p><strong>The Research<br />
</strong>So I started doing some research and quickly discovered that to make this work the component uses the <strong>uid</strong> property and on updating the data for the dataProvider Flex reassigns new uid&#8217;s to the items in the collection. So, in short, Flex doesn&#8217;t recognize the items as the same items after the reload, because of the new uid values.</p>
<p>I encountered <a href="http://livedocs.adobe.com/flex/3/html/help.html?content=about_dataproviders_6.html" target="_blank">this article in the Flex 3 Help pages</a> and started experimenting with creating custom classes that implemented the IUID interface and soon discovered that this was way to complicated for the (actually) quite simple problem I had. The pages in my database had unique ID&#8217;s! Why the h*ll couldn&#8217;t I use these values as the uid values instead of the built-in values?</p>
<p><strong>The Solution</strong><br />
I suddenly had an idea: what if I simply add the uid property to my data serverside by using the id value I already had? This could be done in many ways but I chose to alter my SQL query like so: <em><br />
&#8220;SELECT pages.id, <strong>pages.id uid</strong>, &#8230; FROM pages&#8230;&#8221;</em>. This way the value would be passed on into Flex the same way as all the other values.</p>
<p>And, voilà, it worked!<br />
After this tiny alteration of my SQL query Flex recognized my items as the ones saved in the openTreeItems variable and when using <em>tree.invalidateList()</em> before the update and <em>tree.validateNow()</em> after the update there isn&#8217;t even a flicker upon updating the data. Sweetness!</p>
<p>Hope this helps anyone that has had the same problem.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20090312%2Fmaintaining-state-on-tree-component-while-updating-remote-data%2F&amp;linkname=Maintaining%20state%20on%20Tree%20Component%20while%20updating%20remote%20data"><img src="http://blog.enestrom.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Analytics and Flex using ExternalInterface</title>
		<link>http://blog.enestrom.com/20081114/google-analytics-and-flex-using-externalinterface/</link>
		<comments>http://blog.enestrom.com/20081114/google-analytics-and-flex-using-externalinterface/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 10:17:09 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[ExternalInterface]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Google Analytics]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=64</guid>
		<description><![CDATA[A big issue for people creating flash sites is getting the site to work well with Google Analytics. &#8220;The page doesn&#8217;t refresh. How can I track the clicks?&#8221;
Well, it is actually very easy. If you look at the trace script Google Analytics gives you to add to your HTML code you can find a call [...]]]></description>
			<content:encoded><![CDATA[<p>A big issue for people creating flash sites is getting the site to work well with Google Analytics. &#8220;The page doesn&#8217;t refresh. How can I track the clicks?&#8221;</p>
<p>Well, it is actually very easy. If you look at the trace script Google Analytics gives you to add to your HTML code you can find a call to a method that actually records the event. This method is simple to call using JavaScript.</p>
<p>I have solved it like this in my latest Flex App (which is a public site). NOTE: This is for the new trace code version.</p>
<p><strong>1. Paste the Google Analytics trace code as usual just before the &lt;/BODY&gt; tag.</strong><br />
Check your Google Analytics account for the correct code.</p>
<p><strong>2. See to it that your embedded flash works with ExternalInterface.</strong><br />
This can be a bit tricky, but in my experience the things that do the trick are to change <em>allowScriptAccess</em> to <em>always</em> and inside the Flex App call a custom JavaScript function on <em>creationComplete</em> like so: <em>ExternalInterface.call(&#8217;initFlash&#8217;)</em>. In my html this initFlash function creates a variable reference to the embedded flash. This sort of &#8220;creates the connection&#8221; between them. I&#8217;m not sure why this is so, but for me it works, so I&#8217;m happy with that. If there is a need I would be glad to create a more thorough tutorial on the use of ExternalInterface. Just let me know.</p>
<p><strong>3. Create a custom JavaScript that passes the URL you want to register to the Google Analytics script.</strong><br />
This is not necessary, but I have found it easier to work with, as you don&#8217;t need to edit you call from inside of Flex if something changes in the Google code or such.</p>
<div class="geshi no javascript">
<div class="head">function trackURL(url)</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; pageTracker._trackPageview<span class="br0">&#40;</span>url<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><strong>4. Call your custom javascript from within Flex.</strong><br />
I created a static class for this. (I love static classes). I named it <em>Analytics.as</em> and placed it in the root source folder in the Flex App. It looks like this. All it does really is call the JavaScript using ExternalInterface, but putting it within a static class lets you call it from anywhere in your application without having to pass on references to this or that object or function.</p>
<div class="geshi no actionscript">
<div class="head">package</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">public</span> <span class="kw2">class</span> Analytics</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">import</span> flash.<span class="me1">external</span>.<span class="me1">ExternalInterface</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">function</span> track<span class="br0">&#40;</span><span class="kw3">url</span>:<span class="kw3">String</span><span class="br0">&#41;</span> : <span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExternalInterface.<span class="kw3">call</span><span class="br0">&#40;</span><span class="st0">&quot;trackURL&quot;</span>, <span class="kw3">url</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>And anywhere in your app write:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1">Analytics.<span class="me1">track</span><span class="br0">&#40;</span><span class="st0">&#39;/path_to_tha_page_you_want_to_track/&#39;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>(NOTE: You have to start your path with a slash).</p>
<p><strong>There you go.</strong> It now should track the URL:s you want and give you nice statistics.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20081114%2Fgoogle-analytics-and-flex-using-externalinterface%2F&amp;linkname=Google%20Analytics%20and%20Flex%20using%20ExternalInterface"><img src="http://blog.enestrom.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.enestrom.com/20081114/google-analytics-and-flex-using-externalinterface/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Passing on optional arguments in ActionScript 3</title>
		<link>http://blog.enestrom.com/20080811/passing-on-optional-arguments-in-actionscript-3/</link>
		<comments>http://blog.enestrom.com/20080811/passing-on-optional-arguments-in-actionscript-3/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 10:28:32 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flex]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=25</guid>
		<description><![CDATA[The other day I ran into a small problem with optional arguments in Flex. While writing my tutorial on AMFPHP and Flex I decided to create a small static class that would take care of all the boring stuff with calling AMFPHP. This class enables me to simply use AMFPHP.send(&#8221;ServiceName&#8221;, and so on).
However, writing the [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I ran into a small problem with optional arguments in Flex. While writing my tutorial on <a href="http://blog.enestrom.com/20080808/amfphp-and-flex/">AMFPHP and Flex</a> I decided to create a small static class that would take care of all the boring stuff with calling AMFPHP. This class enables me to simply use AMFPHP.send(&#8221;ServiceName&#8221;, and so on).</p>
<p>However, writing the class I realized I wouldn&#8217;t be able to pass on the optional parameters. If I would use:</p>
<div class="geshi no actionscript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> <span class="kw3">send</span><span class="br0">&#40;</span>anArgument:<span class="kw3">Object</span>, &#8230;<span class="me1">args</span><span class="br0">&#41;</span></div>
</li>
</ol>
</div>
<p>&#8230;I wouldn&#8217;t be able to send the args argument to the NetConnection.call method, because actionscript would send a &#8220;bunched up&#8221; array with all the arguments as ONE parameter to the call method, as opposed to a series of parameters, which was what I wanted.</p>
<p>The solution to this is using the <a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Function.html#apply()" target="_blank">Function.apply()</a> method. What I did was to create an empty array and add a series of arguments I wanted to pass on to a function, create a reference to the function and then use the apply method. This is what my finished static method looks like:</p>
<div class="geshi no actionscript">
<div class="head">public static function send(serviceFunction:String, resultHandler:Function, faultHandler:Function, &#8230; args:*) : void</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&quot;AMFPHP(&quot;</span>+serviceFunction+<span class="st0">&quot;)&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Create responder</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">var</span> responder:Responder = <span class="kw2">new</span> Responder<span class="br0">&#40;</span>resultHandler, faultHandler<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Create an array that will temporarily store all the arguments</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">var</span> collectArgs:<span class="kw3">Array</span> = <span class="kw2">new</span> <span class="kw3">Array</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Add the fixed arguments</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;collectArgs.<span class="kw3">push</span><span class="br0">&#40;</span>serviceFunction<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;collectArgs.<span class="kw3">push</span><span class="br0">&#40;</span>responder<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Loop through the optional arguments and add them too</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i:uint=<span class="nu0">0</span>; i<span class="sy0">&lt;</span>args.<span class="kw3">length</span>; i++<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; collectArgs.<span class="kw3">push</span><span class="br0">&#40;</span>args<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Create a reference to the function we will call</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">var</span> callFunction:<span class="kw2">Function</span> = connection.<span class="kw3">call</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Call the function using the arguments</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;callFunction.<span class="kw3">apply</span><span class="br0">&#40;</span>connection,collectArgs<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20080811%2Fpassing-on-optional-arguments-in-actionscript-3%2F&amp;linkname=Passing%20on%20optional%20arguments%20in%20ActionScript%203"><img src="http://blog.enestrom.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://blog.enestrom.com/20080811/passing-on-optional-arguments-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
