<?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>Matt Smith Blog</title>
	<atom:link href="http://www.chaosm.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chaosm.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 27 Dec 2011 18:43:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>EaselJS Canvas vs Flash: Moving an Image</title>
		<link>http://www.chaosm.net/blog/2011/12/23/easeljs-canvas-vs-flash-moving-an-image/</link>
		<comments>http://www.chaosm.net/blog/2011/12/23/easeljs-canvas-vs-flash-moving-an-image/#comments</comments>
		<pubDate>Fri, 23 Dec 2011 20:28:12 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=978</guid>
		<description><![CDATA[This example shows an image moving to the mouse position inside a canvas tag compared to Flash. The HTML5 version uses the EaselJS javascript library and comes from gotoAndLearn() and Activetuts+ tutorials. Both versions are set at 60fps. View a &#8230; <a href="http://www.chaosm.net/blog/2011/12/23/easeljs-canvas-vs-flash-moving-an-image/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This example shows an image moving to the mouse position inside a <a href="http://www.w3schools.com/html5/tag_canvas.asp">canvas tag</a> compared to Flash. The HTML5 version uses the <a href="http://www.easeljs.com">EaselJS</a> javascript library and comes from <a href="http://gotoandlearn.com/play.php?id=152">gotoAndLearn()</a> and <a href="http://active.tutsplus.com/tutorials/html5/getting-started-with-easeljs-a-flash-like-interface-for-the-html5-canvas/">Activetuts+</a> tutorials. Both versions are set at 60fps. View a demo <a href="http://chaosm.net/html5/ex9_easeljs/">here</a>.</p>
<p><a href="http://www.chaosm.net/html5/ex9_easeljs/"><img src="http://www.chaosm.net/blog/wp-content/uploads/2011/12/screenshot.png" alt="" title="cookie" width="600" height="399" class="aligncenter size-full wp-image-991" /></a></p>
<p>HTML5:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;Canvas EaselJS Flash Move Image&lt;/title&gt;
&lt;script src=&quot;easel.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
	var stage;
	var cookieImage = new Image();
	var cookie;

	function init() {
		stage = new Stage(document.getElementById(&quot;canvas&quot;));
		cookieImage.src = 'cookie.png';
  		cookieImage.name = 'cookie';
  		cookieImage.onload = loadGraphics;
	}

	function loadGraphics() {
		cookie = new Bitmap(cookieImage);
		buildInterface();
	}

	function buildInterface() {
		cookie.regX = cookie.image.width*0.5;
		cookie.regY = cookie.image.height*0.5;
		stage.addChild(cookie);
		Ticker.setFPS(60);
		Ticker.addListener(window);
	}

	function tick() {
		cookie.x += (stage.mouseX-cookie.x)*0.1;
		cookie.y += (stage.mouseY-cookie.y)*0.1;
		stage.update();
	}
&lt;/script&gt;
&lt;style&gt;
body {
	font-family: Verdana, Geneva, sans-serif;
	color: #333;
}
canvas {
	background-color: #CCC;
}
&lt;/style&gt;
&lt;/head&gt;

&lt;body onLoad=&quot;init()&quot;&gt;
&lt;div&gt;
  &lt;h1&gt;Canvas EaselJS&lt;/h1&gt;
  &lt;canvas id=&quot;canvas&quot; width=&quot;600&quot; height=&quot;400&quot;&gt;&lt;/canvas&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>AS3:</p>
<pre class="brush: plain; title: ; notranslate">
import flash.events.Event;
import flash.events.MouseEvent;

function easeCookie(e:Event):void {
	cookie_mc.x += (stage.mouseX-cookie_mc.x-cookie_mc.width*0.5)*0.1;
	cookie_mc.y += (stage.mouseY-cookie_mc.y-cookie_mc.height*0.5)*0.1;
}

stage.addEventListener(MouseEvent.MOUSE_OVER, manageMouseOver);

function manageMouseOver(event:MouseEvent):void{
  stage.removeEventListener(MouseEvent.MOUSE_OVER, manageMouseOver);
  stage.addEventListener(Event.MOUSE_LEAVE, manageMouseOut);
  stage.addEventListener(Event.ENTER_FRAME,easeCookie);
  stage.frameRate = 60;
}

function manageMouseOut(event:Event):void{
  stage.removeEventListener(Event.MOUSE_LEAVE, manageMouseOut);
  stage.addEventListener(MouseEvent.MOUSE_OVER, manageMouseOver);
  stage.removeEventListener(Event.ENTER_FRAME,easeCookie);
  stage.frameRate = 0;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/12/23/easeljs-canvas-vs-flash-moving-an-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS3 Fill Background with Image</title>
		<link>http://www.chaosm.net/blog/2011/12/11/css3-fill-background-with-image/</link>
		<comments>http://www.chaosm.net/blog/2011/12/11/css3-fill-background-with-image/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 15:59:47 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=917</guid>
		<description><![CDATA[Using the CSS3 background size property to fill the background with an image. The image is scaled so that it&#8217;s smallest width or height fills the browser. View a demo here. Links: - Image Source - -moz-background-size - -webkit-background-size]]></description>
			<content:encoded><![CDATA[<p>Using the <a href="http://www.w3schools.com/cssref/css3_pr_background-size.asp">CSS3 background size</a> property to fill the background with an image. The image is scaled so that it&#8217;s smallest width or height fills the browser. View a demo <a href="http://chaosm.net/css3/ex9_background_image/index.php">here</a>.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;CSS3 Background Image Cover&lt;/title&gt;
&lt;style&gt;
html {
	height: 100%;
}
body {
	background-image: url(background.png);
	-moz-background-size: cover;
	-o-background-size: cover;
	-webkit-background-size: cover;
	background-size: cover;
}
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Links:<br />
- <a href="http://livestand.yahoo.com">Image Source</a><br />
- <a href="https://developer.mozilla.org/en/CSS/-moz-background-size">-moz-background-size</a><br />
- <a href="http://developer.apple.com/library/safari/#documentation/appleapplications/reference/SafariCSSRef/Articles/StandardCSSProperties.html">-webkit-background-size</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/12/11/css3-fill-background-with-image/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PlayBook Error #2044 Unhandled IOErrorEvent</title>
		<link>http://www.chaosm.net/blog/2011/10/09/playbook-error-2044-unhandled-ioerrorevent/</link>
		<comments>http://www.chaosm.net/blog/2011/10/09/playbook-error-2044-unhandled-ioerrorevent/#comments</comments>
		<pubDate>Sun, 09 Oct 2011 04:13:59 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=823</guid>
		<description><![CDATA[While porting over my Android photo upload demo application to the PlayBook I ran into: Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error. The issue is that you have to get permission to access the shared file system. To &#8230; <a href="http://www.chaosm.net/blog/2011/10/09/playbook-error-2044-unhandled-ioerrorevent/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While porting over my <a href="http://www.chaosm.net/blog/2011/06/04/flex-mobile-upload-photo-to-server-with-php/">Android photo upload demo application</a> to the PlayBook I ran into: Error #2044: Unhandled IOErrorEvent:. text=Error #2038: File I/O Error.</p>
<p><a href="http://www.chaosm.net/blog/wp-content/uploads/2011/10/IMG_00000024.jpg"><img src="http://www.chaosm.net/blog/wp-content/uploads/2011/10/IMG_00000024.jpg" alt="error 2044 playbook screenshot" title="error 2044 playbook" width="470" class="aligncenter size-medium wp-image-826" /></a></p>
<p>The issue is that you have to get permission to <a href="http://docs.blackberry.com/en/developers/deliverables/23959/Overview_1710989_11.jsp">access the shared file system</a>. To do this add &lt;action&gt;access_shared&lt;/action&gt; to blackberry-tablet.xml.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;qnx&gt;
	&lt;authorId&gt;xxxxxxxxxxxxxxxxxxxxxxx&lt;/authorId&gt;
	&lt;author&gt;Matt Smith&lt;/author&gt;
	&lt;permission&gt;access_internet&lt;/permission&gt;
	&lt;permission&gt;use_camera&lt;/permission&gt;
	&lt;action&gt;access_shared&lt;/action&gt;
&lt;/qnx&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/10/09/playbook-error-2044-unhandled-ioerrorevent/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upload Multiple Files in Adobe AIR with Zend AMF and Flex</title>
		<link>http://www.chaosm.net/blog/2011/08/14/upload-multiple-files-in-adobe-air-with-zend-amf-and-flex/</link>
		<comments>http://www.chaosm.net/blog/2011/08/14/upload-multiple-files-in-adobe-air-with-zend-amf-and-flex/#comments</comments>
		<pubDate>Sun, 14 Aug 2011 21:34:52 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=799</guid>
		<description><![CDATA[This is a revised version of this post which allowed a user to upload a single file. Instead a user can select multiple files to upload. On the server we need to upload the Zend Framework (minimal) and create some &#8230; <a href="http://www.chaosm.net/blog/2011/08/14/upload-multiple-files-in-adobe-air-with-zend-amf-and-flex/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is a revised version of <a href="http://www.chaosm.net/blog/2011/08/07/upload-files-in-adobe-air-with-zend-amf-and-flex/">this post</a> which allowed a user to upload a single file. Instead a user can select multiple files to upload.</p>
<p>On the server we need to upload the <a href="http://www.zend.com/community/downloads">Zend Framework (minimal)</a> and create some files. This is how the file structure will end up looking:</p>
<p><img src="http://www.chaosm.net/blog/wp-content/uploads/2011/08/serverfilestructure.png" alt="server file structure" title="serverfilestructure" width="184" height="154" class="alignnone size-full wp-image-767" /></p>
<p>Create index.php (the gateway):</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
error_reporting(E_ALL|E_STRICT);
ini_set(&quot;display_errors&quot;, &quot;on&quot;);

require('Zend/Amf/Server.php');
require_once('vo/FileVO.php');
require_once('service/UploadService.php');

$server = new Zend_Amf_Server();
$server-&gt;setClass(&quot;UploadService&quot;);
$server-&gt;setClassMap(&quot;FileVO&quot;,&quot;FileVO&quot;);

echo($server-&gt;handle());
?&gt;
</pre>
<p>In the service directory create UploadService.php:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
require_once($_SERVER['DOCUMENT_ROOT'].'/chaosm/air/ex2_uploadamf/vo/FileVO.php');
class UploadService
{
	public function __construct() {}

	public function upload(FileVO $data)
	{
		try
		{
			$fileData = $data-&gt;fileData;
			file_put_contents($_SERVER['DOCUMENT_ROOT'].'/chaosm/air/ex2_uploadamf/uploads/'.$data-&gt;fileName,$fileData);
			return true;
		}
		catch (Exception $e)
		{
			throw new Exception($e-&gt;getMessage());
		}
	}
}
?&gt;
</pre>
<p>In the vo directory create FileVO.php (the value object for the file):</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
class FileVO
{
	public $fileName;
	public $fileData;

	function __construct() {}
}
?&gt;
</pre>
<p>In services-config.xml change the endpoint uri (line 17) to the location of the gateway on your server: </p>
<pre class="brush: plain; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;services-config&gt;
    &lt;services&gt;
        &lt;service id=&quot;amfphp-flashremoting-service&quot; class=&quot;flex.messaging.services.RemotingService&quot; messageTypes=&quot;flex.messaging.messages.RemotingMessage&quot;&gt;
            &lt;destination id=&quot;zendamf&quot;&gt;
                &lt;channels&gt;
                    &lt;channel ref=&quot;zend-amf-channel&quot;/&gt;
                &lt;/channels&gt;
                &lt;properties&gt;
                    &lt;source&gt;*&lt;/source&gt;
                &lt;/properties&gt;
            &lt;/destination&gt;
        &lt;/service&gt;
    &lt;/services&gt;
    &lt;channels&gt;
        &lt;channel-definition id=&quot;zend-amf-channel&quot; class=&quot;mx.messaging.channels.AMFChannel&quot;&gt;
            &lt;endpoint uri=&quot;http://www.chaosm.net/air/ex2_uploadamf/&quot; class=&quot;flex.messaging.endpoints.AMFEndpoint&quot;/&gt;
        &lt;/channel-definition&gt;
    &lt;/channels&gt;
&lt;/services-config&gt;
</pre>
<p>Finally make a directory called uploads. This is where files will be written to, so it needs to have the required permissions (such as 777).</p>
<p>In Flash Builder create a new Flex project called UploadAMF (or import my .fxp file). This is how the file structure will end up looking:</p>
<p><img src="http://www.chaosm.net/blog/wp-content/uploads/2011/08/flashfilestructure.png" alt="flash builder file structure" title="flashfilestructure" width="170" height="169" class="alignnone size-full wp-image-746" /></p>
<p>Right-click on the project and select Properties. Include the services-config.xml under additional compiler arguments like this: </p>
<p><a href="http://www.chaosm.net/blog/wp-content/uploads/2011/08/screenshot.png"><img src="http://www.chaosm.net/blog/wp-content/uploads/2011/08/screenshot.png" alt="flash builder additional argument" width="800" height="545" class="aligncenter size-full wp-image-733" /></a></p>
<p>Right-click on the src folder and create a new package called vo. In the vo package create a new ActionScript class called FileVO (notice that it has the same properties as the php value object on the server):</p>
<pre class="brush: plain; title: ; notranslate">
package vo
{
	import flash.utils.ByteArray;

	[RemoteClass(alias=&quot;FileVO&quot;)]
	[Bindable]
	public class FileVO
	{
		public var fileName:String;
		public var fileData:ByteArray;
	}
}
</pre>
<p>The main application file UploadAMF.mxml is where everything happens. A remote object is created, the user selects images to upload and the upload method is called on each file. The <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReferenceList.html">FileReferenceList</a> class  provides the means to select multiple files for uploading.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:WindowedApplication xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
					   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
					   xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot;&gt;
	&lt;fx:Script&gt;
		&lt;![CDATA[
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;

			import vo.FileVO;

			private var fileRefList:FileReferenceList;
			private var fileTypes:FileFilter = new FileFilter(&quot;Images (*.jpg, *.jpeg)&quot;, &quot;*.jpg; *.jpeg&quot;);
			private var allTypes:Array = new Array(fileTypes);

			private var totalFilesCount:int = 0;
			private var currentFileCount:int = 0;

			protected function selectButton_clickHandler(event:MouseEvent):void
			{
				fileRefList = new FileReferenceList();
				fileRefList.addEventListener(Event.SELECT,selectHandler);
				fileRefList.browse(allTypes);
			}

			protected function selectHandler(event:Event):void
			{
				totalFilesCount = fileRefList.fileList.length;
				currentFileCount = 0;
			}

			protected function uploadButton_clickHandler(event:MouseEvent):void
			{
				if (currentFileCount &lt; totalFilesCount) {
					uploadFile();
					selectButton.enabled = false;
					uploadButton.enabled = false;
				}
			}

			public function uploadFile():void
			{
				if (currentFileCount &lt; totalFilesCount) {
					trace(&quot;current file = &quot;+currentFileCount);
					var currentFileRef:FileReference = new FileReference;
					currentFileRef = fileRefList.fileList[currentFileCount];
					currentFileRef.addEventListener(Event.COMPLETE,function fileLoadComplete(event:Event):void {
						trace(&quot;file loaded into memory&quot;);
						var data:ByteArray = new ByteArray();
						currentFileRef.data.readBytes(data,0,currentFileRef.data.length);
						var fileVO:FileVO = new FileVO();
						fileVO.fileName = currentFileRef.name;
						fileVO.fileData = data;
						upload.token = ro.upload(fileVO);
					});
					currentFileRef.load();
				} else {
					trace(&quot;uploads complete&quot;);
					selectButton.enabled = true;
					uploadButton.enabled = true;
				}
				currentFileCount++;
			}

			protected function upload_faultHandler(event:FaultEvent):void
			{
				Alert.show(event.fault.faultString,&quot;Error&quot;);
			}

			protected function upload_resultHandler(event:ResultEvent):void
			{
				if (Boolean(event.message.body))
				{
					trace(&quot;file uploaded&quot;);
				}
				else
				{
					trace(&quot;unable to upload file&quot;);
				}
				uploadFile();
			}

		]]&gt;
	&lt;/fx:Script&gt;
	&lt;fx:Declarations&gt;
		&lt;s:RemoteObject id=&quot;ro&quot; destination=&quot;zendamf&quot; source=&quot;UploadService&quot;/&gt;
		&lt;s:CallResponder id=&quot;upload&quot; fault=&quot;upload_faultHandler(event)&quot;
						 result=&quot;upload_resultHandler(event)&quot;/&gt;
	&lt;/fx:Declarations&gt;
	&lt;s:Form x=&quot;10&quot; y=&quot;10&quot;&gt;
		&lt;s:FormItem label=&quot;Upload Files&quot;&gt;
			&lt;s:HGroup&gt;
				&lt;s:Button id=&quot;selectButton&quot; label=&quot;Select&quot; click=&quot;selectButton_clickHandler(event)&quot;/&gt;
				&lt;s:Button id=&quot;uploadButton&quot; label=&quot;Upload&quot; click=&quot;uploadButton_clickHandler(event)&quot;/&gt;
			&lt;/s:HGroup&gt;
		&lt;/s:FormItem&gt;
	&lt;/s:Form&gt;
&lt;/s:WindowedApplication&gt;
</pre>
<p>Download the <a href='http://www.chaosm.net/blog/wp-content/uploads/2011/08/Multi_UploadAMF.zip'>source files</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/08/14/upload-multiple-files-in-adobe-air-with-zend-amf-and-flex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upload Files in Adobe AIR with Zend AMF and Flex</title>
		<link>http://www.chaosm.net/blog/2011/08/07/upload-files-in-adobe-air-with-zend-amf-and-flex/</link>
		<comments>http://www.chaosm.net/blog/2011/08/07/upload-files-in-adobe-air-with-zend-amf-and-flex/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 23:26:50 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=725</guid>
		<description><![CDATA[This example shows how to upload files in an Adobe AIR application to a server using Zend AMF and Flex. It&#8217;s based off a blog post by Leonardo França. I found getting started with Zend AMF a bit confusing, this &#8230; <a href="http://www.chaosm.net/blog/2011/08/07/upload-files-in-adobe-air-with-zend-amf-and-flex/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This example shows how to upload files in an Adobe AIR application to a server using Zend AMF and Flex. It&#8217;s based off a blog post by <a href="http://www.leonardofranca.com/index.php/2010/10/18/file-uploads-with-adobe-flex-and-zend-amf/">Leonardo França</a>. I found getting started with Zend AMF a bit confusing, <a href="http://ria.dzone.com/articles/flex-php-zendamf">this tutorial</a> by Ryan Stewart was very helpful.</p>
<p>On the server we need to upload the <a href="http://www.zend.com/community/downloads">Zend Framework (minimal)</a> and create some files. This is how the file structure will end up looking:</p>
<p><img src="http://www.chaosm.net/blog/wp-content/uploads/2011/08/serverfilestructure.png" alt="server file structure" title="serverfilestructure" width="184" height="154" class="alignnone size-full wp-image-767" /></p>
<p>Create index.php (the gateway):</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
error_reporting(E_ALL|E_STRICT);
ini_set(&quot;display_errors&quot;, &quot;on&quot;);

require('Zend/Amf/Server.php');
require_once('vo/FileVO.php');
require_once('service/UploadService.php');

$server = new Zend_Amf_Server();
$server-&gt;setClass(&quot;UploadService&quot;);
$server-&gt;setClassMap(&quot;FileVO&quot;,&quot;FileVO&quot;);

echo($server-&gt;handle());
?&gt;
</pre>
<p>In the service directory create UploadService.php:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
require_once($_SERVER['DOCUMENT_ROOT'].'/chaosm/air/ex2_uploadamf/vo/FileVO.php');
class UploadService
{
	public function __construct() {}

	public function upload(FileVO $data)
	{
		try
		{
			$fileData = $data-&gt;fileData;
			file_put_contents($_SERVER['DOCUMENT_ROOT'].'/chaosm/air/ex2_uploadamf/uploads/'.$data-&gt;fileName,$fileData);
			return true;
		}
		catch (Exception $e)
		{
			throw new Exception($e-&gt;getMessage());
		}
	}
}
?&gt;
</pre>
<p>In the vo directory create FileVO.php (the value object for the file):</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
class FileVO
{
	public $fileName;
	public $fileData;

	function __construct() {}
}
?&gt;
</pre>
<p>In services-config.xml change the endpoint uri (line 17) to the location of the gateway on your server: </p>
<pre class="brush: plain; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;services-config&gt;
    &lt;services&gt;
        &lt;service id=&quot;amfphp-flashremoting-service&quot; class=&quot;flex.messaging.services.RemotingService&quot; messageTypes=&quot;flex.messaging.messages.RemotingMessage&quot;&gt;
            &lt;destination id=&quot;zendamf&quot;&gt;
                &lt;channels&gt;
                    &lt;channel ref=&quot;zend-amf-channel&quot;/&gt;
                &lt;/channels&gt;
                &lt;properties&gt;
                    &lt;source&gt;*&lt;/source&gt;
                &lt;/properties&gt;
            &lt;/destination&gt;
        &lt;/service&gt;
    &lt;/services&gt;
    &lt;channels&gt;
        &lt;channel-definition id=&quot;zend-amf-channel&quot; class=&quot;mx.messaging.channels.AMFChannel&quot;&gt;
            &lt;endpoint uri=&quot;http://www.chaosm.net/air/ex2_uploadamf/&quot; class=&quot;flex.messaging.endpoints.AMFEndpoint&quot;/&gt;
        &lt;/channel-definition&gt;
    &lt;/channels&gt;
&lt;/services-config&gt;
</pre>
<p>Finally make a directory called uploads. This is where files will be written to, so it needs to have the required permissions (such as 777).</p>
<p>In Flash Builder create a new Flex project called UploadAMF (or import my .fxp file). This is how the file structure will end up looking:</p>
<p><img src="http://www.chaosm.net/blog/wp-content/uploads/2011/08/flashfilestructure.png" alt="flash builder file structure" title="flashfilestructure" width="170" height="169" class="alignnone size-full wp-image-746" /></p>
<p>Right-click on the project and select Properties. Include the services-config.xml under additional compiler arguments like this: </p>
<p><a href="http://www.chaosm.net/blog/wp-content/uploads/2011/08/screenshot.png"><img src="http://www.chaosm.net/blog/wp-content/uploads/2011/08/screenshot.png" alt="flash builder additional argument" width="800" height="545" class="aligncenter size-full wp-image-733" /></a></p>
<p>Right-click on the src folder and create a new package called vo. In the vo package create a new ActionScript class called FileVO (notice that it has the same properties as the php value object on the server):</p>
<pre class="brush: plain; title: ; notranslate">
package vo
{
	import flash.utils.ByteArray;

	[RemoteClass(alias=&quot;FileVO&quot;)]
	[Bindable]
	public class FileVO
	{
		public var fileName:String;
		public var fileData:ByteArray;
	}
}
</pre>
<p>The main application file UploadAMF.mxml is where everything happens. A remote object is created, the user selects an image to upload and the upload method is called. When the upload is complete an Alert box is shown to the user. </p>
<pre class="brush: plain; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:WindowedApplication xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
					   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
					   xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot;&gt;
	&lt;fx:Script&gt;
		&lt;![CDATA[
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;

			import vo.FileVO;

			private var fileRef:FileReference;
			private var fileTypes:FileFilter = new FileFilter(&quot;Images (*.jpg, *.jpeg)&quot;, &quot;*.jpg; *.jpeg&quot;);
			private var allTypes:Array = new Array(fileTypes)

			protected function selectButton_clickHandler(event:MouseEvent):void
			{
				fileRef = new FileReference();
				fileRef.addEventListener(Event.SELECT,selectHandler);
				fileRef.browse(allTypes);
			}

			protected function selectHandler(event:Event):void
			{
				fileTextInput.text = fileRef.name;
				fileRef.load();
			}

			protected function uploadButton_clickHandler(event:MouseEvent):void
			{
				var data:ByteArray = new ByteArray();
				fileRef.data.readBytes(data,0,fileRef.data.length);
				var fileVO:FileVO = new FileVO();
				fileVO.fileName = fileRef.name;
				fileVO.fileData = data;
				upload.token = ro.upload(fileVO);
				selectButton.enabled = false;
				uploadButton.enabled = false;
			}

			protected function upload_faultHandler(event:FaultEvent):void
			{
				Alert.show(event.fault.faultString,&quot;Error&quot;);
				selectButton.enabled = true;
				uploadButton.enabled = true;
			}

			protected function upload_resultHandler(event:ResultEvent):void
			{
				if (Boolean(event.message.body))
				{
					Alert.show(&quot;File uploaded.&quot;,&quot;Success&quot;);
				}
				else
				{
					Alert.show(&quot;Unable to upload file.&quot;,&quot;Error&quot;);
				}
				selectButton.enabled = true;
				uploadButton.enabled = true;
			}

		]]&gt;
	&lt;/fx:Script&gt;
	&lt;fx:Declarations&gt;
		&lt;s:RemoteObject id=&quot;ro&quot; destination=&quot;zendamf&quot; source=&quot;UploadService&quot;/&gt;
		&lt;s:CallResponder id=&quot;upload&quot; fault=&quot;upload_faultHandler(event)&quot;
						 result=&quot;upload_resultHandler(event)&quot;/&gt;
	&lt;/fx:Declarations&gt;
	&lt;s:Form x=&quot;10&quot; y=&quot;10&quot;&gt;
		&lt;s:FormItem label=&quot;File&quot;&gt;
			&lt;s:HGroup&gt;
				&lt;s:TextInput id=&quot;fileTextInput&quot;/&gt;
				&lt;s:Button id=&quot;selectButton&quot; label=&quot;Select&quot; click=&quot;selectButton_clickHandler(event)&quot;/&gt;
				&lt;s:Button id=&quot;uploadButton&quot; label=&quot;Upload&quot; click=&quot;uploadButton_clickHandler(event)&quot;/&gt;
			&lt;/s:HGroup&gt;
		&lt;/s:FormItem&gt;
	&lt;/s:Form&gt;
&lt;/s:WindowedApplication&gt;
</pre>
<p>Download the <a href='http://www.chaosm.net/blog/wp-content/uploads/2011/08/UploadAMF.zip'>source files</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/08/07/upload-files-in-adobe-air-with-zend-amf-and-flex/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Flex Mobile: Upload Photo to Server with PHP</title>
		<link>http://www.chaosm.net/blog/2011/06/04/flex-mobile-upload-photo-to-server-with-php/</link>
		<comments>http://www.chaosm.net/blog/2011/06/04/flex-mobile-upload-photo-to-server-with-php/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 00:26:26 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://mattsmithblog.wordpress.com/?p=631</guid>
		<description><![CDATA[The code below uploads a photo from a Flex mobile application to a server with PHP. When I was first searching on how to do this I came across a good tutorial on Hybrid Hacking. So I&#8217;ve basically just modified &#8230; <a href="http://www.chaosm.net/blog/2011/06/04/flex-mobile-upload-photo-to-server-with-php/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The code below uploads a photo from a <a href="http://www.adobe.com/products/flex/mobile/">Flex mobile</a> application to a server with PHP. When I was first searching on how to do this I came across a good tutorial on <a href="http://hybridhacking.com/tutorials/uploading-files-with-flex-using-php">Hybrid Hacking</a>. So I&#8217;ve basically just modified their code to work on mobile with the <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/CameraUI.html">CameraUI</a> and <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/CameraRoll.html">CameraRoll</a> classes. Download the Flex project <a href="http://www.chaosm.net/flash/ex27_flexmobile_upload/MobileFileUploadr.fxp">here</a>.</p>
<p><img src="http://mattsmithblog.files.wordpress.com/2011/06/upload-photo1.png" alt="" title="upload photo from flex mobile to php" width="470" height="257" class="aligncenter size-full wp-image-645" /></p>
<p>The Flex mobile application has one view which looks like this:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:View xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
		xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
		title=&quot;Photo Upload&quot;&gt;

	&lt;fx:Script&gt;
		&lt;![CDATA[
			private var urlRequest:URLRequest = new URLRequest(&quot;http://www._____.com/upload.php&quot;);
			private var file:File;

			//take a new picture with the camera
			protected function uploadCamera_clickHandler(event:MouseEvent):void
			{
				if (CameraUI.isSupported)
				{
					trace(&quot;camera is supported&quot;);
					var myCam:CameraUI = new CameraUI();
					myCam.launch(MediaType.IMAGE);
					myCam.addEventListener(MediaEvent.COMPLETE,selectCompleteHandler);
				}
				else
				{
					trace(&quot;camera not supported&quot;);
					statusText.text = &quot;Camera not supported on this device.&quot;;
				}
			}

			//select a picture from the camera roll (gallery)
			protected function uploadGallery_clickHandler(event:MouseEvent):void
			{
				if (CameraRoll.supportsBrowseForImage)
				{
					trace(&quot;camera roll is supported&quot;);
					var roll:CameraRoll = new CameraRoll();
					roll.browseForImage();
					roll.addEventListener(MediaEvent.SELECT,selectCompleteHandler);
				}
				else
				{
					trace(&quot;camera roll not supported&quot;);
					statusText.text = &quot;Camera roll not supported on this device.&quot;;
				}
			}

			//when the selection is complete upload it
			protected function selectCompleteHandler(event:MediaEvent):void
			{
				trace(&quot;event.data.file.url; = &quot;+event.data.file.url);
				takePhotoButton.enabled = galleryPhotoButton.enabled = false;
				file = event.data.file;
				file.addEventListener(Event.COMPLETE,uploadCompleteHandler);
				file.addEventListener(Event.OPEN,openUploadHandler);
				file.upload(urlRequest);

			}

			protected function uploadCompleteHandler(event:Event):void
			{
				trace(&quot;upload complete&quot;);
				takePhotoButton.enabled = galleryPhotoButton.enabled = true;
				statusText.text = &quot;Photo Uploaded&quot;;
			}

			protected function openUploadHandler(event:Event):void
			{
				trace(&quot;uploading&quot;);
				statusText.text = &quot;Uploading...&quot;;
			}
		]]&gt;
	&lt;/fx:Script&gt;

	&lt;s:VGroup x=&quot;21&quot; y=&quot;23&quot; width=&quot;200&quot; height=&quot;200&quot;&gt;
		&lt;s:Label id=&quot;statusText&quot; fontSize=&quot;24&quot; text=&quot;Choose a photo...&quot;/&gt;
		&lt;s:Button id=&quot;takePhotoButton&quot; label=&quot;Take Photo&quot; click=&quot;uploadCamera_clickHandler(event)&quot;/&gt;
		&lt;s:Button id=&quot;galleryPhotoButton&quot; label=&quot;Upload from Gallery&quot;
				  click=&quot;uploadGallery_clickHandler(event)&quot;/&gt;
	&lt;/s:VGroup&gt;
&lt;/s:View&gt;
</pre>
<p>The PHP code (from <a href="http://hybridhacking.com/tutorials/uploading-files-with-flex-using-php">Hybrid Hacking</a>) looks like this:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?php
$tempFile = $_FILES['Filedata']['tmp_name'];
$fileName = $_FILES['Filedata']['name'];
$fileSize = $_FILES['Filedata']['size'];
move_uploaded_file($tempFile, &quot;./&quot; . $fileName);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/06/04/flex-mobile-upload-photo-to-server-with-php/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Flex Monty Hall Problem</title>
		<link>http://www.chaosm.net/blog/2011/05/28/flex-monty-hall-problem/</link>
		<comments>http://www.chaosm.net/blog/2011/05/28/flex-monty-hall-problem/#comments</comments>
		<pubDate>Sat, 28 May 2011 08:40:41 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=841</guid>
		<description><![CDATA[I made this quick example in Flex and AS3 to test different outcomes for the Monty Hall problem. View a demo here.]]></description>
			<content:encoded><![CDATA[<p>I made this quick example in Flex and AS3 to test different outcomes for the <a href="http://en.wikipedia.org/wiki/Monty_Hall_problem">Monty Hall problem</a>. View a demo <a href="http://www.chaosm.net/flash/ex25_montyhall/">here</a>.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;s:Application xmlns:fx=&quot;http://ns.adobe.com/mxml/2009&quot;
			   xmlns:s=&quot;library://ns.adobe.com/flex/spark&quot;
			   xmlns:mx=&quot;library://ns.adobe.com/flex/mx&quot;
			   minWidth=&quot;500&quot; minHeight=&quot;610&quot;
			   creationComplete=&quot;application1_creationCompleteHandler(event)&quot;
			   viewSourceURL=&quot;srcview/index.html&quot;&gt;
	&lt;fx:Script&gt;
		&lt;![CDATA[
			import flash.net.navigateToURL;

			import mx.charts.PieChart;
			import mx.collections.ArrayCollection;
			import mx.events.FlexEvent;

			[Bindable]
			public var dp:ArrayCollection;
			public var outputNum:int;

			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				outputText.appendText(&quot;Click a button to process random tests.\n&quot;);
			}

			public function changeAlways():Boolean
			{
				var array:Array = new Array();
				var winPosition:int = Math.random() * 3;
				array[winPosition] = &quot;Car&quot;;
				var guess:int = Math.random() * 3;
				if (array[guess] == &quot;Car&quot;)
				{
					if (outputNum &lt; 50) outputText.appendText(&quot;You won a car on your first guess!\n&quot;);
					return true;
				} else
				{
					array[guess] = &quot;Guess&quot;;
					//the goat
					var goat:int = -1;
					while (goat != -1)
					{
						var tmp:int = Math.random()*3;
						if (array[tmp] != &quot;Car&quot; &amp;&amp; array[tmp] != &quot;Guess&quot;) goat = tmp;
					}
					array[goat] = &quot;Goat&quot;;
					//change your guess
					for (var i:int; i&lt;array.length; i++)
					{
						if(array[i] != &quot;Guess&quot; &amp;&amp; array[i] != &quot;Goat&quot;)
						{
							if(array[i] == &quot;Car&quot;)
							{
								if (outputNum &lt; 50) outputText.appendText(&quot;You won a car on your second guess!\n&quot;);
								return true;
							} else {
								if (outputNum &lt; 50) outputText.appendText(&quot;You lost!\n&quot;);
								return false;
							}
						}
					}
					return false;
				}
			}

			public function changeNever():Boolean
			{
				var array:Array = new Array();
				var winPosition:int = Math.random() * 3;
				array[winPosition] = &quot;Car&quot;;
				var guess:int = Math.random() * 3;
				if (array[guess] == &quot;Car&quot;)
				{
					if (outputNum &lt; 50) outputText.appendText(&quot;You won a car!\n&quot;);
					return true;
				} else {
					if (outputNum &lt; 50) outputText.appendText(&quot;You lost!\n&quot;);
					return false;
				}
			}

			protected function alwaysChangeBtn_clickHandler(event:MouseEvent):void
			{
				var numTrials:int = int(numTrialsInp.text);
				if (numTrials &gt;= 0) {
					outputNum = 0;
					outputText.text = &quot;Sample Results (&quot;+numTrials+&quot;):\n&quot;;
					var won:int = 0;
					var lost:int = 0;
					for(var i:int; i&lt;numTrials; i++)
					{
						if(changeAlways())
						{
							won++;
						} else {
							lost++;
						}
						outputNum++;
					}
					dp = new ArrayCollection([{Label:&quot;Won&quot;,Data:won},{Label:&quot;Lost&quot;,Data:lost}]);
					if (outputNum &gt;= 100) {
						outputText.appendText(&quot;... done\n&quot;);
					} else {
						outputText.appendText(&quot;done\n&quot;);
					}
				}
			}

			protected function neverChangeBtn_clickHandler(event:MouseEvent):void
			{
				var numTrials:int = int(numTrialsInp.text);
				if (numTrials &gt;= 0) {
					outputNum = 0;
					outputText.text = &quot;Sample Results (&quot;+numTrials+&quot;):\n&quot;;
					var won:int = 0;
					var lost:int = 0;
					for(var i:int; i&lt;numTrials; i++)
					{
						if(changeNever())
						{
							won++;
						} else {
							lost++;
						}
						outputNum++;
					}
					dp = new ArrayCollection([{Label:&quot;Won&quot;,Data:won},{Label:&quot;Lost&quot;,Data:lost}]);
					if (outputNum &gt;= 100) {
						outputText.appendText(&quot;... done\n&quot;);
					} else {
						outputText.appendText(&quot;done\n&quot;);
					}
				}

			}

			protected function labelResults(data:Object, field:String, index:Number, percentValue:Number):String
			{
				return data.Label + &quot; &quot; + Math.round(data.Data/int(numTrialsInp.text)*100) + &quot;%&quot;;
			}

			protected function whatIs_clickHandler(event:MouseEvent):void
			{
				navigateToURL(new URLRequest(&quot;http://en.wikipedia.org/wiki/Monty_Hall_problem&quot;));
			}

		]]&gt;
	&lt;/fx:Script&gt;
	&lt;fx:Declarations&gt;
		&lt;!-- Place non-visual elements (e.g., services, value objects) here --&gt;
		&lt;!--&lt;fx:String id=&quot;butterfly2&quot;&gt;Purple&lt;/fx:String&gt;--&gt;
	&lt;/fx:Declarations&gt;
	&lt;s:VGroup x=&quot;10&quot; y=&quot;10&quot;&gt;
		&lt;s:Label fontSize=&quot;20&quot; fontWeight=&quot;bold&quot; text=&quot;Monty Hall Probability&quot;/&gt;
		&lt;s:HGroup&gt;
			&lt;s:Button id=&quot;alwaysChangeBtn&quot; label=&quot;Always Change&quot; click=&quot;alwaysChangeBtn_clickHandler(event)&quot;/&gt;
			&lt;s:Button id=&quot;neverChangeBtn&quot; label=&quot;Never Change&quot; click=&quot;neverChangeBtn_clickHandler(event)&quot;/&gt;
			&lt;s:TextInput id=&quot;numTrialsInp&quot; text=&quot;100&quot; textAlign=&quot;right&quot;/&gt;
		&lt;/s:HGroup&gt;
		&lt;s:TextArea id=&quot;outputText&quot; width=&quot;372&quot; height=&quot;233&quot;/&gt;
		&lt;mx:LinkButton id=&quot;whatIs&quot; label=&quot;What is the Monty Hall problem?&quot;
					   click=&quot;whatIs_clickHandler(event)&quot;/&gt;
		&lt;mx:PieChart id=&quot;piechart1&quot; dataProvider=&quot;{dp}&quot; fontSize=&quot;14&quot;&gt;
			&lt;mx:series&gt;
				&lt;mx:PieSeries labelField=&quot;Label&quot; labelPosition=&quot;inside&quot; labelFunction=&quot;labelResults&quot;  nameField=&quot;Label&quot; displayName=&quot;Series 1&quot; field=&quot;Data&quot;&gt;
					&lt;!-- Clear the drop shadow filters from the chart. --&gt;
					&lt;mx:filters&gt;
						&lt;fx:Array/&gt;
					&lt;/mx:filters&gt;
				&lt;/mx:PieSeries&gt;
			&lt;/mx:series&gt;
		&lt;/mx:PieChart&gt;
	&lt;/s:VGroup&gt;
&lt;/s:Application&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/05/28/flex-monty-hall-problem/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is the best way to communicate with MySQL from a Flash application?</title>
		<link>http://www.chaosm.net/blog/2011/02/22/what-is-the-best-way-to-communicate-with-mysql-from-a-flash-application/</link>
		<comments>http://www.chaosm.net/blog/2011/02/22/what-is-the-best-way-to-communicate-with-mysql-from-a-flash-application/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 18:09:55 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=876</guid>
		<description><![CDATA[I asked this question on Quora and got a really good answer (read here). What I actually had to learn was how to get Flash communicating with PHP using serialization (compared to get/post requests and xml). There are two options &#8230; <a href="http://www.chaosm.net/blog/2011/02/22/what-is-the-best-way-to-communicate-with-mysql-from-a-flash-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I asked this question on Quora and got a really good answer (read <a href="http://www.quora.com/What-is-the-best-way-to-communicate-with-MySQL-from-a-Flash-application">here</a>). What I actually had to learn was how to get Flash communicating with PHP using serialization (compared to get/post requests and xml). There are two options for doing this, <a href="http://amfphp.sourceforge.net/">AMFPHP</a> and <a href="http://framework.zend.com/download/amf">ZendAMF</a>. The video tutorials below are a great walk through:</p>
<p>- <a href="http://www.gotoandlearn.com/play.php?id=78">Introduction to AMFPHP: Part 1</a><br />
- <a href="http://www.gotoandlearn.com/play.php?id=79">Introduction to AMFPHP: Part 2</a><br />
- <a href="http://gotoandlearn.com/play.php?id=90">Introduction to ZendAMF</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/02/22/what-is-the-best-way-to-communicate-with-mysql-from-a-flash-application/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>YUI3 StumbleUpon List</title>
		<link>http://www.chaosm.net/blog/2011/02/17/yui3-stumbleupon-list/</link>
		<comments>http://www.chaosm.net/blog/2011/02/17/yui3-stumbleupon-list/#comments</comments>
		<pubDate>Thu, 17 Feb 2011 18:12:45 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=878</guid>
		<description><![CDATA[Using YUI3 YQL Query Utility to display a StumbleUpon user&#8217;s recent favorites. View a demo here.]]></description>
			<content:encoded><![CDATA[<p>Using YUI3 <a href="http://developer.yahoo.com/yui/3/yql/">YQL Query Utility</a> to display a StumbleUpon user&#8217;s recent favorites. View a demo <a href="http://www.chaosm.net/yui3/ex46_stumbleupon.php">here</a>.</p>
<pre class="brush: plain; title: ; notranslate">
&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot;&gt;
&lt;title&gt;StumbleUpon List YUI3 YQL&lt;/title&gt;
&lt;script src=&quot;http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;
&lt;/head&gt;
&lt;h1&gt;StumbleList&lt;/h1&gt;
&lt;ul id=&quot;stumbleList&quot;&gt;
&lt;/ul&gt;
&lt;body&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
// Create a new YUI instance and populate it with the required modules.
YUI().use('yql','node', function (Y) {
	Y.YQL('select * from feed where url=\'http://rss.stumbleupon.com/user/mattsm604/favorites\'', function(r) {
		var stumbles = r.query.results.item;
		var list = Y.one('#stumbleList');
		for (var i=0; i&lt;stumbles.length; i++) {
			list.append('&lt;li&gt;&lt;a href=&quot;'+stumbles[i].link+'&quot;&gt;'+stumbles[i].title+'&lt;/a&gt;&lt;/li&gt;');
		}
	});
});
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/02/17/yui3-stumbleupon-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resize SWFObject with YUI3</title>
		<link>http://www.chaosm.net/blog/2011/01/07/resize-swfobject-with-yui3/</link>
		<comments>http://www.chaosm.net/blog/2011/01/07/resize-swfobject-with-yui3/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 04:10:23 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.chaosm.net/blog/?p=902</guid>
		<description><![CDATA[Using YUI3 Animation to change the height of a swfobject. View a demo here. Download the FLA file here. Links: - AS3 External Interface [Update - I've redone this example with jQuery here.]]]></description>
			<content:encoded><![CDATA[<p>Using <a href="http://developer.yahoo.com/yui/3/anim/">YUI3 Animation</a> to change the height of a <a href="http://code.google.com/p/swfobject/">swfobject</a>. View a demo <a href="http://www.chaosm.net/flash/ex12_toggle_size/index.php">here</a>. Download the FLA file <a href="http://www.chaosm.net/flash/ex12_toggle_size/toggle_size.fla">here</a>.</p>
<pre class="brush: plain; title: ; notranslate">
//ActionScript 3
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

toggle_txt.x = toggle_txt.y = 10;
toggle_txt.text = &quot;Toggle Height (click) StageHeight = &quot;+String(stage.stageHeight);
toggle_txt.buttonMode = true;

toggle_txt.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

function fl_MouseClickHandler(event:MouseEvent):void
{
	ExternalInterface.call('toggleSize');
}

stage.addEventListener(Event.RESIZE, resizeHandler);

function resizeHandler(evt:Event):void
{
	toggle_txt.text = &quot;Toggle Height (click) StageHeight = &quot;+String(stage.stageHeight);
}
</pre>
<pre class="brush: plain; title: ; notranslate">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;
&lt;title&gt;Expand Stage&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; charset=&quot;utf-8&quot; src=&quot;http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	var flashvars = {};
	var params = {allowscriptaccess:&quot;always&quot;};
	var attributes = {};
	swfobject.embedSWF(&quot;toggle_size.swf&quot;, &quot;banner&quot;, &quot;960&quot;, &quot;60&quot;, &quot;10.0.0&quot;, false, flashvars, params, attributes);
&lt;/script&gt;
&lt;style type=&quot;text/css&quot;&gt;
@import url(&quot;http://yui.yahooapis.com/combo?3.2.0/build/cssfonts/fonts-min.css&amp;3.2.0/build/cssreset/reset-min.css&quot;);
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;div id=&quot;banner&quot;&gt;&lt;/div&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
function toggleSize() {
	YUI().use('node','anim', function(Y) {
		var b = Y.one(&quot;#banner&quot;);
		//Y.log(b);
		if (b.getStyle('height') === '120px'){
			var bAnim = new Y.Anim({
				node: '#banner',
				to: {
					height:60
				}
			});
			bAnim.run();
		} else if (b.getStyle('height') === '60px') {
			var bAnim = new Y.Anim({
				node: '#banner',
				to: {
					height:120
				}
			});
			bAnim.run();
		}
	});
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>Links:<br />
- <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/external/ExternalInterface.html">AS3 External Interface</a></p>
<p>[Update - I've redone this example with jQuery <a href="http://www.chaosm.net/flash/ex26_change_size_jquery/index.php">here</a>.]</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chaosm.net/blog/2011/01/07/resize-swfobject-with-yui3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

