<?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>Pig Development</title>
	<atom:link href="http://blog.pigdev.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.pigdev.com</link>
	<description>Flash Platform and Multimedia topics from Brad Manderscheid</description>
	<lastBuildDate>Sat, 03 Oct 2009 00:18:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AIR / PDF and SnowLeopard compatibility issue</title>
		<link>http://blog.pigdev.com/?p=187</link>
		<comments>http://blog.pigdev.com/?p=187#comments</comments>
		<pubDate>Sat, 03 Oct 2009 00:18:45 +0000</pubDate>
		<dc:creator>Brad Manderscheid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.pigdev.com/?p=187</guid>
		<description><![CDATA[I recently have been working an AIR application and hit a wall fast when the PDF load portion of the app kept crashing when the PDF would load in.  Of course I spent a good day trying to figure this out.  I jumped on this thread and had a few email conversations with [...]]]></description>
			<content:encoded><![CDATA[<p>I recently have been working an AIR application and hit a wall fast when the PDF load portion of the app kept crashing when the PDF would load in.  Of course I spent a good day trying to figure this out.  I jumped on <a href="http://groups.google.com/group/air-tight/browse_thread/thread/26b947eff5b2b211?pli=1">this thread</a> and had a few email conversations with members of the AIR team.  Finally it was confirmed that this is a SnowLeopard and AIR compatibility issue.  Everything else seems to be working fine in SL, but of course the app I&#8217;m working on uses features with issues. sigh&#8230; Anyway, I hope this saves someone a headache. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pigdev.com/?feed=rss2&amp;p=187</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Client-Side Image Manipulation and Upload using Flex 3 (fp10) and Zend AMF</title>
		<link>http://blog.pigdev.com/?p=137</link>
		<comments>http://blog.pigdev.com/?p=137#comments</comments>
		<pubDate>Mon, 24 Aug 2009 16:45:45 +0000</pubDate>
		<dc:creator>Brad Manderscheid</dc:creator>
				<category><![CDATA[Flash Player 10]]></category>
		<category><![CDATA[Flex 3]]></category>

		<guid isPermaLink="false">http://blog.pigdev.com/?p=137</guid>
		<description><![CDATA[There are many cool server-side image manipulation libraries out there including the very popular GD for PHP.  The problem is that your server has to have it installed for you to be able to utilize it and if your server does not ( and you don&#8217;t admin your own), it&#8217;s often difficult or even [...]]]></description>
			<content:encoded><![CDATA[<p>There are many cool server-side image manipulation libraries out there including the very popular GD for PHP.  The problem is that your server has to have it installed for you to be able to utilize it and if your server does not ( and you don&#8217;t admin your own), it&#8217;s often difficult or even impossible for you to install it yourself.  Another pitfall of using the server-side approach for image processing is that you still have to upload the image before it can be processed, and with cameras these days, end users will most likely upload some pretty large images.</p>
<p>Ideally we would process the image locally before sending it to the server.  I did some hefty research and found a lot of cool things we can do in the flash player, but no solid step by step to doing exactly what I wanted to achieve.  My goal was to do the following.</p>
<p>1. Allow user to browse for image on their local system<br />
2. Convert file reference into BitmapData<br />
3. Scale BitmapData to fit inside a MAX resolution<br />
4. Compress and encode the BitmapData into a ByteArray<br />
5. Send ByteArray to server-side script to create and save the image file</p>
<p>After finding several articles covering pieces of these steps, I was able to stitch together the code to achieve the above goal. To use my code examples, you will need to use Flex 3 targeted for Flash Player 10 and Zend AMF to send the image data to your server.</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&#8220;1.0&#8243;</span> encoding=<span class="st0">&#8220;utf-8&#8243;</span>?&gt;<br />
&lt;mx:Application xmlns:mx=<span class="st0">&#8220;http://www.adobe.com/2006/mxml&#8221;</span> layout=<span class="st0">&#8220;absolute&#8221;</span>&gt;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:Script&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!<span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">import</span> mx.<span class="me1">graphics</span>.<span class="me1">codec</span>.<span class="me1">JPEGEncoder</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _fileRef:FileReference;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _netConnection:<span class="kw3">NetConnection</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _imageByteArray:ByteArray;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw3">static</span> const MAX_SIZE:<span class="kw3">Number</span> = <span class="nu0">300</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> getFile<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _fileRef = <span class="kw2">new</span> FileReference<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _fileRef.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">SELECT</span>,onFileSelect<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _fileRef.<span class="me1">browse</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onFileSelect<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _fileRef.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>,onFileLoad<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _fileRef.<span class="kw3">load</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onFileLoad<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> loader:Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">contentLoaderInfo</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">COMPLETE</span>, onImageLoaded<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; loader.<span class="me1">loadBytes</span> <span class="br0">&#40;</span>_fileRef.<span class="kw3">data</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> onImageLoaded<span class="br0">&#40;</span><span class="kw3">e</span>:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> loadedBitmap:Bitmap = Bitmap<span class="br0">&#40;</span><span class="kw3">e</span>.<span class="kw3">target</span>.<span class="me1">content</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> scale:<span class="kw3">Number</span> = getScale<span class="br0">&#40;</span>loadedBitmap<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> bmpData:BitmapData = <span class="kw2">new</span> BitmapData<span class="br0">&#40;</span>loadedBitmap.<span class="kw3">width</span> * scale, loadedBitmap.<span class="kw3">height</span> * scale,<span class="kw2">false</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> matrix:Matrix = <span class="kw2">new</span> Matrix<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; matrix.<span class="me1">scale</span><span class="br0">&#40;</span>scale,scale<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bmpData.<span class="me1">draw</span><span class="br0">&#40;</span>loadedBitmap,matrix<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> jpg:JPEGEncoder = <span class="kw2">new</span> JPEGEncoder<span class="br0">&#40;</span><span class="nu0">60</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _imageByteArray = jpg.<span class="me1">encode</span><span class="br0">&#40;</span>bmpData<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uploadImage<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> getScale<span class="br0">&#40;</span>img:Bitmap<span class="br0">&#41;</span>:<span class="kw3">Number</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> scale:<span class="kw3">Number</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>img.<span class="kw3">width</span> &gt; MAX_SIZE<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scale = MAX_SIZE / img.<span class="kw3">width</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span>img.<span class="kw3">height</span> &gt; MAX_SIZE<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scale = MAX_SIZE / img.<span class="kw3">height</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scale = <span class="nu0">1</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> scale;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> uploadImage<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _netConnection = <span class="kw2">new</span> <span class="kw3">NetConnection</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _netConnection.<span class="kw3">connect</span><span class="br0">&#40;</span><span class="st0">&#8216;http://localhost:8888/_PHP/classes/&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> res:Responder = <span class="kw2">new</span> Responder<span class="br0">&#40;</span>onDataResult, onDataError<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _netConnection.<span class="kw3">call</span><span class="br0">&#40;</span><span class="st0">&#8220;KingHippo.saveImage&#8221;</span>,res,_imageByteArray<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> onDataResult<span class="br0">&#40;</span>obj:<span class="kw3">Object</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span>obj<span class="br0">&#41;</span>;<span class="co1">/////FILE SAVED</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> onDataError<span class="br0">&#40;</span>obj:<span class="kw3">Object</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&#8216;error&#8217;</span><span class="br0">&#41;</span>;<span class="co1">///////OOPS</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/mx:Script&gt;</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Button</span> label=<span class="st0">&#8220;browse&#8221;</span> click=<span class="st0">&#8220;getFile()&#8221;</span> /&gt;</p>
<p>&lt;/mx:Application&gt;</p></div>
</div>
<p>That pretty much wraps up the Flex code.  I&#8217;ll explain the code referring to our original goal list.</p>
<p>1. Allow user to browse for image<br />
Here we have a simple Button that calls a function that will instantiate a file reference object and use its browse() method to prompt the user with their local file browser.</p>
<p>2. Convert file reference into BitmapData<br />
Upon file select, we will need to get this file loaded in to grab its BitmapData. This is where Flash Player 10 comes in. We now have some cool FileReference additions to play with and can now load in the file selected.  First we call the load() method.  When COMPLETE, we have access to the data of that file which means we can use a Loader to load the bytes of the data using the loadBytes() method from our Loader.</p>
<p>3. Scale BitmapData to fit inside a MAX resolution<br />
OK, so now we have our image data and its time to do some BitmapData trickery. First we need to set the incoming data to a Bitmap object. Next we determine how much we need to scale down the image by using our MAX_SIZE variable.  Here I&#8217;m using 300 so the width or height will not exceed that number. Once I determine the scale value (using the getScale function) , I can now create and manipulate my Bitmap Data.  I create a new BitmapData object and set it to the appropriate size using my scale value against the image&#8217;s original size. Now I need to draw from the loaded image. It&#8217;s not enough to just draw it b/c it will just grab that rect from the original image data, essentially cropping it.  We need to use Matrix to set the scale of the original data within our draw() method.<br />
Now we have our image data and appropriate resolution. </p>
<p>4. Compress and encode BitmapData into a ByteArray<br />
Next, using Flex&#8217;s JPEGEncoder, we can compress the data and encode it to a ByteArray.  Simply create a new JPEGEncoder object and pass a quality value to its constructor. The values are 1 &#8211; 100.  Here I&#8217;m using 60. Then we call the JPEGEncoder&#8217;s encode() method which will then give us our long-awaited ByteArray.  Now we can pass it on to the server.</p>
<p>5. Send ByteArray to server-side script to create image file<br />
Lastly, we need to send off the image data to the server.  Here I&#8217;m using Zend AMF and sending the ByteArray to a PHP class.</p>
<p>Now we are done on the Flex end.  The last thing we need to do is create the image file from the data sent to the server and save it.<br />
PHP code below..</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?php</p>
<p><span class="kw2">class</span> KingHippo<span class="br0">&#123;</span>&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//////construct</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> saveImage<span class="br0">&#40;</span>$obj<span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $fp = fopen<span class="br0">&#40;</span><span class="st0">&#8216;myNewImage.jpg&#8217;</span>, <span class="st0">&#8216;wb&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fwrite<span class="br0">&#40;</span> $fp, implode<span class="br0">&#40;</span><span class="st0">&#8221;</span>,$obj<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fclose<span class="br0">&#40;</span> $fp <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&#8220;FILE SAVED&#8221;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></p>
<p>&lt;?</p></div>
</div>
<p>That&#8217;s pretty much it. You&#8217;ll most likely want to add to it by sending a unique path and file name for the saved image.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pigdev.com/?feed=rss2&amp;p=137</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Column View File Browser with Flex 3 and Air 1.5 (part 1)</title>
		<link>http://blog.pigdev.com/?p=103</link>
		<comments>http://blog.pigdev.com/?p=103#comments</comments>
		<pubDate>Wed, 05 Aug 2009 02:18:51 +0000</pubDate>
		<dc:creator>Brad Manderscheid</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.pigdev.com/?p=103</guid>
		<description><![CDATA[I&#8217;ve been starting and stopping this AIR application idea I&#8217;ve had for a while which is, in a nutshell, some sort of super local file manager.  I&#8217;m always creating and moving around Finder windows to fit a specific need or project so I think it would be nice to have an app that will [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_118" class="wp-caption aligncenter" style="width: 635px"><img class="size-full wp-image-118" title="fileBrowser" src="http://blog.pigdev.com/wp-content/uploads/2009/08/fileBrowser41.jpg" alt="Column View File Browser v.1" width="625" height="325" /><p class="wp-caption-text">Column View File Browser </p></div>
<p>I&#8217;ve been starting and stopping this AIR application idea I&#8217;ve had for a while which is, in a nutshell, some sort of super local file manager.  I&#8217;m always creating and moving around Finder windows to fit a specific need or project so I think it would be nice to have an app that will handle all of that in one application window. I&#8217;ve used SQLite for other AIR apps so adding &#8216;Favorites&#8217; and &#8216;Preferences&#8217; should make this application fairly decent.  I&#8217;m sure these sorts of applications exist but I think it would be the perfect project to gain some more AIR skills.</p>
<p>Recently I decided to pick it back up and try to actually finish it.  This time I&#8217;m starting over from scratch and hopefully I&#8217;ll remember all of the &#8216;gotchas&#8217; when creating this in Flex that made me give up some many times in the past.  The first thing I decided to do was to make a better file browser that will be used for the windows in my app.  I&#8217;m not really all that happy with the packaged FileSystem.. Flex components so I decided to create one.  I&#8217;m a huge fan of the column view in Finder on a Mac, so I decided to mimic this approach. </p>
<p>A snapshot of the component so far is above.</p>
<p>I call this &#8216;part one&#8217; because I have not gotten too much into skinning etc on this one, but I plan on doing that next.  I can already see the cool things I&#8217;ll be able to do with it now that the base functionality is complete. I&#8217;ll be using icons for the files in the lists as well as image, video, and sound previews in the file info columns.  Should be pretty fun.</p>
<p>Do I dare create a Cover Flow version as well?? Eh, sounds like a pain in the ass.</p>
<p><a href="http://blog.pigdev.com/examples/FileListViewer.zip">Grab Source</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pigdev.com/?feed=rss2&amp;p=103</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Flash CS5 Wishlist</title>
		<link>http://blog.pigdev.com/?p=75</link>
		<comments>http://blog.pigdev.com/?p=75#comments</comments>
		<pubDate>Thu, 23 Jul 2009 17:14:19 +0000</pubDate>
		<dc:creator>Brad Manderscheid</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Builder]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.pigdev.com/?p=75</guid>
		<description><![CDATA[I was lucky enough to get a free Adobe CS4 upgrade so I installed it the day it was released &#8211; (on my birthday) &#8211; so it&#8217;s hard to say how soon I would&#8217;ve finally upgraded if that hadn&#8217;t been the case.  Having used it for about 9 months now, I&#8217;d say that there [...]]]></description>
			<content:encoded><![CDATA[<p>I was lucky enough to get a free Adobe CS4 upgrade so I installed it the day it was released &#8211; (on my birthday) &#8211; so it&#8217;s hard to say how soon I would&#8217;ve finally upgraded if that hadn&#8217;t been the case.  Having used it for about 9 months now, I&#8217;d say that there are just enough features in Flash to where I couldn&#8217;t go back to using Flash CS3&#8230;but not much.</p>
<p>First and foremost is the Library Search.  This has become crucial to my workflow and I don&#8217;t know how I survived without it. Another one worth mentioning before I go on is the &#8216;Show in Library&#8217; feature.  If you see it on stage, you can gain quick access to it in your library which is another feature that helps a lot, especially when taking over flash projects.</p>
<p>That being said, I thought I&#8217;d come up with a wish list of what I hope to see in Flash CS5.  I&#8217;ve submitted my full list to Adobe but thought I&#8217;d share my top 5 with you.</p>
<p><span style="color:#D507B9;fontWeight:bold">1. Better folder creation in the Library</span><br />
I&#8217;ve become pretty anal with my library these days.  I go as far as to package my movie clips to match the packages of their corresponding classes.  This helps me stay organized but creating those folders inside the library is a pain in the ass (at least on a Mac).  If you select a folder, then click the new folder icon, it won&#8217;t put the new one INSIDE the folder you selected.  With long libraries, it&#8217;s such a pain to go all the way to the bottom, find the new folder, then drag it where you want it. I know there is the Move To&#8230; option, but still, why the extra step?</p>
<p>And please add Right Click (on folder) -&gt; New Folder.</p>
<p><span style="color:#D507B9;fontWeight:bold">2. Update Bitmap from Stage</span><br />
Or at least from the &#8216;other&#8217; properties panel. Getting revisions is a common thing in this field and the &#8216;Update&#8217; feature on bitmaps really helps out.  But most of the time you also have to get to it on the stage to see the result of the update, so it&#8217;d be nice to just do the update from there and not have to dig around in the library.  At least the &#8216;Show in Library&#8217; feature helps out on this one, but it&#8217;s still an extra step.</p>
<p>Right Click -&gt; update&#8230;&#8230;. or at least&#8230;.. select symbol, click &#8216;Update&#8217; from properties panel (currently only has &#8216;Edit&#8217; and &#8216;Swap&#8217;).</p>
<p><span style="color:#D507B9;fontWeight:bold">3. Generate Class for Movie Clip.</span><br />
I&#8217;d be nice if Flash could start a class for me.  Currently, you open its properties, check Export for Action Script, write in your package, go over to another editor and create that class.(or the other way around)  It would be very cool if Flash could create that file for you if you opt to write the class.</p>
<p>So instead of the current alert:</p>
<p>A definition for this class could not be found in the classpath, so one will be automatically generated in the SWF file upon export.</p>
<p>How about:</p>
<p>A definition for this class could not be found in the classpath.<br />
Would you like Flash to create one upon export OR generate the script?</p>
<p>In doing so, Flash would start the class file and create the package directories if they don&#8217;t currently exist.</p>
<p><span style="color:#D507B9;fontWeight:bold">4. Edit Class&#8230;&#8230;..in Flash Builder</span><br />
You can open a class file in CS4 by pressing the pencil icon inside a Movie Clips properties.  Of course this opens in Flash, but with the new Flash Builder, I really hope you have an option to have it open inside of there. And again, let me access its class, or edit the path, without having to first find it in the library.</p>
<p>This feature also goes for double clicking on compiler errors.</p>
<p><span style="color:#D507B9;fontWeight:bold">5. Relative source paths.</span><br />
This one really pisses me off.  I often find myself passing an FLA back and forth with timeline animators and designers, but the thing won&#8217;t publish if it can&#8217;t find my scripts.  Flash puts in an absolute path here (again &#8211; at least on a Mac), which makes sense for cross-project settings, but it gets old when both parties have to change the path to scripts right next to it everytime they get an updated FLA.</p>
<p>I have a few more, like a preference to &#8216;never automatically declare stage instances (for all projects)&#8217;, but those are mostly &#8216;kind of&#8217; important issues.</p>
<p>Please, if any of these things ARE doable, or if you have found a nice solution, respond with them here. Also, are any of these issues not present on a PC?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pigdev.com/?feed=rss2&amp;p=75</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Extending MXML components &#8211; not so straight forward</title>
		<link>http://blog.pigdev.com/?p=26</link>
		<comments>http://blog.pigdev.com/?p=26#comments</comments>
		<pubDate>Sat, 11 Jul 2009 03:34:39 +0000</pubDate>
		<dc:creator>Brad Manderscheid</dc:creator>
				<category><![CDATA[Flex 3]]></category>

		<guid isPermaLink="false">http://blog.pigdev.com/?p=26</guid>
		<description><![CDATA[I came across a snag that took me by surprise while developing our Band Beast Administration. The admin has several views and forms in it and they all basically have the same logic, but different visuals. I write base classes all the time in my Flash development, but hadn&#8217;t attempted to do this with MXML [...]]]></description>
			<content:encoded><![CDATA[<p>I came across a snag that took me by surprise while developing our <a href="http://bandbeast.com" target="_blank">Band Beast</a> Administration. The admin has several views and forms in it and they all basically have the same logic, but different visuals. I write base classes all the time in my Flash development, but hadn&#8217;t attempted to do this with MXML components in Flex. I wrote my base component that would handle common logic and display common visuals and then I created my first component that would extend this base class. The MXML looks like this:<br />
<br />
<i>ChildView.mxml &#8211; extends BaseView</i></p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&#8220;1.0&#8243;</span> encoding=<span class="st0">&#8220;utf-8&#8243;</span>?&gt;<br />
&lt;BaseView xmlns=<span class="st0">&#8220;*&#8221;</span> xmlns:mx=<span class="st0">&#8220;http://www.adobe.com/2006/mxml&#8221;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">width</span>=<span class="st0">&#8220;400&#8243;</span> <span class="kw3">height</span>=<span class="st0">&#8220;300&#8243;</span>&gt;<br />
&lt;/BaseView&gt;</div>
</div>
<p>This works fine and when adding this component to my Application, it looked and worked the same as my base class.  The next logical step, or so I thought, would be to start adding my visual elements in the MXML of my sub component.</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&#8220;1.0&#8243;</span> encoding=<span class="st0">&#8220;utf-8&#8243;</span>?&gt;<br />
&lt;BaseView xmlns=<span class="st0">&#8220;*&#8221;</span> xmlns:mx=<span class="st0">&#8220;http://www.adobe.com/2006/mxml&#8221;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">width</span>=<span class="st0">&#8220;400&#8243;</span> <span class="kw3">height</span>=<span class="st0">&#8220;300&#8243;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Text</span> text=<span class="st0">&#8220;I am a CHILD&#8221;</span> /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:ComboBox /&gt;<br />
&lt;/BaseView&gt;</div>
</div>
<p>When compiling, I got an unexpected error:</p>
<p><b>Error: Multiple sets of visual children have been specified for this component (base component definition and derived component definition).</b></p>
<p>So this means I can extend a MXML component, but I can&#8217;t add visual components to it?  Seems strange to me; why else would you extend a component? After researching, I found out that allowing this approach was a hot debate when developing Flex Builder and Adobe ultimately decided not to allow this procedure.  Instead, they suggest you use what they call &#8216;Component Templating&#8217;. To do this you must first wrap the visual children inside of your sub component inside a tag in your MXML. You can call this tag whatever you want but in this example I called it &#8217;subComponents&#8217;.</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&#8220;1.0&#8243;</span> encoding=<span class="st0">&#8220;utf-8&#8243;</span>?&gt;<br />
&lt;BaseView xmlns=<span class="st0">&#8220;*&#8221;</span> xmlns:mx=<span class="st0">&#8220;http://www.adobe.com/2006/mxml&#8221;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">width</span>=<span class="st0">&#8220;400&#8243;</span> <span class="kw3">height</span>=<span class="st0">&#8220;300&#8243;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;subComponents&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Text</span> text=<span class="st0">&#8220;I am a CHILD&#8221;</span> /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:ComboBox /&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/subComponents&gt;<br />
&lt;/BaseView&gt;</div>
</div>
<p>Notice you&#8217;ll get the following error inside of Flex Builder</p>
<p><b>Error: Could not resolve subComponents to a component implementation</b></p>
<p>This is because you need to declare &#8217;subComponents&#8217; in your base component. At this point, &#8217;subComponents&#8217; is an array that holds all of the display children in your sub component. We need to declare this variable in our base class as well as create our Setter function so its value will be set.<br />
<br />
<i>our BaseClass &#8211; extends Canvas</i></p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&#8220;1.0&#8243;</span> encoding=<span class="st0">&#8220;utf-8&#8243;</span>?&gt;<br />
&lt;mx:Canvas xmlns:mx=<span class="st0">&#8220;http://www.adobe.com/2006/mxml&#8221;</span> <span class="kw3">width</span>=<span class="st0">&#8220;400&#8243;</span> <span class="kw3">height</span>=<span class="st0">&#8220;300&#8243;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:Script&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!<span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _subComponents:<span class="kw3">Array</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">set</span> subComponents<span class="br0">&#40;</span>a:<span class="kw3">Array</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _subComponents = a;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/mx:Script&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Text</span> text=<span class="st0">&#8220;I am the MASTER&#8221;</span> /&gt;<br />
&lt;/mx:Canvas&gt;</div>
</div>
<p>Now we&#8217;ve killed our error and Flex is happy. Lastly, we need to actually add these children to the stage by writing a function that fires on the &#8216;creationComplete&#8217; event in our base class.</p>
<div class="codesnip-container" >
<div class="codesnip">&lt;?<span class="kw3">xml</span> <span class="kw3">version</span>=<span class="st0">&#8220;1.0&#8243;</span> encoding=<span class="st0">&#8220;utf-8&#8243;</span>?&gt;<br />
&lt;mx:Canvas xmlns:mx=<span class="st0">&#8220;http://www.adobe.com/2006/mxml&#8221;</span> <span class="kw3">width</span>=<span class="st0">&#8220;400&#8243;</span> <span class="kw3">height</span>=<span class="st0">&#8220;300&#8243;</span> creationComplete=<span class="st0">&#8220;addSubComponents()&#8221;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:Script&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;!<span class="br0">&#91;</span>CDATA<span class="br0">&#91;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span class="kw3">private</span> <span class="kw2">var</span> _subComponents:<span class="kw3">Array</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">set</span> subComponents<span class="br0">&#40;</span>a:<span class="kw3">Array</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _subComponents = a;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">private</span> <span class="kw2">function</span> addSubComponents<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span><span class="br0">&#40;</span><span class="kw2">var</span> i:<span class="kw3">int</span>=<span class="nu0">0</span>; i &lt; _subComponents.<span class="kw3">length</span>; i++<span class="br0">&#41;</span> <span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span> _subComponents<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#93;</span><span class="br0">&#93;</span>&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;/mx:Script&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;mx:<span class="kw3">Text</span> text=<span class="st0">&#8220;I am the MASTER&#8221;</span> /&gt;<br />
&lt;/mx:Canvas&gt;</div>
</div>
<p>Now we&#8217;ve successfully extended a MXML component. This may sound like a &#8216;work around&#8217;, but in the end it makes sense. Plus the cool part is that now we can add these sub components <i>inside</i> a styled or skinned container &#8212; hence the title &#8216;Component Templating&#8217;.</p>
<div class="codesnip-container" >
<div class="codesnip"><span class="co1">////inside our addSubComponents loop</span><br />
someCoolContainer.<span class="me1">addChild</span><span class="br0">&#40;</span> _subComponents<span class="br0">&#91;</span>i<span class="br0">&#93;</span> <span class="br0">&#41;</span>;</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.pigdev.com/?feed=rss2&amp;p=26</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Flash Builder&#8217;s Getter/Setter Generator is almost cool</title>
		<link>http://blog.pigdev.com/?p=18</link>
		<comments>http://blog.pigdev.com/?p=18#comments</comments>
		<pubDate>Thu, 09 Jul 2009 18:45:06 +0000</pubDate>
		<dc:creator>Brad Manderscheid</dc:creator>
				<category><![CDATA[Flash Builder]]></category>

		<guid isPermaLink="false">http://blog.pigdev.com/?p=18</guid>
		<description><![CDATA[I&#8217;m certainly not a fan of anything writing out code for me, but when it comes to Getter and Setter functions, it can get a bit tedious.  Flash Builder 4 comes with a command that will generate that code for you. To do so, position your cursor inside your variable, then select Source-&#62;Generate Getter/Setter. It [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m certainly not a fan of anything writing out code for me, but when it comes to Getter and Setter functions, it can get a bit tedious.  Flash Builder 4 comes with a command that will generate that code for you. To do so, position your cursor inside your variable, then select Source-&gt;Generate Getter/Setter. It even adds the underscore before your private variable, which I do anyway so I like that. This is all great, but I can&#8217;t stand the way Flash Builder formats code.  There seems to be two camps when it comes to code formatting. One places opening curly braces on the next line, the other does not. Here is a great post by <a href="http://www.gskinner.com/blog/" target="_blank">Grant Skinner</a> on the <a href="http://www.gskinner.com/blog/archives/2008/11/curly_braces_to.html" target="_blank">topic</a>.  Personally, I keep the open curly brace on the same line and Flash Builder does not. I&#8217;ve come to just deal with reformatting when FB creates my new classes, it&#8217;s like second nature now, but now that I have this getter/setter feature, I&#8217;d really like to change the way it formats.</p>
<p>FB4 also has an Event Handler Generator which comes up in your code hinting inside MXML.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pigdev.com/?feed=rss2&amp;p=18</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Flash Builder auto import for static classes</title>
		<link>http://blog.pigdev.com/?p=6</link>
		<comments>http://blog.pigdev.com/?p=6#comments</comments>
		<pubDate>Wed, 08 Jul 2009 04:39:43 +0000</pubDate>
		<dc:creator>Brad Manderscheid</dc:creator>
				<category><![CDATA[Flash Builder]]></category>

		<guid isPermaLink="false">http://blog.pigdev.com/?p=6</guid>
		<description><![CDATA[This is my first blog post ever so I thought I&#8217;d start out with something pretty simple.
I recently discovered a nice, and not so obvious, key command in Flash Builder to import classes. It&#8217;s no secret that when using Flash Builder&#8217;s auto completion after the &#8216;new&#8217; keyword, it will import that class for you, but [...]]]></description>
			<content:encoded><![CDATA[<p>This is my first blog post ever so I thought I&#8217;d start out with something pretty simple.</p>
<p>I recently discovered a nice, and not so obvious, key command in Flash Builder to import classes. It&#8217;s no secret that when using Flash Builder&#8217;s auto completion after the &#8216;new&#8217; keyword, it will import that class for you, but what about when using static classes like Tweener, Sound Mixer, or File?  I often find myself in the middle of writing a function and having to stop, go to the top of my script, and import the static class I want to use. How can I get Flash Builder to import this class for me without having to interupt my flow? Simply press Cntrl + Space (Mac and PC) when the cursor is positioned direclty after the class name and Flash Builder will import the class.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pigdev.com/?feed=rss2&amp;p=6</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
