<?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>Bytearray - Programming, Computers and Technology &#187; Flex</title>
	<atom:link href="http://bytearray.brixtonjunkies.com/category/code/flex/feed/" rel="self" type="application/rss+xml" />
	<link>http://bytearray.brixtonjunkies.com</link>
	<description></description>
	<lastBuildDate>Tue, 03 Nov 2009 11:52:07 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Flex: Multiple File Uploader</title>
		<link>http://bytearray.brixtonjunkies.com/2009/10/01/flex-multiple-file-uploader/</link>
		<comments>http://bytearray.brixtonjunkies.com/2009/10/01/flex-multiple-file-uploader/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 14:32:27 +0000</pubDate>
		<dc:creator>alchemist</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[file uploader]]></category>
		<category><![CDATA[flex uploader]]></category>
		<category><![CDATA[multi uploader]]></category>
		<category><![CDATA[uploader]]></category>

		<guid isPermaLink="false">http://bytearray.brixtonjunkies.com/?p=529</guid>
		<description><![CDATA[Uploading is such a common task and can often be a little painful so I decided to write a small library in Flex which simplifies the task. I have released it under GPL license so feel free to use and modify it according to the conditions  
The Flex client side uploader supports multiple file [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bytearray.brixtonjunkies.com/wp-content/uploads/2009/10/uploader.jpg"><img class="size-full wp-image-528  alignleft" title="Flex Multi Uploader" src="http://bytearray.brixtonjunkies.com/wp-content/uploads/2009/10/uploader.jpg" alt="Flex Multi Uploader" width="378" height="178" /></a>Uploading is such a common task and can often be a little painful so I decided to write a small library in Flex which simplifies the task. I have released it under GPL license so feel free to use and modify it according to the conditions <img src='http://bytearray.brixtonjunkies.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>The Flex client side uploader supports multiple file upload with queuing and multiple threads, meaning more than one upload can be active at a time. It is also written in component style so creating an instance of the uploader is very simple and can be achieved in only a few lines of code <em>(see the example below).</em> It also supports posted additional data with the file upload, handy if you need to pass instructions to the back-end upload script.</p>
<p>The back-end script is not included in the library but could easily be implemented in any language. I have however supplied a <strong>PHP</strong> example below of how to implement the back-end script to support the Flex uploader <em>(see the example below).</em> </p>
<p>One final note, this code is not polished, it&#8217;s definitely Alpha&#8230;but still very usable. If you have any issues or questions please let me know, cheers.</p>
<p><em><strong>Simple example implementation of uploader library</strong></em></p>
<pre class="brush: as3;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;mx:Application xmlns:mx=&quot;http://www.adobe.com/2006/mxml&quot;
				xmlns:cc=&quot;FileUploader.Renderers.*&quot;
				layout=&quot;absolute&quot;
			    creationComplete=&quot;{init()}&quot;
			    width=&quot;1018&quot;
			    height=&quot;455&quot;
				&gt;
	&lt;mx:Script&gt;
		&lt;![CDATA[

			private function init():void{
				fileUploader.addPostData('mydata','1234567890');
			}

		]]&gt;
	&lt;/mx:Script&gt;

	&lt;cc:FileUploadComp id=&quot;fileUploader&quot;
					   x=&quot;0&quot;
					   top=&quot;8&quot;
					   left=&quot;8&quot;
					   width=&quot;1000&quot;
					   maxThreadsEnabled=&quot;true&quot;
					   uploadUrl=&quot;http://a.b.c.d/MyUploaderScript.php&quot;
					   /&gt;
&lt;/mx:Application&gt;
</pre>
<p><em><br />
<strong>PHP backend example implementation of uploader code</strong></em></p>
<pre class="brush: php;">
&lt;?php
	$tmpFileName = isset($_FILES['Filedata']['tmp_name']) ? $_FILES['Filedata']['tmp_name'] : '';
	$orgFileName = isset($_FILES['Filedata']['name']) ? $_FILES['Filedata']['name'] : '';
	$mydata = isset($_REQUEST['mydata']) ? $_REQUEST['mydata'] : '';

	error_log('tmpfile: ' . $tmpFileName);
	error_log('filename: ' . $orgFileName);
	error_log('mydata: ' . $mydata);	

	if (true){
		print 'ok';
	}
	else{
		header('Status: 500 ' . $resultAry[1]);
		header('HTTP/1.1 500 ' . $resultAry[1]);

		$outputStr = '&lt;!DOCTYPE HTML PUBLIC \&quot;-//IETF//DTD HTML 2.0//EN\&quot;&gt;' .
				 '&lt;html&gt;&lt;head&gt;' .
				 '&lt;title&gt;500 ' . $resultAry[1] . '&lt;/title&gt;' .
				 '&lt;/head&gt;&lt;body&gt;' .
				 '&lt;h1&gt;500 ' . $resultAry[1] . '&lt;/h1&gt;' .
				 '&lt;hr&gt;' .
				 $_SERVER['SERVER_SIGNATURE'] .
				 '&lt;/body&gt;&lt;/html&gt;';
		print $outputStr;
	}
?&gt;
</pre>
<p>Also here&#8217;s and example of a Flash <strong>crossdomain.xml</strong><em> (this one is reasonably open!)</em> which will be needed in the <strong>root</strong> of your site&#8230;otherwise flex will complain. </p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;!DOCTYPE cross-domain-policy SYSTEM &quot;http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd&quot;&gt;
&lt;cross-domain-policy&gt;
	&lt;allow-access-from domain=&quot;*&quot; to-ports=&quot;*&quot;/&gt;
	&lt;site-control permitted-cross-domain-policies=&quot;all&quot;/&gt;
&lt;/cross-domain-policy&gt;
</pre>
<p style="text-align: center;"><a rel="nofollow" href="http://bytearray.brixtonjunkies.com/wp-content/uploads/uploader/FlexUploaderExample.html" target="_blank">Demo Flex Uploader</a></p>
<p style="text-align: center;"><a href="http://bytearray.brixtonjunkies.com/wp-content/uploads/2009/10/FlexFileUploader.zip">DOWNLOAD (version 1.0a)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bytearray.brixtonjunkies.com/2009/10/01/flex-multiple-file-uploader/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Flex: View Source Code</title>
		<link>http://bytearray.brixtonjunkies.com/2009/08/21/flex-view-source-code/</link>
		<comments>http://bytearray.brixtonjunkies.com/2009/08/21/flex-view-source-code/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 16:12:31 +0000</pubDate>
		<dc:creator>alchemist</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[flexbuilder]]></category>
		<category><![CDATA[release build]]></category>
		<category><![CDATA[right click]]></category>
		<category><![CDATA[view source]]></category>
		<category><![CDATA[viewSourceURL]]></category>

		<guid isPermaLink="false">http://bytearray.brixtonjunkies.com/?p=201</guid>
		<description><![CDATA[If you want to publish your application source code by right-clicking on the application SWF and you&#8217;re using FlexBuilder then from the top menu bar select:

File-&#62;Export-&#62;Release Build
Right click you project folder and select &#8220;Export&#8221;

Alternatively if you want to format the source code your self then you can set the &#8220;viewSourceURL&#8221; attribute in the Application tag [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to publish your application source code by right-clicking on the application SWF and you&#8217;re using FlexBuilder then from the top menu bar select:</p>
<ul>
<li>File<strong>-&gt;</strong>Export<strong>-&gt;</strong>Release Build</li>
<li>Right click you project folder and select &#8220;Export&#8221;</li>
</ul>
<p>Alternatively if you want to format the source code your self then you can set the &#8220;viewSourceURL&#8221; attribute in the <span style="text-decoration: underline;">Application</span> tag which should enable the &#8220;View Source&#8221; option on the right-click menu. And of course when you click &#8220;View Source&#8221; you should be navigated to the value of &#8220;viewSourceURL&#8221;.</p>
<p style="text-align: center;">For more information: <a href="http://www.adobe.com/cfusion/communityengine/index.cfm?event=showdetails&amp;loc=en_US&amp;postId=7752&amp;productId=2" target="_blank" rel="nofollow">www.adobe.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://bytearray.brixtonjunkies.com/2009/08/21/flex-view-source-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex: High Definition MP4 with Flex VideoDisplay</title>
		<link>http://bytearray.brixtonjunkies.com/2009/08/21/high-definition-mp4-with-flex-videodisplay/</link>
		<comments>http://bytearray.brixtonjunkies.com/2009/08/21/high-definition-mp4-with-flex-videodisplay/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 15:35:50 +0000</pubDate>
		<dc:creator>alchemist</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[h264]]></category>
		<category><![CDATA[hd]]></category>
		<category><![CDATA[high definition]]></category>
		<category><![CDATA[mp4]]></category>
		<category><![CDATA[videodisplay]]></category>

		<guid isPermaLink="false">http://bytearray.brixtonjunkies.com/?p=185</guid>
		<description><![CDATA[ Firstly I just like to say it&#8217;s not really true &#8220;High Definition&#8221; but rather &#8220;Higher Definition&#8221;. However if you are are looking to improve playback via the Flex VideoDisplay component then make sure you encode your mp4 (which is in fact not really an mp4) using the H264 codec, sometimes referred to as AVC [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-full wp-image-186 alignleft" title="HD" src="http://bytearray.brixtonjunkies.com/wp-content/uploads/2009/08/hd.png" alt="HD" width="83" height="62" /> Firstly I just like to say it&#8217;s not really true &#8220;High Definition&#8221; but rather &#8220;<span style="text-decoration: underline;">Higher</span> Definition&#8221;. However if you are are looking to improve playback via the Flex <a href="http://livedocs.adobe.com/flex/3/langref/mx/controls/VideoDisplay.html" target="_blank" rel="nofollow">VideoDisplay</a> component then make sure you encode your mp4 <em>(which is in fact not really an mp4)</em> using the H264 codec, sometimes referred to as AVC or AVC1. It&#8217;s not really a big issue as there are plenty of free H264 encoders around, like <a href="http://www.h264encoder.com" target="_blank" rel="nofollow">www.h264encoder.com</a></p>
<p>You &#8216;ll soon know if the mp4 is encoded correctly as you&#8217;ll probably get a black square box with no video and only audio if the mp4 is not compatible.</p>
]]></content:encoded>
			<wfw:commentRss>http://bytearray.brixtonjunkies.com/2009/08/21/high-definition-mp4-with-flex-videodisplay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex: ExternalInterface &#8211; The Flex Javascript Bridge</title>
		<link>http://bytearray.brixtonjunkies.com/2009/08/21/flex-externalinterface-the-flex-javascript-bridge/</link>
		<comments>http://bytearray.brixtonjunkies.com/2009/08/21/flex-externalinterface-the-flex-javascript-bridge/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 14:56:51 +0000</pubDate>
		<dc:creator>alchemist</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[cookie]]></category>
		<category><![CDATA[externalinterface]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://bytearray.brixtonjunkies.com/?p=53</guid>
		<description><![CDATA[It is really very easy to gain access to Javascript via Flex, the Javascript API is made available via flash.external.ExternalInterface flex class. There are a couple of methods you can use, you can either:

Make calls to pre-existing functions (yours or exists JS ones) using the flex  ExternalInterface.call function where the argument to call is [...]]]></description>
			<content:encoded><![CDATA[<p>It is really very easy to gain access to Javascript via Flex, the Javascript API is made available via <strong>flash.external.ExternalInterface</strong> flex class. There are a couple of methods you can use, you can either:</p>
<ul>
<li>Make calls to pre-existing functions <em>(yours or exists JS ones)</em> using the flex  <strong>ExternalInterface.call</strong> function where the argument to <strong>call</strong> is a string which represents the normal Javascript function invocation.</li>
<li> Defined a whole Javascript function inside Flex as a string and pass that string to <strong>call</strong>, ExternalInterface.call will then automatically execute the function.</li>
</ul>
<p><em>There is of course no real use in passing in arguments if you are pre-defining the Javascript function as a string because you can just use those value during the generation of the string.<br />
</em></p>
<p><strong>Below is an example of creating and fetching a Javascript cookie, you never know it might come in handy</strong> <img src='http://bytearray.brixtonjunkies.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre class="brush: as3;">
// ************************ START EXAMPLE *****************************

/**
 * Flex class ExternalInterface does all the magic
 */

import flash.external.ExternalInterface;

public function createCookie(name:String,value:String,days:int=0):void{

    var js:String = &quot;function createCookie(){&quot; +
                     &quot;var expires = '';&quot; +

    &quot;if (&quot; + days + &quot; &gt; 0){&quot; +
        &quot;var date = new Date();&quot; +
        &quot;date.setTime(date.getTime()+(&quot; + days + &quot;*24*60*60*1000));&quot; +
        &quot;expires = 'expires = ' + date.toGMTString();&quot; +
        &quot;}&quot; +
        &quot;document.cookie = '&quot; + name + &quot;=&quot; + value + &quot;; expires=' + expires + '; path=/';&quot; +
    &quot;}&quot;;

    ExternalInterface.call(js);

}

public function getCookie(cookieName:String):String {

   var r:String = &quot;&quot;;

    var search:String = cookieName + &quot;=&quot;;
    var js:String = &quot;function getCookie(){return document.cookie;}&quot;;
    var cookieVariable:String = ExternalInterface.call(js).toString();

    if (cookieVariable.length &gt; 0) {
        var offset:int = cookieVariable.indexOf(search);
        if (offset != -1) {
            offset += search.length;
            var end:int = cookieVariable.indexOf(&quot;;&quot;, offset);
            if (end == -1){
                end = cookieVariable.length;
            }
            r = unescape(cookieVariable.substring(offset, end));
        }
    }

    return r;

}

// ************************ END EXAMPLE *****************************
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bytearray.brixtonjunkies.com/2009/08/21/flex-externalinterface-the-flex-javascript-bridge/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex: Google Analytics Howto</title>
		<link>http://bytearray.brixtonjunkies.com/2009/08/20/flex-google-analytics-howto/</link>
		<comments>http://bytearray.brixtonjunkies.com/2009/08/20/flex-google-analytics-howto/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 17:51:20 +0000</pubDate>
		<dc:creator>alchemist</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[google analytics]]></category>

		<guid isPermaLink="false">http://bytearray.brixtonjunkies.com/?p=54</guid>
		<description><![CDATA[How do you track events in Google Analytics (GA)? Well it&#8217;s easy enough when your&#8217;re dealing with regular html markup web pages (I&#8217;m assuming your&#8217;ve done a basic implementation of Google Analytics before), but what about flex. Once the webpage that your main flex application sits in is loaded nothing else will be tracked by [...]]]></description>
			<content:encoded><![CDATA[<p>How do you track events in Google Analytics (GA)? Well it&#8217;s easy enough when your&#8217;re dealing with regular html markup web pages <em>(I&#8217;m assuming your&#8217;ve done a basic implementation of Google Analytics before)</em>, but what about flex. Once the webpage that your main flex application sits in is loaded nothing else will be tracked by GA.</p>
<p>The easiest way to track any action in a Flex application using GA is to use the Flex-Javascript bridge in <strong>flash.external.ExternalInterface</strong></p>
<p>Also you don&#8217;t want any possibility that Flex is going to hang around for the Javascript call to complete, and if there&#8217;s a communication issue then GA could slow down your program. So in a nunshell  what is needed is an asynchronous event driven framework for GA which is implemented around Flex ExternalInterface calls to Javascript.</p>
<p>In order to make the below example work you will need a Google account with Analytics setup on a domain. You will need to check your supplied GA Javascript code and find your unique tracking ID, which will look something like: UA-xxxxxxx-x. You can setup and test the below code to a point in FlexBuilder but ultimately you will need to integrate your code onto your website URL which is registered with GA. The GA Javascript code will not execute unless it&#8217;s running integrated on your website <em>(it&#8217;s most likely due to Javascript environment variables or the lake of)</em></p>
<p><strong>Tip:</strong><br />
You need a tool to monitor HTTP traffic from your browser, Firefox has plug-in call: Tamper Data which works well enough. </p>
<p><em><strong>This is the core Google Analytics code which should always be listening for Flex tracking events and ultimately makes the Javascript call to track your custom event. </strong></em></p>
<pre class="brush: as3;">
package Framework.Utilities.GoogleAnalytics{

	import Framework.Utilities.GoogleAnalytics.Events.TrackingEvent;
	import Framework.Utilities.JavascriptAPI;

	import flash.events.EventDispatcher;

	public class GoogleAnalytics{

		private var globalEventDispatcher:EventDispatcher = null;

		private var trackingId:String = '';

		private var javascriptApi:JavascriptAPI = null;

		public static const GANALYTICS_URI_SOAP_PREFIX:String = '/SOAP/';

		public static const GANALYTICS_URI_UI_PREFIX:String = '/UI/';

		public function GoogleAnalytics(globalEventDispatcher:EventDispatcher,trackingId:String = ''){
			this.trackingId = trackingId;
			this.globalEventDispatcher = globalEventDispatcher;
			javascriptApi = new JavascriptAPI();
			initListeners();
		}

		public function setTrackingId(trackingId:String):void{
			this.trackingId = trackingId;
		}

		public function getTrackingId():String{
			return trackingId;
		}

		private function initListeners():void{
			this.globalEventDispatcher.addEventListener(TrackingEvent.GOOGLE_TRACKING_EVENT,trackingHandler);
		}

		private function trackingHandler(te:TrackingEvent):void{
	    	var currentTrackingId:String = trackingId;
	    	if (te.getTrackingId() != null){
	    		if (te.getTrackingId() != ''){
	    			currentTrackingId = te.getTrackingId();
	    		}
	    	}

	    	if (currentTrackingId != null){
	    		if (currentTrackingId != ''){
	    			// Make the google analytics call via javascript
	    			javascriptApi.googleTracker(currentTrackingId,te.urlOrUrl);
	    		}
	    	}
		}

	}
}
</pre>
<p><em><br />
<strong>This is the tracking event which will hold your custom Google Analytics call which will be fired every time you want to track something in Flex.</strong></em></p>
<pre class="brush: as3;">
package Framework.Utilities.GoogleAnalytics.Events{

	import flash.events.Event;

	public class TrackingEvent extends Event{

	    public static const GOOGLE_TRACKING_EVENT:String = 'GOOGLE_TRACKING_EVENT';

	    public var urlOrUrl:String = '';

	    private var trackingId:String = '';

	    public function TrackingEvent(urlOrUrl:String,type:String = GOOGLE_TRACKING_EVENT):void{
	    	this.urlOrUrl = urlOrUrl;
	    	super(type);
	    }

	    public function setTrackingId(trackingId:String):void{
	    	this.trackingId = trackingId;
	    }

	    public function getTrackingId():String{
	    	return trackingId;
	    }

		public override function clone():Event{
			var trackingEvent:TrackingEvent = new TrackingEvent(urlOrUrl,type);
			trackingEvent.setTrackingId(trackingId);

	    	return trackingEvent;
		}
	}
}
</pre>
<p><em><br />
<strong>This is a small class which uses the Flex ExternalInterface call to execute Google Analytics Javascript, which in turn makes an HTTP call to the GA server.  </strong></em></p>
<pre class="brush: as3;">
package Framework.Utilities{

	import flash.external.ExternalInterface;

	public class JavascriptAPI{

		public static const PLUGIN_MODE:int = 0;

		public static const AIR_MODE:int = 1;

		public static const GANALYTICS_URI_SOAP_PREFIX:String = '/SOAP/';

		private var mode:int = 0;

		public function JavascriptAPI(mode:int = 0){
			this.mode = mode;
		}

		public function googleTracker(trackerId:String,action:String):void{
			if (mode == PLUGIN_MODE){
				var js:String = &quot;function googleTracker(){&quot; +
								&quot;var pageTracker = _gat._getTracker('&quot; + trackerId + &quot;');&quot;+
								&quot;pageTracker._trackPageview('&quot; + action + &quot;');}&quot;;
				ExternalInterface.call(js);
			}
		}
	}
}
</pre>
<p><em><br />
<strong>This is how you use the above code</strong></em></p>
<pre class="brush: as3;">

/**
 * Where myEventDispatcher extends an EventDispatcher
 */

var googleAnalytics:GoogleAnalytics = new GoogleAnalytics(myEventDispatcher);
googleAnalytics.setTrackingId(myGoogleAnalyticsId);

/**
 * Then somewhere else in your application do this
 * to track your something in Google Analytics
 */

var googleTrackingEvent:TrackingEvent = new TrackingEvent('myTrackingStringOrUrl');
myEventDispatcher.dispatchEvent(googleTrackingEvent);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://bytearray.brixtonjunkies.com/2009/08/20/flex-google-analytics-howto/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
