<?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</title>
	<atom:link href="http://blog.enestrom.com/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>I think I&#8217;m in love with Felicia Day</title>
		<link>http://blog.enestrom.com/20100127/i-think-im-in-love-with-felicia-day/</link>
		<comments>http://blog.enestrom.com/20100127/i-think-im-in-love-with-felicia-day/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 19:48:16 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/20100127/i-think-im-in-love-with-felicia-day/</guid>
		<description><![CDATA[I&#8217;ve never met her but I think I have a teenage crush on her anyway. If you haven&#8217;t seen The Guild yet, do it now!
Season one

Ps. We&#8217;re the same age too. That has to mean something, man! Ds.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve never met her but I think I have a teenage crush on her anyway. If you haven&#8217;t seen The Guild yet, do it now!</p>
<p><a href="http://www.youtube.com/user/watchtheguild#grid/user/EE93D30C5588A850">Season one</a></p>
<p><object width="512" height="313"><param name="movie" value="http://www.youtube.com/v/urNyg1ftMIU&#038;hl=sv_SE&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/urNyg1ftMIU&#038;hl=sv_SE&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="512" height="313"></embed></object></p>
<p>Ps. We&#8217;re the same age too. That has to mean something, man! Ds.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20100127%2Fi-think-im-in-love-with-felicia-day%2F&amp;linkname=I%20think%20I%26%238217%3Bm%20in%20love%20with%20Felicia%20Day"><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/20100127/i-think-im-in-love-with-felicia-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Google Maps Flash API is sooo fun</title>
		<link>http://blog.enestrom.com/20091011/google-maps-flash-api-is-sooo-fun/</link>
		<comments>http://blog.enestrom.com/20091011/google-maps-flash-api-is-sooo-fun/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 19:32:57 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[RIA]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/20091011/google-maps-flash-api-is-sooo-fun/</guid>
		<description><![CDATA[I&#8217;m implementing some Google Maps magic into a RIA for a client. Together with an auto-location thing using IP numbers the results are indeed stunning. I love Google&#8217;s API&#8217;s!
Google Maps API for Flash Developer Guide
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m implementing some Google Maps magic into a RIA for a client. Together with an auto-location thing using IP numbers the results are indeed stunning. I love Google&#8217;s API&#8217;s!</p>
<p><a href="http://code.google.com/intl/sv-SE/apis/maps/documentation/flash/intro.html">Google Maps API for Flash Developer Guide</a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20091011%2Fgoogle-maps-flash-api-is-sooo-fun%2F&amp;linkname=Google%20Maps%20Flash%20API%20is%20sooo%20fun"><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/20091011/google-maps-flash-api-is-sooo-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phpThumb and imagerotate()</title>
		<link>http://blog.enestrom.com/20090509/phpthumb-and-imagerotate/</link>
		<comments>http://blog.enestrom.com/20090509/phpthumb-and-imagerotate/#comments</comments>
		<pubDate>Sat, 09 May 2009 09:41:12 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[Image processing]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[imagerotate()]]></category>
		<category><![CDATA[phpThumb]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=90</guid>
		<description><![CDATA[One of the PHP libraries I use the most is phpThumb, because of its ease to use and portability. Simply putting the folder in the web root is usually sufficient to get started. One thing has annoyed me for a while though, and it is that I couldn&#8217;t get the rotating commands to work.
After some [...]]]></description>
			<content:encoded><![CDATA[<p>One of the PHP libraries I use the most is phpThumb, because of its ease to use and portability. Simply putting the folder in the web root is usually sufficient to get started. One thing has annoyed me for a while though, and it is that I couldn&#8217;t get the rotating commands to work.</p>
<p>After some research I discovered that the <a href="http://se2.php.net/imagerotate()" target="_blank">imagerotate()</a> function in GD library (a library that handles many of the graphics processing in phpThumb) is only available in the bundled version of GD library (that is: the version that sometimes comes bundled with PHP). That is not the case for me and I have my own server with lots of sites on, and didn&#8217;t feel like recompiling PHP just to get the imagerotate function to work.</p>
<p>So, in this new light, I looked for a function replacement using <a href="http://www.imagemagick.org/script/index.php" target="_blank">ImageMagick</a> instead (a much better image processing library, but rarely installed by default) and found this one somewhere. Simply put it at the bottom of your <em>phpthumb.functions.php </em>file and *poof* rotating images in phpThumb will start working.</p>
<div class="geshi no php">
<div class="head">if ( !function_exists( &#39;imagerotate&#39; ) ) {</div>
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">function</span> imagerotate<span class="br0">&#40;</span> <span class="re1">$source_image</span><span class="sy0">,</span> <span class="re1">$angle</span><span class="sy0">,</span> <span class="re1">$bgd_color</span><span class="sy0">=</span><span class="kw2">null</span> <span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$angle</span> <span class="sy0">=</span> <span class="nu0">360</span><span class="sy0">-</span><span class="re1">$angle</span><span class="sy0">;</span> <span class="co1">// GD rotates CCW, imagick rotates CW</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$temp_src</span> <span class="sy0">=</span> <span class="st0">&#39;/tmp/temp_src.png&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$temp_dst</span> <span class="sy0">=</span> <span class="st0">&#39;/tmp/temp_dst.png&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span>imagepng<span class="br0">&#40;</span><span class="re1">$source_image</span><span class="sy0">,</span><span class="re1">$temp_src</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$imagick</span> <span class="sy0">=</span> <span class="kw2">new</span> Imagick<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$imagick</span><span class="sy0">-&gt;</span><span class="me1">readImage</span><span class="br0">&#40;</span><span class="re1">$temp_src</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$imagick</span><span class="sy0">-&gt;</span><span class="me1">rotateImage</span><span class="br0">&#40;</span><span class="kw2">new</span> ImagickPixel<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">,</span> <span class="re1">$angle</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$imagick</span><span class="sy0">-&gt;</span><span class="me1">writeImage</span><span class="br0">&#40;</span><span class="re1">$temp_dst</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//trigger_error( &#39;imagerotate(): could not write to &#39; . $file1 . &#39;, original image returned&#39;, E_USER_WARNING );</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$result</span> <span class="sy0">=</span> imagecreatefrompng<span class="br0">&#40;</span><span class="re1">$temp_dst</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">unlink</span><span class="br0">&#40;</span><span class="re1">$temp_dst</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">unlink</span><span class="br0">&#40;</span><span class="re1">$temp_src</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="re1">$result</span><span class="sy0">;</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>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20090509%2Fphpthumb-and-imagerotate%2F&amp;linkname=phpThumb%20and%20imagerotate%28%29"><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/20090509/phpthumb-and-imagerotate/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>Firebug equivalent for Internet Explorer</title>
		<link>http://blog.enestrom.com/20081219/firebug-equivalent-for-internet-explorer/</link>
		<comments>http://blog.enestrom.com/20081219/firebug-equivalent-for-internet-explorer/#comments</comments>
		<pubDate>Fri, 19 Dec 2008 10:25:16 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML DOM]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=72</guid>
		<description><![CDATA[I guess I&#8217;m not the only one who&#8217;s been searching for an IE equivalent of Firebug. Being a Mac developer using Visual Studio simply to be able to debug my web sites in IE has never really been an option and the Internet Explorer Developer Toolbar is too simple for my needs. I want to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.debugbar.com/?langage=en" target="_blank"><img class="alignright" title="DebugBar" src="http://www.debugbar.com/data/debugbar-script.gif" alt="" width="151" height="303" /></a>I guess I&#8217;m not the only one who&#8217;s been searching for an IE equivalent of Firebug. Being a Mac developer using Visual Studio simply to be able to debug my web sites in IE has never really been an option and the <a href="http://en.wikipedia.org/wiki/IE_Developer_Toolbar" target="_blank">Internet Explorer Developer Toolbar</a> is too simple for my needs. I want to be able to debug JavaScript, not just CSS and HTML DOM. Long have I pulled my hair trying to find out why the h*ll something is working fine in Firefox/Safari but not in IE.</p>
<p>The other day I came across the <a href="http://www.debugbar.com/?langage=en" target="_blank">DebugBar</a> by the French Toulouse-based company Core Services. It&#8217;s excellent! Well, not as simple, clean and accurate as Firebug, but still way ahead of all the other debug solutions I have found for Internet Explorer. And it also has some good features that Firebug is missing.</p>
<p>Vive la France!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20081219%2Ffirebug-equivalent-for-internet-explorer%2F&amp;linkname=Firebug%20equivalent%20for%20Internet%20Explorer"><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/20081219/firebug-equivalent-for-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>0</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>MySQL Sample Data Creator</title>
		<link>http://blog.enestrom.com/20081023/mysql-sample-data-creator/</link>
		<comments>http://blog.enestrom.com/20081023/mysql-sample-data-creator/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 14:30:21 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Sample data]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=58</guid>
		<description><![CDATA[A year or two back I was in a real need of a lot of sample data for testing a web tool I was working on, so I wrapped up a small tool to generate sample data by defining a few parameters and choosing how many rows to add, using Flex 2 (or perhaps 1.5, [...]]]></description>
			<content:encoded><![CDATA[<p>A year or two back I was in a real need of a lot of sample data for testing a web tool I was working on, so I wrapped up a small tool to generate sample data by defining a few parameters and choosing how many rows to add, using Flex 2 (or perhaps 1.5, don&#8217;t remember). Well today the need arose again, so I went through my old backup files and found it again. I thought I&#8217;d put it up on the web so as maybe someone else could be helped by it. I know it&#8217;s not perfect and only spent a few hours creating it, but if you have any suggestions on how to improve it please write a comment and let me know what you think. I would be glad to update it and eventually make it a really useful tool.</p>
<p><a href="http://mysqlsampledata.enestrom.com" target="_blank">Go to the MySQL Sample Data Creator 1.0</a></p>
<p><a href="http://mysqlsampledata.enestrom.com" target="_blank"><img class="alignnone size-full wp-image-59" title="MySQL Sample Data Creator" src="http://blog.enestrom.com/wp-content/uploads/mysqlsampledatacreator.gif" alt="" width="400" height="294" /></a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20081023%2Fmysql-sample-data-creator%2F&amp;linkname=MySQL%20Sample%20Data%20Creator"><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/20081023/mysql-sample-data-creator/feed/</wfw:commentRss>
		<slash:comments>0</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>8</slash:comments>
		</item>
		<item>
		<title>AMFPHP and Flex</title>
		<link>http://blog.enestrom.com/20080808/amfphp-and-flex/</link>
		<comments>http://blog.enestrom.com/20080808/amfphp-and-flex/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 13:44:45 +0000</pubDate>
		<dc:creator>Daniel Eneström</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[Tutorial]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=13</guid>
		<description><![CDATA[Being a LAMP (Linux Apache MySQL PHP) guy as well as a Flex developer it didn&#8217;t take me long to discover AMFPHP. If you haven&#8217;t heard of it I can tell you in short it&#8217;s a framework for sending and receiving data between Actionscript and PHP, without having to use an XML layer or similar [...]]]></description>
			<content:encoded><![CDATA[<p>Being a LAMP <em>(Linux Apache MySQL PHP)</em> guy as well as a Flex developer it didn&#8217;t take me long to discover <a href="http://www.amfphp.org/" target="_blank">AMFPHP</a>. If you haven&#8217;t heard of it I can tell you in short it&#8217;s a framework for sending and receiving data between Actionscript and PHP, without having to use an XML layer or similar in between, so to speak. It&#8217;s really neat, because lets say you extract an array of rows from your MySQL database, then you can just pass the entire array back to Actionscript and it will be received as an Actionscript array in the other end.</p>
<p>Would you like to try it? This is how to do it:</p>
<p>1. Download the latest AMFPHP package from <a href="http://www.amfphp.org/" target="_blank">www.amfphp.org</a></p>
<p>2. Unpack and (preferably) place the folder called <em>amfphp</em> in the document root on your web server.</p>
<p>3. By default the AMFPHP gateway is set to converting all UTF-8 data to Latin 1. Big NO NO for &#8220;international&#8221; developers like me, so you should open the <em>gateway.php</em> file in the <em>amfphp</em> folder for editing and change the following line (it should be around line 127):</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$gateway</span><span class="sy0">-&gt;</span><span class="me1">setCharsetHandler</span><span class="br0">&#40;</span><span class="st0">&quot;utf8_decode&quot;</span><span class="sy0">,</span> <span class="st0">&quot;ISO-8859-1&quot;</span><span class="sy0">,</span> <span class="st0">&quot;ISO-8859-1&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>to </p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$gateway</span><span class="sy0">-&gt;</span><span class="me1">setCharsetHandler</span><span class="br0">&#40;</span><span class="st0">&quot;iconv&quot;</span><span class="sy0">,</span><span class="st0">&quot;UTF-8&quot;</span><span class="sy0">,</span><span class="st0">&quot;UTF-8&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>If you don&#8217;t do this all UTF-8 special characters from the database will be distorted on arriving at the Flex application.</p>
<p>4. Now create a simple PHP class file, call it <em>HelloWorld.php</em>, and place it in the <em>/amfphp/services</em> folder. You should use a commenting pattern like that of PHPDoc. Here is a simple HelloWorld example:</p>
<div class="geshi no php">
<div class="head">/**</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;<span class="sy0">*</span> A simple amfphp service<span class="sy0">.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="sy0">*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> HelloWorld</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; * A simple HelloWorld function</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; * @returns A string containing the phrase &#39;Hello World!&#39;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">function</span> SayHello<span class="br0">&#40;</span><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; <span class="kw1">return</span> <span class="st0">&quot;Hello World!&quot;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; * A simple HelloWorld function that bounces back the given string</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; * @returns A string containing the supplied string</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp; */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">function</span> SayWhat<span class="br0">&#40;</span><span class="re1">$string</span><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; <span class="kw1">return</span> <span class="re1">$string</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>In this class I&#8217;ve put two functions; one that returns the string &#8216;Hello World!&#8217; and another that returns whatever string you send to it. Okay, so let&#8217;s get on with the show&#8230;</p>
<p>5. Now you can test your service by browsing to the <em>browser</em> folder. It should have a URL similar to this: <em>yourserver.com/amfphp/browser</em>. In the service browser you can test whether your class is working as it should.</p>
<p>6. <strong>Flex<br />
</strong>To simplify things I&#8217;ve created a small class for the implementation of this in Flex. There is a number of ways of doing this, but I&#8217;ve chosen the one way that I am most comfortable with.</p>
<p>For ease of use, create an actionscript document in your Flex Projects root directory called <em>AMFPHP.as</em> and past the following code into the file:</p>
<div class="geshi no actionscript">
<div class="head">package {</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">net</span>.<span class="kw3">NetConnection</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">import</span> flash.<span class="me1">net</span>.<span class="me1">Responder</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">public</span> <span class="kw2">class</span> AMFPHP</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">private</span> <span class="kw3">static</span> <span class="kw2">var</span> gateway:<span class="kw3">String</span> = <span class="st0">&quot;http://www.yourserver.com/amfphp/gateway.php&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">private</span> <span class="kw3">static</span> <span class="kw2">var</span> connection:<span class="kw3">NetConnection</span> = <span class="kw2">new</span> <span class="kw3">NetConnection</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; connection.<span class="kw3">connect</span><span class="br0">&#40;</span>gateway<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">public</span> <span class="kw2">function</span> AMFPHP<span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Static class</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">public</span> <span class="kw3">static</span> <span class="kw2">function</span> <span class="kw3">send</span><span class="br0">&#40;</span>serviceFunction:<span class="kw3">String</span>, resultHandler:<span class="kw2">Function</span>, faultHandler:<span class="kw2">Function</span>, &#8230; <span class="me1">args</span>:<span class="sy0">*</span><span class="br0">&#41;</span> : <span class="kw3">void</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &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; &nbsp;<span class="co1">// Create responder</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &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; &nbsp;<span class="co1">// Create an array that will temporarily store all the arguments</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &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; &nbsp;<span class="co1">// Add the fixed arguments</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &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; &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; &nbsp;<span class="co1">// Loop through the optional arguments and add them too</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &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; &nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &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; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Create a reference to the function we will call</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &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; &nbsp;<span class="co1">// Call the function using the arguments</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &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">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The only thing you have to change here is the URL to the <em>gateway.php </em>file on your server at line 7 in the file.</p>
<p>7. Usage</p>
<p>To use this in your code you will need three things:</p>
<p>• Calling the service using the static AMFPHP.send() function<br />
• A function that handles the result coming from amfphp<br />
• A function that handles errors</p>
<p>This is the first HelloWorld example (without the argument). The first argument for the send() function is a string describing the path to the function, with this structure: <em>[directory.]class.function</em>, within the services folder. A directory is not necessary, but can be convenient if you have packages of many classes.</p>
<div class="geshi no actionscript">
<div class="head">private function helloWorld() : void</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;AMFPHP.<span class="kw3">send</span><span class="br0">&#40;</span><span class="st0">&quot;HelloWorld.SayHello&quot;</span>,onResult,onFault<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onResult<span class="br0">&#40;</span>result:<span class="kw3">String</span><span class="br0">&#41;</span> : <span class="kw3">void</span></div>
</li>
<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>result<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onFault<span class="br0">&#40;</span>result:<span class="kw3">Object</span><span class="br0">&#41;</span> : <span class="kw3">void</span></div>
</li>
<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="kw3">String</span><span class="br0">&#40;</span>result.<span class="me1">description</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Easy huh!?</p>
<p>And the example with the argument is pretty much the same, but with an argument added to the end of the function call. Like this:</p>
<div class="geshi no actionscript">
<div class="head">private function helloWorld() : void</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;AMFPHP.<span class="kw3">send</span><span class="br0">&#40;</span><span class="st0">&quot;HelloWorld.SayWhat&quot;</span>, onResult, onFault, <span class="st0">&quot;Hello to you!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onResult<span class="br0">&#40;</span>result:<span class="kw3">String</span><span class="br0">&#41;</span> : <span class="kw3">void</span></div>
</li>
<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>result<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">private</span> <span class="kw2">function</span> onFault<span class="br0">&#40;</span>result:<span class="kw3">Object</span><span class="br0">&#41;</span> : <span class="kw3">void</span></div>
</li>
<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="kw3">String</span><span class="br0">&#40;</span>result.<span class="me1">description</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Note that I changed the path to the function from <em>HelloWorld.SayHello</em> to <em>HelloWorld.SayWhat</em> to use the other function in the class.</p>
<p>Well, that&#8217;s it. Hope it was of some use. Good luck!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fblog.enestrom.com%2F20080808%2Famfphp-and-flex%2F&amp;linkname=AMFPHP%20and%20Flex"><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/20080808/amfphp-and-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
