<?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>Floorplanner Tech Blog &#187; Flash</title>
	<atom:link href="http://techblog.floorplanner.com/tag/flash/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Thu, 19 Nov 2009 04:00:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Load, modify and save local images with Flash Player 10</title>
		<link>http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-player-10/</link>
		<comments>http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-player-10/#comments</comments>
		<pubDate>Mon, 04 May 2009 11:53:10 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flash player 10]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[load]]></category>
		<category><![CDATA[local file system]]></category>
		<category><![CDATA[pixel bender]]></category>
		<category><![CDATA[save]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=609</guid>
		<description><![CDATA[ // 



One of the cool new things about Flash Player 10 is that you now have access to the local file system. This means that you can load, modify and save files directly on the client side without any server interaction. Mike Chambers wrote a post about reading and writing text files and I [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F05%2F04%2Fload-modify-and-save-local-images-with-flash-player-10%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F05%2F04%2Fload-modify-and-save-local-images-with-flash-player-10%2F" height="61" width="51" /></a></div><p><script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.1/swfobject.js" type="text/javascript"></script> <script type="text/javascript">// <![CDATA[
 window.onload = function() { swfobject.embedSWF("http://techblog.floorplanner.com/wp-content/uploads/2009/05/main.swf", 'thumbr', '280', '265', '10.0.0'); }
// ]]&gt;</script></p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top">One of the cool new things about Flash Player 10 is that you now have access to the local file system. This means that you can load, modify and save files directly on the client side without any server interaction. <a href="http://twitter.com/mesh">Mike Chambers</a> wrote a post about <a href="http://www.mikechambers.com/blog/2008/08/20/reading-and-writing-local-files-in-flash-player-10/">reading and writing text files</a> and I was wondering if it was possible to do this with image files too.</td>
<td>
<div id="thumbr">thumbr here</div>
</td>
<td valign="top"></td>
</tr>
</tbody>
</table>
<h3>Publish Flash Player 10 content</h3>
<p>To test this, I first needed a way to make my Flex Builder compile Flash Player 10 content. I found a rather old post by <a href="http://www.flexer.info/author/webdevandrei/">Andrei Ionescu</a> about<a href="http://www.flexer.info/2008/05/21/how-to-build-flash-player-10-applications-using-flex-sdk/"> building Flash Player 10 applications</a> that told me exactly what I was looking for. I downloaded the latest Flex SDK (3.3) from <a href="http://www.adobe.com/products/flex/flexdownloads/">Adobe&#8217;s Flex Download page</a>, followed the tutorial and I was ready to go.</p>
<h3>Load image from local file system</h3>
<p>Reading a local file was no biggie, just copied and pasted the code from Mike&#8217;s sample. What I needed now was a way to convert the loaded data into an image. As usual <a href="http://twitter.com/timknip">Tim</a> helped me out by sending me a snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:ByteArray = fileRef<span style="color: #66cc66;">&#91;</span><span style="color: #ff0000;">'data'</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
addChild<span style="color: #66cc66;">&#40;</span>loader<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<h3>Modify image</h3>
<p>Now that I could load the image, I wanted to modify it before having it rendered. I extended the snippet to use BitmapData and a Matrix to resize the image to a thumb image (240&#215;180px).</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onDataLoadComplete<span style="color: #66cc66;">&#41;</span>;
loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span>loadFileRef.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDataLoadComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData = Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
  <span style="color: #000000; font-weight: bold;">var</span> matrix:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  matrix.<span style="color: #006600;">scale</span><span style="color: #66cc66;">&#40;</span>THUMB_WIDTH<span style="color: #66cc66;">/</span>bitmapData.<span style="color: #0066CC;">width</span>, THUMB_HEIGHT<span style="color: #66cc66;">/</span>bitmapData.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
  imageView.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
  imageView.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">beginBitmapFill</span><span style="color: #66cc66;">&#40;</span>bitmapData, matrix, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>;
  imageView.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, THUMB_WIDTH, THUMB_HEIGHT<span style="color: #66cc66;">&#41;</span>;
  imageView.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<h3>Save image to local file system</h3>
<p>Now that it&#8217;s possible to load and modify an image, saving it is the last step. To save an image, it has to be encoded to a ByteArray. I used the open source <a href="http://code.google.com/p/as3corelib/">as3corelib</a> to help me out. Saving the ByteArray to a file is rather straight forward.</p>
<p><strong>Update 1:</strong> You don&#8217;t need to use the as3corelib anymore, Flex 3.3 has it own <a href="http://livedocs.adobe.com/flex/3/langref/mx/graphics/codec/JPEGEncoder.html">JPEGEncoder</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #000000; font-weight: bold;">var</span> encoder:JPEGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPEGEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> rawBytes:ByteArray = encoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bitmapData<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> saveFileRef:FileReference = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
saveFileRef.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>rawBytes<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><strong>Update 2:</strong> <a href="http://www.bytearray.org/">Thibault Imbert</a> figured out a way to <a href="http://www.bytearray.org/?p=775">speed up JPEG encoding</a> using the new FP10 Vector class. Good stuff!</p>
<p><strong>Update 3</strong>: You can now also use Alchemy for the encoding. It&#8217;s much, much faster then the other options! See this post from <a href="http://www.websector.de/blog/">Jens Krause</a>: <a href="http://www.websector.de/blog/2009/06/21/speed-up-jpeg-encoding-using-alchemy/">Speed up JPEG encoding using Alchemy</a></p>
<p>This sample shows that it&#8217;s not only possible to load, modify and save images directly from the local file system, but that it&#8217;s actually very simple to do so. Add some <a href="http://labs.adobe.com/technologies/pixelbender/">PixelBender</a> image processing power to the game and you almost have a Photoshop killer running completly client side!</p>
<h3>Code sample</h3>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #66cc66;">&lt;</span>?<span style="color: #0066CC;">xml</span> <span style="color: #0066CC;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> encoding=<span style="color: #ff0000;">&quot;utf-8&quot;</span>?<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;</span>mx:Application xmlns:mx=<span style="color: #ff0000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #ff0000;">&quot;absolute&quot;</span> backgroundGradientColors=<span style="color: #ff0000;">&quot;[0xFFFFFF,0xFFFFFF]&quot;</span> <span style="color: #0066CC;">backgroundColor</span>=<span style="color: #ff0000;">&quot;0xFFFFFF&quot;</span><span style="color: #66cc66;">&gt;</span>
&nbsp;
	<span style="color: #66cc66;">&lt;</span>mx:Script<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;!</span><span style="color: #66cc66;">&#91;</span>CDATA<span style="color: #66cc66;">&#91;</span>
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">codec</span>.<span style="color: #006600;">JPEGEncoder</span>;
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">binding</span>.<span style="color: #006600;">utils</span>.<span style="color: #006600;">BindingUtils</span>;
			<span style="color: #0066CC;">import</span> mx.<span style="color: #006600;">core</span>.<span style="color: #006600;">UIComponent</span>;
&nbsp;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">FileReference</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">net</span>.<span style="color: #006600;">FileFilter</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">IOErrorEvent</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">events</span>.<span style="color: #006600;">Event</span>;
			<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">ByteArray</span>;
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> loadFileRef:FileReference;
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const FILE_TYPES:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span><span style="color: #000000; font-weight: bold;">new</span> FileFilter<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Image Files&quot;</span>, <span style="color: #ff0000;">&quot;*.jpg;*.jpeg;*.gif;*.png;*.JPG;*.JPEG;*.GIF;*.PNG&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#93;</span>;
			<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const THUMB_WIDTH:uint = <span style="color: #cc66cc;">240</span>;
			<span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const THUMB_HEIGHT:uint = <span style="color: #cc66cc;">180</span>;
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> loadFile<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				loadFileRef = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				loadFileRef.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">SELECT</span>, onFileSelect<span style="color: #66cc66;">&#41;</span>;
				loadFileRef.<span style="color: #006600;">browse</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> saveFile<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>		
				<span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>THUMB_WIDTH, THUMB_HEIGHT<span style="color: #66cc66;">&#41;</span>;
				bitmapData.<span style="color: #006600;">draw</span><span style="color: #66cc66;">&#40;</span>imageView<span style="color: #66cc66;">&#41;</span>;
&nbsp;
				<span style="color: #000000; font-weight: bold;">var</span> encoder:JPEGEncoder = <span style="color: #000000; font-weight: bold;">new</span> JPEGEncoder<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				<span style="color: #000000; font-weight: bold;">var</span> rawBytes:ByteArray = encoder.<span style="color: #006600;">encode</span><span style="color: #66cc66;">&#40;</span>bitmapData<span style="color: #66cc66;">&#41;</span>;
&nbsp;
 				<span style="color: #000000; font-weight: bold;">var</span> saveFileRef:FileReference = <span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				saveFileRef.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>rawBytes<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onFileSelect<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				loadFileRef.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onFileLoadComplete<span style="color: #66cc66;">&#41;</span>;
				loadFileRef.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onFileLoadComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
			   	<span style="color: #000000; font-weight: bold;">var</span> loader:Loader = <span style="color: #000000; font-weight: bold;">new</span> Loader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			   	loader.<span style="color: #006600;">contentLoaderInfo</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, onDataLoadComplete<span style="color: #66cc66;">&#41;</span>;
			   	loader.<span style="color: #006600;">loadBytes</span><span style="color: #66cc66;">&#40;</span>loadFileRef.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				loadFileRef = <span style="color: #000000; font-weight: bold;">null</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
			<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> onDataLoadComplete<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> bitmapData:BitmapData = Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">content</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">bitmapData</span>;
&nbsp;
                <span style="color: #000000; font-weight: bold;">var</span> matrix:Matrix = <span style="color: #000000; font-weight: bold;">new</span> Matrix<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
                matrix.<span style="color: #006600;">scale</span><span style="color: #66cc66;">&#40;</span>THUMB_WIDTH<span style="color: #66cc66;">/</span>bitmapData.<span style="color: #0066CC;">width</span>, THUMB_HEIGHT<span style="color: #66cc66;">/</span>bitmapData.<span style="color: #0066CC;">height</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
				imageView.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">clear</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
				imageView.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">beginBitmapFill</span><span style="color: #66cc66;">&#40;</span>bitmapData, matrix, <span style="color: #000000; font-weight: bold;">false</span><span style="color: #66cc66;">&#41;</span>; 
				imageView.<span style="color: #006600;">graphics</span>.<span style="color: #006600;">drawRect</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span>, THUMB_WIDTH, THUMB_HEIGHT<span style="color: #66cc66;">&#41;</span>;
				imageView.<span style="color: #006600;">graphics</span>.<span style="color: #0066CC;">endFill</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
				saveButton.<span style="color: #0066CC;">enabled</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			<span style="color: #66cc66;">&#125;</span>
&nbsp;
		<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Script<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;</span>mx:Panel title=<span style="color: #ff0000;">&quot;Create thumb image&quot;</span> paddingBottom=<span style="color: #ff0000;">&quot;5&quot;</span> paddingLeft=<span style="color: #ff0000;">&quot;5&quot;</span> paddingRight=<span style="color: #ff0000;">&quot;5&quot;</span> paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span><span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;</span>mx:VBox<span style="color: #66cc66;">&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:Canvas id=<span style="color: #ff0000;">&quot;imageView&quot;</span> <span style="color: #0066CC;">width</span>=<span style="color: #ff0000;">&quot;240&quot;</span> <span style="color: #0066CC;">height</span>=<span style="color: #ff0000;">&quot;180&quot;</span> borderThickness=<span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #0066CC;">borderColor</span>=<span style="color: #ff0000;">&quot;#CCCCCC&quot;</span> borderStyle=<span style="color: #ff0000;">&quot;solid&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;</span>mx:HBox paddingTop=<span style="color: #ff0000;">&quot;5&quot;</span> borderThickness=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #66cc66;">&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Load image&quot;</span> click=<span style="color: #ff0000;">&quot;loadFile()&quot;</span><span style="color: #66cc66;">/&gt;</span>
				<span style="color: #66cc66;">&lt;</span>mx:<span style="color: #0066CC;">Button</span> label=<span style="color: #ff0000;">&quot;Save image&quot;</span> click=<span style="color: #ff0000;">&quot;saveFile()&quot;</span> id=<span style="color: #ff0000;">&quot;saveButton&quot;</span> <span style="color: #0066CC;">enabled</span>=<span style="color: #ff0000;">&quot;false&quot;</span><span style="color: #66cc66;">/&gt;</span>
			<span style="color: #66cc66;">&lt;/</span>mx:HBox<span style="color: #66cc66;">&gt;</span>
		<span style="color: #66cc66;">&lt;/</span>mx:VBox<span style="color: #66cc66;">&gt;</span>
	<span style="color: #66cc66;">&lt;/</span>mx:Panel<span style="color: #66cc66;">&gt;</span>
<span style="color: #66cc66;">&lt;/</span>mx:Application<span style="color: #66cc66;">&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/05/04/load-modify-and-save-local-images-with-flash-player-10/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Unproject with useProjectionMatrix = true</title>
		<link>http://techblog.floorplanner.com/2009/04/29/unproject-with-useprojectionmatrix-true/</link>
		<comments>http://techblog.floorplanner.com/2009/04/29/unproject-with-useprojectionmatrix-true/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 00:45:40 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[Collaboration]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Floorplanner]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Papervision3D]]></category>
		<category><![CDATA[camera]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[unproject]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=580</guid>
		<description><![CDATA[I just updated Papervision3D to allow the CameraObject3D#unproject method to work when CameraObject3D#useProjectionMatrix = true.
Papervision3D has two methods of &#8216;projecting&#8217; vectors onto the screen:

useProjectionMatrix = false, this is the default &#8216;fast&#8217; method
useProjectionMatrix = true, this is the method where projection is done by a matrix

Note that Papervision3D switches to method #2 in &#8216;ortho mode&#8217;.
So what [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F04%2F29%2Funproject-with-useprojectionmatrix-true%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F04%2F29%2Funproject-with-useprojectionmatrix-true%2F" height="61" width="51" /></a></div><p>I just updated <a href="http://blog.papervision3d.org">Papervision3D</a> to allow the CameraObject3D#unproject method to work when CameraObject3D#useProjectionMatrix = true.</p>
<p>Papervision3D has two methods of &#8216;projecting&#8217; vectors onto the screen:</p>
<ol>
<li>useProjectionMatrix = false, this is the default &#8216;fast&#8217; method</li>
<li>useProjectionMatrix = true, this is the method where projection is done by a matrix</li>
</ol>
<p>Note that Papervision3D switches to method #2 in &#8216;ortho mode&#8217;.</p>
<p>So what is the difference exactly between these two kinds of projection? First we need to define what projection is. Projection is what adds &#8216;perspective&#8217; to a scene and makes sure your scene fits to the viewport. Its the last step in the so-called &#8216;render pipeline&#8217;. </p>
<p>We can derive the &#8216;fore shortening&#8217; effect of perspective in several ways. Method #1 is simple, effective and fast. It uses the camera&#8217;s focus and zoom values. Method #2 uses a more classic way of projection : it uses a dedicated matrix. Tech buffs: very much like OpenGL&#8217;s <a href="http://www.opengl.org/sdk/docs/man/xhtml/gluPerspective.xml">gluPerspective</a>.</p>
<p><a href="http://blog.zupko.info/">Andy Zupko</a> has a great <a href="http://blog.zupko.info/?p=143">post</a> on unproject using method #1.</p>
<p>We will discuss unproject using method #2, which works slightly different.</p>
<p>The difference is that when #useProjectionMatrix is set to true, then CameraObject3D#unproject  returns a point in world-space, rather then a ray. Let me explain with some code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="actionscript3" style="font-family: Monaco,monospace;"><span style="color: #009900;">// we want to use a projection matrix</span>
camera.useProjectionMatrix = <span style="color: #0033ff; font-weight: bold;">true</span>;
&nbsp;
<span style="color: #009900;">// '0' indicates we want a point on the near plane</span>
<span style="color: #6699cc; font-weight: bold;">var</span> pointOnNearPlane <span style="color: #000000; font-weight: bold;">:</span> Number3D = camera.unproject<span style="color: #000000;">&#40;</span> screenX, screenY, <span style="color: #000000; font-weight:bold;">0</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// '1' indicates we want a point on the far plane</span>
<span style="color: #6699cc; font-weight: bold;">var</span> pointOnFarPlane <span style="color: #000000; font-weight: bold;">:</span> Number3D = camera.unproject<span style="color: #000000;">&#40;</span> screenX, screenY, <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// Construct the ray's direction</span>
<span style="color: #6699cc; font-weight: bold;">var</span> dir <span style="color: #000000; font-weight: bold;">:</span> Number3D = Number3D.sub<span style="color: #000000;">&#40;</span> pointOnFarPlane, pointOnNearPlane <span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// Normalize</span>
dir.<span style="color: #004993;">normalize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #009900;">// So, now you have a ray with its origin at 'pointOnNearPlane',</span>
<span style="color: #009900;">// and direction 'dir'</span></pre></td></tr></table></div>

<p>Optimization: could save some cycles by doing (*not* in ortho mode!, see below):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="actionscript3" style="font-family: Monaco,monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> camPosition <span style="color: #000000; font-weight: bold;">:</span> Number3D = <span style="color: #0033ff; font-weight: bold;">new</span> Number3D<span style="color: #000000;">&#40;</span> camera.<span style="color: #004993;">x</span>, camera.<span style="color: #004993;">y</span>, camera.z <span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">// Construct the ray's direction</span>
<span style="color: #6699cc; font-weight: bold;">var</span> dir <span style="color: #000000; font-weight: bold;">:</span> Number3D = Number3D.sub<span style="color: #000000;">&#40;</span> pointOnFarPlane, camPosition <span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">// Normalize</span>
dir.<span style="color: #004993;">normalize</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #009900;">// So, now you have a ray with its origin at the camera's position</span>
<span style="color: #009900;">// and direction 'dir'</span></pre></td></tr></table></div>

<p>Why can&#8217;t we use above optimization in ortho mode?<br />
In perspective mode all &#8216;rays&#8217; originate from the camera&#8217;s position: the &#8216;view cone&#8217; has shape of a pyramid. Hence we can assume &#8216;pointOnNearPlane&#8217; to coincide with the camera&#8217;s position.<br />
In ortho mode however the &#8216;view cone&#8217; has the shape of a cube, all rays are parallel. Hence we need to unproject *two* points to construct our ray.</p>
<p>Now simply follow <a href="http://blog.zupko.info/?p=143">Andy Zupko &#8217;s post</a> to drag objects around.<br />
Or perform &#8216;picking&#8217;, or&#8230;</p>
<p>Update:<br />
Created a little demo to visualize what I&#8217;m ranting about, check it out <a href='http://techblog.floorplanner.com/wp-content/uploads/2009/04/unprojecttest1.swf'>here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/04/29/unproject-with-useprojectionmatrix-true/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating a REST API for a Flash application</title>
		<link>http://techblog.floorplanner.com/2009/02/25/creating-a-rest-api-for-a-flash-application/</link>
		<comments>http://techblog.floorplanner.com/2009/02/25/creating-a-rest-api-for-a-flash-application/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 16:49:47 +0000</pubDate>
		<dc:creator>Willem van Bergen</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[caveats]]></category>
		<category><![CDATA[DELETE]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[PUT]]></category>
		<category><![CDATA[request]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=486</guid>
		<description><![CDATA[We have been working hard to implement an XML-based REST-style API for Floorplanner and some of our partners are using it already to access their users and plans. We now have started to use this API ourselves.
The Floorplanner Flash application communicates with our servers to load and save projects and designs. The backend for this [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F25%2Fcreating-a-rest-api-for-a-flash-application%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F25%2Fcreating-a-rest-api-for-a-flash-application%2F" height="61" width="51" /></a></div><p>We have been working hard to implement an XML-based REST-style API for Floorplanner and some of our partners are using it already to access their users and plans. We now have started to use this API ourselves.</p>
<p>The Floorplanner Flash application communicates with our servers to load and save projects and designs. The backend for this functionality used to be written in PHP. Eliminating this PHP application simplifies our server setup, eases development and reduces our maintenance burden. To rewrite this functionality in Rails, we decided to eat our own dogfood and use the REST API to load and save designs. Why reinvent the wheel?</p>
<p>However, while implementing the changes it the Flash application, we found that it did not work out of the box, because of some limitations in ActionScript. Note that we still use ActionScript 2, so some of these issues may not be relevant for ActionScript 3. In this post, we will detail what these issues are and how we overcame them.</p>
<h3> Using a separate format </h3>
<p>Our REST API uses the XML format supplied by Rails. Because we had to make some changes to make it work from ActionScript, we decided to add a distinct format that we could implement differently without altering the behavior of the default XML API. Adding a new format, called &#8220;flash&#8221; can be done in Rails by adding a MIME alias to your environment:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family: Monaco,monospace;"><span style="color:#6666ff; font-weight:bold;">Mime::Type</span>.<span style="color:#9900CC;">register_alias</span> <span style="color:#996600;">&quot;application/xml&quot;</span>, <span style="color:#ff3333; font-weight:bold;">:flash</span></pre></div></div>

<p>Now we can send different responses based on this format:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family: Monaco,monospace;">respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">xml</span>   <span style="color:#006600; font-weight:bold;">&#123;</span> ... <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># default API behavior</span>
  <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">flash</span> <span style="color:#006600; font-weight:bold;">&#123;</span> ... <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#008000; font-style:italic;"># do something different</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<h3> HTTP status codes </h3>
<p>REST APIs use HTTP status codes to return whether a call succeeded, and if not, why. Flash however uses the browser to perform HTTP requests. The browser only returns something to Flash if the request was successful. So, if an error code is used if a request failed together with some error messages, these error messages will not be delivered to Flash and cannot be displayed to the user. We resolved this by always sending the HTTP OK status.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family: Monaco,monospace;">respond_to <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>format<span style="color:#006600; font-weight:bold;">|</span>
  <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">xml</span>   <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:xml</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0066ff; font-weight:bold;">@project</span>.<span style="color:#9900CC;">errors</span>, <span style="color:#ff3333; font-weight:bold;">:status</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">422</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#CC0066; font-weight:bold;">format</span>.<span style="color:#9900CC;">flash</span> <span style="color:#006600; font-weight:bold;">&#123;</span> render <span style="color:#ff3333; font-weight:bold;">:xml</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> XML.<span style="color:#9900CC;">failure</span><span style="color:#006600; font-weight:bold;">&#40;</span>@project.<span style="color:#9900CC;">errors</span>, <span style="color:#006666;">422</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Our <code>XML.failure</code> method will return something like:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family: Monaco,monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;failure</span> <span style="color: #000066;">status</span>=<span style="color: #ff0000;">&quot;422&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;error</span> <span style="color: #000066;">on</span>=<span style="color: #ff0000;">&quot;name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>A project should have a name!<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/error<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/failure<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Note that other HTTP success statuses than 200 work in Safari and Firefox, but not in Internet Explorer. So, never return a 201 (<code>:created</code>), because Internet Explorer will not send the result to Flash!</p>
<h3> PUT and DELETE requests </h3>
<p>REST-style APIs use HTTP PUT requests to alter objects and DELETE requests to destroy objects. Most browsers do not support these request type. It is not supported by ActionScript either, because Flash uses the browser to send the request. </p>
<p>To overcome this problem, these types of requests can be simulated in Rails by sending a <code>_method</code> parameter along with a POST request. Unfortunately, this does not work when calling the REST API. The POST request body cannot be used to send additional variables, because it is used for the XML payload.</p>
<p>We solved this issue by creating additional routes for POST requests to the <code>update</code> and <code>destroy</code> actions of our resource controllers. Our <code>routes.rb</code> file now looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family: Monaco,monospace;">  map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:projects</span>, <span style="color:#ff3333; font-weight:bold;">:member</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:update</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:post</span>, <span style="color:#ff3333; font-weight:bold;">:destroy</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:post</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>These routes route to exactly the same methods as the default REST actions (<code>ProjectsController#update</code> and <code>ProjectsController#destroy</code>), so no additional code is needed. The following calls are now equivalent:</p>
<pre>
PUT    /projects/123.xml
POST   /projects/123/update.xml
POST   /projects/123/update.flash

DELETE /projects/123.xml
POST   /projects/123/destroy.xml
POST   /projects/123/destroy.flash
</pre>
<h3>The result </h3>
<p>It requires some stretching of the pure REST principles, but doing so is worth it: we can now reuse the code we use for our API to handle Flash application calls and we can eliminate the PHP backend.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/02/25/creating-a-rest-api-for-a-flash-application/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Write JAVA, publish SWF</title>
		<link>http://techblog.floorplanner.com/2009/02/15/write-java-publish-swf/</link>
		<comments>http://techblog.floorplanner.com/2009/02/15/write-java-publish-swf/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 20:27:16 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[flex builder]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=474</guid>
		<description><![CDATA[Ted Patrick (Senior Manager Developer Communities at Adobe Systems) has posted an interesting article about the first milestone of the Eclipse E4 project.
It seems that the SWT project has added compilation support for SWF from JAVA. Write your app in JAVA and publish as SWF to Flash Player. The cool part is that you get full [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F15%2Fwrite-java-publish-swf%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F02%2F15%2Fwrite-java-publish-swf%2F" height="61" width="51" /></a></div><p>Ted Patrick (Senior Manager Developer Communities at Adobe Systems) has posted <a title="Write JAVA, publish SWF" href="http://onflash.org/ted/2009/02/publish-swt-to-flash-player.php" target="_blank">an interesting article</a> about the first milestone of the <a title="Ecilpse E4 project" href="http://download.eclipse.org/e4/downloads/drops/S-0.9M1-200902061045/e4-news-M1.html" target="_blank">Eclipse E4 project</a>.</p>
<blockquote><p><em>It seems that the SWT project has added compilation support for SWF from JAVA. Write your app in JAVA and publish as SWF to Flash Player. The cool part is that you get full JAVA development in Eclipse with all debugging and tooling but you get a SWF file on publish. </em></p></blockquote>
<p>We&#8217;re using Flex Builder for our Flex/AS3 stuff, but this could become a very interesting option since the JAVA development in Eclipse is a lot more sophisticated than Flex Builder at the moment.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/02/15/write-java-publish-swf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FITC Amsterdam 2009</title>
		<link>http://techblog.floorplanner.com/2009/01/24/fitc-amsterdam-2009/</link>
		<comments>http://techblog.floorplanner.com/2009/01/24/fitc-amsterdam-2009/#comments</comments>
		<pubDate>Sat, 24 Jan 2009 10:52:57 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[amsterdam]]></category>
		<category><![CDATA[fitc]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=419</guid>
		<description><![CDATA[
On February 22-24th the Flash In The Can event is back in town! Design, Technology. Cool shit. I will be just a visitor, but Tim is going to help Ralph with his workshop Papervision3D from the Core. If you want to meet up, give us a ping.
]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F01%2F24%2Ffitc-amsterdam-2009%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2009%2F01%2F24%2Ffitc-amsterdam-2009%2F" height="61" width="51" /></a></div><p><a href="http://fitc.ca"><img class="alignnone size-full wp-image-421" title="FITC Amsterdam 2009" src="http://techblog.floorplanner.com/wp-content/uploads/2009/01/afbeelding-1.png" alt="FITC Amsterdam 2009" width="598" height="150" /></a></p>
<p>On February 22-24th the Flash In The Can event is back in town! Design, Technology. Cool shit. I will be just a visitor, but Tim is going to help <a title="Ralph Hauwert" href="http://www.unitzeroone.com/blog/" target="_blank">Ralph</a> with his workshop <a title="Papervision3D from the Core" href="http://www.fitc.ca/presentation_detail.cfm?festival_id=80&amp;presentation_id=749" target="_blank">Papervision3D from the Core</a>. If you want to meet up, give us a ping.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2009/01/24/fitc-amsterdam-2009/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Drag&#8217;n&#039;drop from HTML to Flash</title>
		<link>http://techblog.floorplanner.com/2008/11/06/dragndrop-from-html-to-flash/</link>
		<comments>http://techblog.floorplanner.com/2008/11/06/dragndrop-from-html-to-flash/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 10:42:12 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[drag]]></category>
		<category><![CDATA[drop]]></category>
		<category><![CDATA[externalinterface]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[script.aculo.us]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=247</guid>
		<description><![CDATA[Last week we released a new Floorplanner account, the Enterprise account. With it, companies can have an online Floorplanner solution completely branded to their wishes. It includes the Roomplanner module and a custom library of their own furniture elements.  Steelcase and Maxon are the first to have an active Enterprise account.

The interesting part of this [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F11%2F06%2Fdragndrop-from-html-to-flash%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F11%2F06%2Fdragndrop-from-html-to-flash%2F" height="61" width="51" /></a></div><p>Last week we released a new Floorplanner account, the <a href="http://beta.floorplanner.com/products/comparison">Enterprise account</a>. With it, companies can have an online Floorplanner solution completely branded to their wishes. It includes the Roomplanner module and a custom library of their own furniture elements.  <a href="http://steelcase.floorplanner.com">Steelcase</a> and <a href="http://maxon.floorplanner.com">Maxon</a> are the first to have an active Enterprise account.</p>
<div style="float:right;margin-left:10px;margin-bottom:10px;border:1px solid #ccc;"><img title="drag-n-drop" src="http://techblog.floorplanner.com/wp-content/uploads/2008/11/afbeelding-7.png" alt="" width="296" height="150" /></div>
<p>The interesting part of this release, from a tech point of view, is the new drag-and-drop functionality. The Roomplanner is running in the Flash Player. However, the library of furniture elements is in HTML. We chose to build the furniture library in the HTML sidebar for a couple of reasons. It&#8217;s not in the Roomplanner, so there is more space left to design. It gives us more freedom in the page layout. All items on the page are indexed and things like sorting and tags we&#8217;re easier to build in Ruby on Rails than in Flash.</p>
<p>Now we only needed a way to get the furniture from the sidebar to the Roomplanner. That&#8217;s where the drag&#8217;n'drop comes in, drag from HTML and drop in Flash. To drag an image of a furniture element in HTML we used the fantastic JavaScript <a href="http://script.aculo.us/">script.aculo.us</a> framework. The next step was to swap the image to an element in the Roomplanner and to update the position of the element while moving the cursor on the Flash content. For this we used ExternalInterface to communicate between JavaScript and ActionScript. That&#8217;s all there is to it. The theory is actually quite simple, but in practice it was very (I repeat, VERY) difficult to get it working in all the main browsers. All those nitty gritty browser details&#8230;</p>
<p>At this moment everything seems to work just fine, so please take a look at <a href="http://steelcase.floorplanner.com">Steelcase</a> and/or <a href="http://maxon.floorplanner.com">Maxon</a> and let me know what you think!</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/11/06/dragndrop-from-html-to-flash/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>New cross domain findings</title>
		<link>http://techblog.floorplanner.com/2008/09/12/new-cross-domain-findings/</link>
		<comments>http://techblog.floorplanner.com/2008/09/12/new-cross-domain-findings/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 09:08:38 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[bitmapdata]]></category>
		<category><![CDATA[crossdomain.xml]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[policy file]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=154</guid>
		<description><![CDATA[Today I learned a couple of new things about the use (and trouble) of BitmapData in combination with loading content from other domains. I thought we solved it a while ago, but it in some situations it didn&#8217;t work&#8230; I definitely hope this is my last post about the subject!
When you load content from another domain and [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F09%2F12%2Fnew-cross-domain-findings%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F09%2F12%2Fnew-cross-domain-findings%2F" height="61" width="51" /></a></div><p>Today I learned a couple of new things about the use (and trouble) of BitmapData in combination with loading content from other domains. I thought we <a href="http://techblog.floorplanner.com/2008/05/26/bitmapdatadraw-cross-domains/">solved it</a> a while ago, but it in some situations it didn&#8217;t work&#8230; I definitely hope this is my last post about the subject!</p>
<p>When you load content from another domain and you want to use BitmapData, then you always have to load a policy file (crossdomain.xml) from that other domain. What I discovered today is that you have to do this for ALL the content you&#8217;re loading, otherwise the BitmapData just doesn&#8217;t work. Even if it&#8217;s content you don&#8217;t want to use for the BitmapData, you still need to load the policy file. It took me quite a while of debugging to figure this out.</p>
<p>This is our current setup. Every server has its own domain.</p>
<p><img class="alignnone size-full wp-image-156" style="border: 0px initial initial;" title="Server setup" src="http://techblog.floorplanner.com/wp-content/uploads/2008/09/afbeelding-4.png" alt="" width="540" height="227" /></p>
<p>The other thing I learned today is a small trick to remove the <em>Warning</em> in your logs. Jeffry Houser explains it in his post <a href="http://www.jeffryhouser.com/index.cfm/2008/8/12/Fixing-your-CrossDomainxml-File">Fixing your CrossDomain.xml File.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/09/12/new-cross-domain-findings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Error calling method on NPObject!</title>
		<link>http://techblog.floorplanner.com/2007/03/13/error-calling-method-on-npobject/</link>
		<comments>http://techblog.floorplanner.com/2007/03/13/error-calling-method-on-npobject/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 13:32:35 +0000</pubDate>
		<dc:creator>jaap</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[crossdomain]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/?p=5</guid>
		<description><![CDATA[UPDATE:
To fix the issue I discussed some days ago(see below) use:
System.security.allowDomain(&#8221;http://ip-adress&#8221;);
ip-adress is the IP you are developing on! This will fix the security issues!

While trying to let Actionscript talk to Javascript using the External Interface API of Actionscript I bounced upon a problem when Actionscript tried to invoke this Javascript function. In Firefox 2.0.0.2 an [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2007%2F03%2F13%2Ferror-calling-method-on-npobject%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2007%2F03%2F13%2Ferror-calling-method-on-npobject%2F" height="61" width="51" /></a></div><p><strong>UPDATE:</strong><br />
<em>To fix the issue I discussed some days ago(see below) use:<br />
System.security.allowDomain(&#8221;http://ip-adress&#8221;);<br />
ip-adress is the IP you are developing on! This will fix the security issues!<br />
</em></p>
<p>While trying to let Actionscript talk to Javascript using the External Interface API of Actionscript I bounced upon a problem when Actionscript tried to invoke this Javascript function. In Firefox 2.0.0.2 an alert message shouted to me: &#8220;Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.].&#8221;. </p>
<p>My precise environment was, the html running on the localhost (Rails application) and the swf from an other domain and this seemed to be the  problem. When I deployed the Rails application to this server, there was no problem at all invoking these functions. It looks like a bug in the flash player, cause I tried all the security settings possible in flash, the famous crossdomain.xml, adding all locations to the flash settings but no result. Somehow the SWF from that other domain had some troubles talking to the local javascript. </p>
<p>My way to solve this issue was to load the SWF also from the localhost. Everything works perfectly and I can continue testing.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2007/03/13/error-calling-method-on-npobject/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>SWF and Internet Explorer</title>
		<link>http://techblog.floorplanner.com/2007/03/13/swf-and-internet-explorer/</link>
		<comments>http://techblog.floorplanner.com/2007/03/13/swf-and-internet-explorer/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 12:23:16 +0000</pubDate>
		<dc:creator>Gert-Jan</dc:creator>
				<category><![CDATA[Flash+ActionScript]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://www.suite75.net/blog/dev/?p=4</guid>
		<description><![CDATA[After some diggin&#8217; I finally figured out why Internet Explorer didn&#8217;t display my SWF movie. The width and the height of my movie are related to the width and height of the Stage. It seems that in IE the Stage isn&#8217;t available in the first frame. Therefore the movie has to wait a frame before [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2007%2F03%2F13%2Fswf-and-internet-explorer%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2007%2F03%2F13%2Fswf-and-internet-explorer%2F" height="61" width="51" /></a></div><p>After some diggin&#8217; I finally figured out why Internet Explorer didn&#8217;t display my SWF movie. The width and the height of my movie are related to the width and height of the Stage. It seems that in IE the Stage isn&#8217;t available in the first frame. Therefore the movie has to wait a frame before it can acces the Stage properties.</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family: Monaco,monospace;"><span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> Application<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
  addEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span>, <span style="color: #0066CC;">onEnterFrame</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> <span style="color: #0066CC;">onEnterFrame</span><span style="color: #66cc66;">&#40;</span> pEvent:Event <span style="color: #66cc66;">&#41;</span> : <span style="color: #0066CC;">void</span> <span style="color: #66cc66;">&#123;</span>
  removeEventListener<span style="color: #66cc66;">&#40;</span> Event.<span style="color: #006600;">ENTER_FRAME</span>, <span style="color: #0066CC;">onEnterFrame</span> <span style="color: #66cc66;">&#41;</span>;
  setWidth<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageWidth</span> <span style="color: #66cc66;">&#41;</span>;
  setHeight<span style="color: #66cc66;">&#40;</span> <span style="color: #0066CC;">stage</span>.<span style="color: #006600;">stageHeight</span> <span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>
</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2007/03/13/swf-and-internet-explorer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
