<?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; Flex</title>
	<atom:link href="http://enestrom.com/tag/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://enestrom.com</link>
	<description>Keep It Simply Stupid</description>
	<lastBuildDate>Fri, 23 Dec 2011 00:50:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Flash trace app for Mac OS X</title>
		<link>http://enestrom.com/20110108/flash-trace-app-for-mac-os-x/</link>
		<comments>http://enestrom.com/20110108/flash-trace-app-for-mac-os-x/#comments</comments>
		<pubDate>Sat, 08 Jan 2011 19:36:49 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Adobe Flash]]></category>
		<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Mac OS X]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=135</guid>
		<description><![CDATA[The other day my FlashTracer (Firefox add-on) and my FBTracer (FireBug extension for Firefox) stopped working (again!). I&#8217;m so tired of these flash tracing tools doing this to me all the time and as an addition I&#8217;ve wanted a stand-alone &#8230; <a href="http://enestrom.com/20110108/flash-trace-app-for-mac-os-x/">Continue reading <span class="meta-nav">&#8594;</span></a><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20110108/flash-trace-app-for-mac-os-x/' addthis:title='Flash trace app for Mac OS X ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p><a href="http://enestrom.enkelbutik.se/wp-content/uploads/2011/01/FlashTrace.zip"><img class="alignright size-full wp-image-137" title="Download FlashTrace" src="http://enestrom.enkelbutik.se/wp-content/uploads/2011/01/Skärmavbild-2011-01-08-kl.-20.05.02.jpeg" alt="Download FlashTrace" width="138" height="139" /></a>The other day my FlashTracer (Firefox add-on) and my FBTracer (FireBug extension for Firefox) stopped working (again!). I&#8217;m so tired of these flash tracing tools doing this to me all the time and as an addition I&#8217;ve wanted a stand-alone tool for my flash trace for a while, so I can have the Flash trace and Safari windows visible at the same time, without the need for Firefox (or a massive debugging tool &#8211; I just want a simple trace output). That&#8217;s why this time I wrapped up a small Mac OS app that simply opens Terminal and shows the user the Flash trace output in a Terminal window.</p>
<p>This is no magical app, it still demands that the user has the <a href="http://www.adobe.com/support/flashplayer/downloads.html" target="_blank">DEBUG version of Flash player</a> installed and that your flash trace text file is in this directory:<br />
~/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt<br />
(the ~ meaning your home directory in unix talk)</p>
<p>The app is downloadable below and is free for you to use. Note that I release the app with a <a href="http://sv.wikipedia.org/wiki/GNU_General_Public_License" target="_blank">GPL license</a> and your are welcome to use, distribute and change it. You can open the app using the AppleScript Editor. I would love to hear if you make any useful additions to it but cannot provide any support, sorry.</p>
<p>Enjoy!</p>
<p><a href="http://enestrom.enkelbutik.se/wp-content/uploads/2011/01/FlashTrace.zip">Download FlashTrace.app here</a></p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20110108/flash-trace-app-for-mac-os-x/' addthis:title='Flash trace app for Mac OS X ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://enestrom.com/20110108/flash-trace-app-for-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google Maps Flash API is sooo fun</title>
		<link>http://enestrom.com/20091011/google-maps-flash-api-is-sooo-fun/</link>
		<comments>http://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</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<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20091011/google-maps-flash-api-is-sooo-fun/' addthis:title='Google Maps Flash API is sooo fun ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></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>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20091011/google-maps-flash-api-is-sooo-fun/' addthis:title='Google Maps Flash API is sooo fun ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://enestrom.com/20091011/google-maps-flash-api-is-sooo-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintaining state on Tree Component while updating remote data</title>
		<link>http://enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/</link>
		<comments>http://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</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 &#8230; <a href="http://enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/">Continue reading <span class="meta-nav">&#8594;</span></a><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/' addthis:title='Maintaining state on Tree Component while updating remote data ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></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>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/' addthis:title='Maintaining state on Tree Component while updating remote data ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://enestrom.com/20090312/maintaining-state-on-tree-component-while-updating-remote-data/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Google Analytics and Flex using ExternalInterface</title>
		<link>http://enestrom.com/20081114/google-analytics-and-flex-using-externalinterface/</link>
		<comments>http://enestrom.com/20081114/google-analytics-and-flex-using-externalinterface/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 10:17:09 +0000</pubDate>
		<dc:creator>daniel</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 &#8230; <a href="http://enestrom.com/20081114/google-analytics-and-flex-using-externalinterface/">Continue reading <span class="meta-nav">&#8594;</span></a><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20081114/google-analytics-and-flex-using-externalinterface/' addthis:title='Google Analytics and Flex using ExternalInterface ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></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(&#8216;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>
<pre lang="javascript">function trackURL(url)
{
    pageTracker._trackPageview(url);
}</pre>
<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>
<pre lang="actionscript">package
{
   public class Analytics
   {
      import flash.external.ExternalInterface;

      public static function track(url:String) : void
      {
         ExternalInterface.call("trackURL", url);
      }
   }
}</pre>
<p>And anywhere in your app write:</p>
<pre lang="actionscript">
Analytics.track('/path_to_tha_page_you_want_to_track/');
</pre>
<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>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20081114/google-analytics-and-flex-using-externalinterface/' addthis:title='Google Analytics and Flex using ExternalInterface ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://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://enestrom.com/20081023/mysql-sample-data-creator/</link>
		<comments>http://enestrom.com/20081023/mysql-sample-data-creator/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 14:30:21 +0000</pubDate>
		<dc:creator>daniel</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 &#8230; <a href="http://enestrom.com/20081023/mysql-sample-data-creator/">Continue reading <span class="meta-nav">&#8594;</span></a><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20081023/mysql-sample-data-creator/' addthis:title='MySQL Sample Data Creator ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></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://enestrom.enkelbutik.se/wp-content/uploads/2008/10/mysqlsampledatacreator.gif" alt="" width="400" height="294" /></a></p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20081023/mysql-sample-data-creator/' addthis:title='MySQL Sample Data Creator ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://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://enestrom.com/20080811/passing-on-optional-arguments-in-actionscript-3/</link>
		<comments>http://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</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 &#8230; <a href="http://enestrom.com/20080811/passing-on-optional-arguments-in-actionscript-3/">Continue reading <span class="meta-nav">&#8594;</span></a><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20080811/passing-on-optional-arguments-in-actionscript-3/' addthis:title='Passing on optional arguments in ActionScript 3 ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></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(&#8220;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>
<pre lang="actionscript">
function send(anArgument:Object, ...args)
</pre>
<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>
<pre lang="actionscript">public static function send(serviceFunction:String, resultHandler:Function, faultHandler:Function, ... args:*) : void
{
	trace("AMFPHP("+serviceFunction+")");
	// Create responder
	var responder:Responder = new Responder(resultHandler, faultHandler);
	// Create an array that will temporarily store all the arguments
	var collectArgs:Array = new Array;
	// Add the fixed arguments
	collectArgs.push(serviceFunction);
	collectArgs.push(responder);
	// Loop through the optional arguments and add them too
	for (var i:uint=0; i<args.length; i++)
	{
		collectArgs.push(args[i]);
	}
	// Create a reference to the function we will call
	var callFunction:Function = connection.call;
	// Call the function using the arguments
	callFunction.apply(connection,collectArgs);
}
</pre>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20080811/passing-on-optional-arguments-in-actionscript-3/' addthis:title='Passing on optional arguments in ActionScript 3 ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://enestrom.com/20080811/passing-on-optional-arguments-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>AMFPHP and Flex</title>
		<link>http://enestrom.com/20080808/amfphp-and-flex/</link>
		<comments>http://enestrom.com/20080808/amfphp-and-flex/#comments</comments>
		<pubDate>Fri, 08 Aug 2008 13:44:45 +0000</pubDate>
		<dc:creator>daniel</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 &#8230; <a href="http://enestrom.com/20080808/amfphp-and-flex/">Continue reading <span class="meta-nav">&#8594;</span></a><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20080808/amfphp-and-flex/' addthis:title='AMFPHP and Flex ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></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>
<pre lang="php">
$gateway->setCharsetHandler("utf8_decode", "ISO-8859-1", "ISO-8859-1");
</pre>
<p>to </p>
<pre lang="php">
$gateway->setCharsetHandler("iconv","UTF-8","UTF-8");
</pre>
<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>
<pre lang="php">/**
 * A simple amfphp service.
 */
class HelloWorld
{
	/**
	 * A simple HelloWorld function
	 * @returns A string containing the phrase 'Hello World!'
	 */
	function SayHello()
	{
		return "Hello World!";
	}

	/**
	 * A simple HelloWorld function that bounces back the given string
	 * @returns A string containing the supplied string
	 */
	function SayWhat($string)
	{
		return $string;
	}
}
</pre>
<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>
<pre lang="actionscript">package {
	import flash.net.NetConnection;
	import flash.net.Responder;

	public class AMFPHP
	{
		private static var gateway:String = "http://www.yourserver.com/amfphp/gateway.php";
		private static var connection:NetConnection = new NetConnection;
		connection.connect(gateway);

		public function AMFPHP() : void
		{
			// Static class
		}

		public static function send(serviceFunction:String, resultHandler:Function, faultHandler:Function, ... args:*) : void
		{
			trace("AMFPHP("+serviceFunction+")");
			// Create responder
			var responder:Responder = new Responder(resultHandler, faultHandler);
			// Create an array that will temporarily store all the arguments
			var collectArgs:Array = new Array;
			// Add the fixed arguments
			collectArgs.push(serviceFunction);
			collectArgs.push(responder);
			// Loop through the optional arguments and add them too
			for (var i:uint=0; i<args.length; i++)
			{
				collectArgs.push(args[i]);
			}
			// Create a reference to the function we will call
			var callFunction:Function = connection.call;
			// Call the function using the arguments
			callFunction.apply(connection,collectArgs);
		}
	}
}
</pre>
<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>
<pre lang="actionscript">private function helloWorld() : void
{
	AMFPHP.send("HelloWorld.SayHello",onResult,onFault);
}

private function onResult(result:String) : void
{
	trace(result);
}

private function onFault(result:Object) : void
{
	trace(String(result.description));
}
</pre>
<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>
<pre lang="actionscript">private function helloWorld() : void
{
	AMFPHP.send("HelloWorld.SayWhat", onResult, onFault, "Hello to you!");
}

private function onResult(result:String) : void
{
	trace(result);
}

private function onFault(result:Object) : void
{
	trace(String(result.description));
}
</pre>
<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's it. Hope it was of some use. Good luck!</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20080808/amfphp-and-flex/' addthis:title='AMFPHP and Flex ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://enestrom.com/20080808/amfphp-and-flex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Flex Apache module hell</title>
		<link>http://enestrom.com/20080610/flex-apache-module-hell/</link>
		<comments>http://enestrom.com/20080610/flex-apache-module-hell/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 15:41:45 +0000</pubDate>
		<dc:creator>daniel</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://blog.enestrom.com/?p=4</guid>
		<description><![CDATA[Yesterday I tried to install the flex sdk apache module on the linux server of one of my clients. Note &#8220;tried&#8221;. Problem 1: The Java JRE isn&#8217;t super easy to install. Well, actually it is, but you just have to &#8230; <a href="http://enestrom.com/20080610/flex-apache-module-hell/">Continue reading <span class="meta-nav">&#8594;</span></a><div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20080610/flex-apache-module-hell/' addthis:title='Flex Apache module hell ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></description>
			<content:encoded><![CDATA[<p>Yesterday I tried to install the flex sdk apache module on the linux server of one of my clients. Note &#8220;tried&#8221;.</p>
<p><strong>Problem 1:</strong> The Java JRE isn&#8217;t super easy to install. Well, actually it is, but you just have to realize how to do it and the information out there is quite misleading. I&#8217;m no Linux nerd although I can handle a linux server fairly well. This server was a Debian Etch server, so my hopes were quite high. Apt-get is a good tool. The reason the info was so misleading is that all the articles I could found out there in &#8220;space&#8221; told me you cannot use apt-get to install the Java run-time because of some Sun legal policy. This is not correct. Since sometime in 2005 you <em>can</em> use apt-get to install Java, however you have to add the non-free repository to the sources.list file. Finally I found out how to do it.</p>
<p><strong>Problem 2:</strong> The information in the Flex SDK about the apache module is slight to say the least. It is almost essential to find a third party tutorial on some blog to figure out how to set it up. One thing I hate about Adobe, which could be a result of the multitude of information they&#8217;re hosting, is the fact that all pages refer to other pages, and some of those pages refer back to the first page and so on and so forth.</p>
<p><strong>Final problem: </strong>So I finally performed a manual install of the Flex SDK for Linux! Wohoo! or&#8230; not&#8230;<br />
The final step is to restart the Apache server. &#8220;Nope. I won&#8217;t restart&#8221; he said, sneerfully. &#8220;You are missing an essential thing called <em>GLIBC_2.4</em>. You need that to be able to run the mod_flex.so! Ha ha!&#8221;.</p>
<p>In search of such a thing and why it wasn&#8217;t already there I found out that the glibc library only exist up to version 2.3 for Debian.</p>
<p><strong>Conclusion</strong><br />
I can&#8217;t use the f*king apache module at all and will have to compile my Flex application locally and upload to the server. Too bad, because that will not be easy giving the fact that I&#8217;m not alone in this project. The whole idea behind this new project we&#8217;re on was creating an online application we could build together.</p>
<p>If someone out there has made this work and can help me out&#8230; PLEASE HELP!</p>
<p>Chears<br />
Daniel</p>
<div class="addthis_toolbox addthis_default_style addthis_32x32_style" addthis:url='http://enestrom.com/20080610/flex-apache-module-hell/' addthis:title='Flex Apache module hell ' ><a class="addthis_button_preferred_1"></a><a class="addthis_button_preferred_2"></a><a class="addthis_button_preferred_3"></a><a class="addthis_button_preferred_4"></a><a class="addthis_button_compact"></a></div>]]></content:encoded>
			<wfw:commentRss>http://enestrom.com/20080610/flex-apache-module-hell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

