<?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>noCreativity.com &#187; application</title>
	<atom:link href="http://nocreativity.com/blog/tag/application/feed" rel="self" type="application/rss+xml" />
	<link>http://nocreativity.com</link>
	<description>The life and discoveries of a new media artist</description>
	<lastBuildDate>Sat, 07 Jan 2012 17:03:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>4 &#8220;WTF?!&#8221; moments during a Flex/AIR experiment</title>
		<link>http://nocreativity.com/blog/4-wtf-moments-during-a-flexair-experiment</link>
		<comments>http://nocreativity.com/blog/4-wtf-moments-during-a-flexair-experiment#comments</comments>
		<pubDate>Thu, 11 Jun 2009 11:56:30 +0000</pubDate>
		<dc:creator>Ronny</dc:creator>
				<category><![CDATA[Download]]></category>
		<category><![CDATA[Experiments]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Alchemy]]></category>
		<category><![CDATA[application]]></category>
		<category><![CDATA[cross platform]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[JPGEncoding]]></category>
		<category><![CDATA[Photo Booth]]></category>
		<category><![CDATA[timelapse]]></category>

		<guid isPermaLink="false">http://nocreativity.com/blog/?p=551</guid>
		<description><![CDATA[On a shiny day I was sitting inside, and I don&#8217;t know what bug just bit me, but I felt like experimenting with Flex and AIR (instead of heading outside into the light). For some reason I felt like creating a Photobooth clone with only one feature: Taking a snapshot every few seconds and saving [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-558" title="picture-1462" src="http://nocreativity.com/blog-engine/wp-content/uploads/2009/06/picture-1462-278x300.jpg" alt="picture-1462" width="278" height="300" />On a shiny day I was sitting inside, and I don&#8217;t know what bug just bit me, but I felt like experimenting with Flex and AIR (instead of heading outside into the light). For some reason I felt like creating a Photobooth clone with only one feature: Taking a snapshot every few seconds and saving it to the disk. During my quest I came across a few findings that were either extremely weird or just plain awesome. Here goes my list of &#8216;WTF?!&#8217;<br />
(If you don&#8217;t like reading, but you do want to check out the AIR app, click <a href="http://nocreativity.com/stuff/Alchyboot.air" target="_blank">here</a>)<span id="more-551"></span></p>
<h2>HorizontalList and ItemRenderers in Flex</h2>
<p>I must&#8217;ve done something wrong&#8230; I can&#8217;t imagine this being so hard.<br />
What I did was: I used a simple HorizontalList component, set the columnWidth to 80, built my own itemrenderer and put them together. The itemrenderer basically loads a JPG and displays it. Seen as my images were larger than 80px I decided to do some maths the resize the image on the fly.<br />
To start with, i went into my itemrenderer, and traced the with of the bitmap, and the width of the itemrenderer itself. Just to make sure those properties are actually ready. First thing to notice: <em>this.width</em> inside the itemrenderer randomly traced 80 and 85.<img class="alignright" title="Flex" src="http://nocreativity.com/blog-engine/wp-content/uploads/2008/09/flex-icon.jpg" alt="" width="100" height="100" /></p>
<p>What the f-&#8230; Wait&#8230; Eh&#8230; No, what?</p>
<p>I didn&#8217;t really find out why that is, but if anybody feels like enlightning me: go right ahead. (After that, I noticed that sometimes the first or the last (or both) items in the list weren&#8217;t updating at all&#8230; I must be misunderstanding some fundamentals of the framework I guess&#8230; [Btw: I did NOT manage to fix this in a decent way, so at some point I gave up an threw it away...])</p>
<h2>The panel titlebar in Flex</h2>
<p>So this is AIR, right? Goodbye system chrome, hello you science-fiction-looking chrome! I created my own (very Flex-looking) chrome and disabled the system chrome. I wanted my app to be able to be moved around on the desktop&#8230; You know: Like windows do (not Windows&#8230;).<br />
I figured: Hell, the Panel component looks a lot like a basic window. Why not use it as the main window? So what&#8217;s the first thing a regular human brain would do? Right, you&#8217;ll try to get to the titleBar via the panel instance&#8230; But you can&#8217;t! I figured I must be misunderstanding the construction of the panel. So there I go, reading about the titleBar on the <a href="http://livedocs.adobe.com/flex/3/langref/mx/containers/Panel.html#titleBar" target="_blank" target="_blank">Panel Class page</a> in the Flex Livedocs. Most of you already know but just let me spell it out for you: It&#8217;s <em>protected</em>&#8230; So you can&#8217;t get to it right away&#8230; You have to built your own panel class that extends the original Panel class, and create your own public getter for the titleBar&#8230;</p>
<p>Excuse me: WTF? Oh, I think I understa&#8230; Oh, no I don&#8217;t: Why again?</p>
<p>No seriously: What&#8217;s the deal with that? I can see how you don&#8217;t want a setter there&#8230; But no getter? What good is that supposed to do? Anyway, let&#8217;s fix this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000066; font-weight: bold;">?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>mx <span style="color: #000066; font-weight: bold;">:</span>Panel xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;absolute&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;400&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;300&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">&gt;&lt;</span>mx <span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span> <span style="color: #000066; font-weight: bold;">!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
<span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>core<span style="color: #000066; font-weight: bold;">.</span>UIComponent<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #0033ff; font-weight: bold;">get</span> theTitlebar<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span>UIComponent<span style="color: #000000;">&#123;</span>
<span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">this</span><span style="color: #000066; font-weight: bold;">.</span>titleBar<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
<span style="color: #000000;">&#125;</span>
<span style="color: #009900; font-style: italic;">// There are probably way easier/simpler ways than this...</span>
<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">&gt;</span></pre></div></div>

<p>And now I can use theTitlebar of my DraggablePanel class to actually drag my panel like a real window&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3" style="font-family:monospace;">pnlMain<span style="color: #000066; font-weight: bold;">.</span>theTitlebar<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">MouseEvent</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">MOUSE_DOWN</span><span style="color: #000066; font-weight: bold;">,</span> startTheDrag<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> startTheDrag<span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><span style="color: #004993;">MouseEvent</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
nativeWindow<span style="color: #000066; font-weight: bold;">.</span>startMove<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>That looks pretty straight forward, and actually works like a charm&#8230; But why did I have to do this? Why is the titleBar protected??</p>
<h2>AS3 JPGEncoder for FP9, FP10 and the one on speedballs</h2>
<p>So at one point I actually got to building the thing I actually wanted to build: A Photobooth-clone that takes a picture and saves it to the harddrive. Drawing the bitmap went fine, saving the encoded JPG to disk went perfectly smooth as well. The AIR API is really fun to work with. Pretty straight foward&#8230; But I will get back to that in just a minute&#8230;</p>
<p>The problem at hand right now was the Bitmap encoding: I draw a bitmap (480 x 360) and I want to write it to disk. So I include the <a href="http://code.google.com/p/as3corelib/" target="_blank" target="_blank">AS3corelib</a> in my project and continue my quest. When testrunning I notice the application freezes while the bitmapdata is encoded. And not just for a moment. Noooo&#8230; For a full second (or longer)! I can hear you thinking: &#8216;A second&#8230;? So?&#8217;. Well if you want to shoot a picture every second this application will just completely freeze. And let&#8217;s just face the fact: it&#8217;s just plain annoying the have an application the freezes every few seconds for that amount of time.</p>
<p>So I started playing with quality settings, and bitmap sizes. All to no avail. The encoder is just too slow. <a href="http://Peterelst.com" target="_blank" target="_blank">Peter</a> suggested taking a look at the Vector implementation found <a href="http://www.bytearray.org/?p=775" target="_blank" target="_blank">here</a>. That went way faster already: Up to 4 times faster. But still: 0.3 seconds is pretty slow&#8230; So I read through the comments and run into the magic word: &#8216;<a href="http://labs.adobe.com/technologies/alchemy/" target="_blank" target="_blank">Alchemy</a>&#8216;. I haven&#8217;t been playing with Alchemy myself (mainly because I don&#8217;t know C), but I knew Alchemy would be the key to he solution of this problem. So I downloaded <a href="http://segfaultlabs.com/blog/post/asynchronous-jpeg-encoding" target="_blank" target="_blank">this SWC</a> (<a href="http://segfaultlabs.com/swf/alchemy/alchemyJpegUpdate_sv/alchemy_flex.zip" target="_blank" target="_blank">direct link</a>), implemented this version of the encoder, ran the script and&#8230;<br />
&#8230;.I went &#8216;WHAT THE FUUUUCK?&#8217; (You can see what that looks like below)</p>
<div style="text-align:center"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="368" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=5101218&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ffff00&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="480" height="368" src="http://vimeo.com/moogaloop.swf?clip_id=5101218&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=ffff00&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
<p>This video was made using the pictures Alchemy created. Alchemy was encoding these bitmaps in .05 seconds per frame! (I swear, I went on for at least 15 minutes WTF-ing over and over again&#8230;). So: From 1.2 seconds to 0.05 seconds&#8230; That&#8217;s about 24 times faster. Ain&#8217;t that amazing?</p>
<p>The coolest thing? I didn&#8217;t even have to compile the C code myself as I was given the .swc file. (Believe me I gave C compiling a try, but me and Terminal&#8230; It&#8217;s just not gonna happen&#8230;)</p>
<h2>File.nativePath and File.url in AIR</h2>
<p><img class="alignleft" title="AIR" src="http://nocreativity.com/blog-engine/wp-content/uploads/2008/09/air_icon_special.jpg" alt="" width="100" height="100" />The one thing I love about AIR? The combination of creating crossplatform applications using the tools I&#8217;m familiar with from online development. The keyword here is <em>crossplatform</em>. Creating AIR apps is supposed to be a straight forward process. You shouldn&#8217;t worry about platform specific issues. AIR is handling the heavy lifting for you. The only thing you need to do is create the app using the crossplatform API. Or so you would think.</p>
<p>One of the first things I noticed was the fact that the <em>file.nativePath </em>property isn&#8217;t all that crossplatform. And nobody can&#8217;t really explain why. Even <a href="http://theflashblog.com" target="_blank" target="_blank">Lee Brimelow</a> didn&#8217;t manage to explain that in <a href="http://www.gotoandlearn.com/play?id=42" target="_blank" target="_blank">his tutorial</a>&#8230;</p>
<p>I mean: How can the <em>native path</em> not be <em>cross platform</em>? It&#8217;s native to it&#8217;s own platform! (I really went WTF when learning that).</p>
<p>Apparently you can do anything using the <em>file.url</em> property. To me <em>file.nativePath</em> isn&#8217;t intended to be used when trying to access a file, but more intended to show the end-user where on the filesystem the file resides using a <em>platform native notation</em>.</p>
<p>Examples</p>
<ul>
<li>Windows XP: c:\Documents and Settings\noCreativity\My Documents\myFile.jpg</li>
<li>Windows Vista: c:\Users\noCreativity\My Documents\myFile.jpg</li>
<li>OSX: /Users/noCreativity/Documents/myFile.jpg</li>
</ul>
<p>instead of</p>
<ul>
<li>file:///c:/Documents%20and%Settings/noCreativity/My%20Documents/myFile.jpg</li>
<li>file:///Users/noCreativity/Documents/myFile.jpg</li>
</ul>
<p>I am no Adobe AIR expert so please, feel free to correct me. Because this really itches me. How can a crossplatform API have a property which is not crossplatform-compatible (and don&#8217;t get me started on the whole OSX Dock/menubar vs Windows Start Menu/taskbar thing&#8230; But somehow, that&#8217;s different&#8230;)</p>
<h2>Finally&#8230; The end&#8230;</h2>
<p>Yes, I had a hard time doing all this but I learned a lot! My conclusions?</p>
<p>I like Flex and how it enables you to rapidly create data driven applications, but I&#8217;m pretty sure I&#8217;d really have to look into the inner workings of the framework before trying to build something, using the framework&#8230; And basically that &#8216;really looking into it&#8217; ruins the mood for me&#8230; Definitely when experimenting.</p>
<p>Alchemy is amazing! I can&#8217;t wait to get a good C development environment up on my iMac and start playing with C and lean how I can get the best from both worlds. If you have got any decent suggestions on how to do that [without Terminal] feel free to tell me <img src='http://nocreativity.com/blog-engine/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /><br />
Oh and by the way: If you&#8217;re experimenting with Alchemy and you&#8217;re open-sourcing code or libraries, I encourage you to add a .swc file with the compiled C code. Thanks in advance!</p>
<p>I love the AIR API. Although that nativePath thing will keep haunting me until somebody can give me a straight answer, &#8217;cause I feel like a complete idiot right now.</p>
<p>Oh, and if you care: Feel free to check out the application!</p>
<p><strong>Download</strong>: <a href="http://nocreativity.com/blog-engine/wp-content/plugins/download-monitor/download.php?id=1" title="Alchyboot - Downloaded 287 times">Click</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://nocreativity.com/blog/4-wtf-moments-during-a-flexair-experiment/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

