<?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>GhostWire Studios &#187; Tips</title>
	<atom:link href="http://www.ghostwire.com/blog/archives/category/tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ghostwire.com/blog</link>
	<description>Flash UI Components</description>
	<lastBuildDate>Tue, 23 Aug 2011 03:51:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[AS3] Referencing Embedded Assets Of Another Class Using Underscore</title>
		<link>http://www.ghostwire.com/blog/archives/as3-referencing-embedded-assets-of-another-class-using-underscore/</link>
		<comments>http://www.ghostwire.com/blog/archives/as3-referencing-embedded-assets-of-another-class-using-underscore/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 10:18:10 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1303</guid>
		<description><![CDATA[This is rather unorthodox but it works. In Flash, when you embed an image into the SWF using a static class member of a class, a new class with the name of CLASSNAME_MEMBERNAME is actually created internally. Using flash.utils.getDefinitionByName(), you can access this class, regardless of whether the static member was declared as public or [...]]]></description>
			<content:encoded><![CDATA[<p>This is rather unorthodox but it works.  In Flash, when you embed an image into the SWF using a static class member of a class, a new class with the name of <code>CLASSNAME_MEMBERNAME</code> is actually created internally.  Using flash.utils.getDefinitionByName(), you can access this class, regardless of whether the static member was declared as <code>public</code> or <code>private</code>. This makes it possible to make a very simple embedded image assets manager.</p>
<p><span id="more-1303"></span></p>
<p>Consider the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/background.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 BACKGROUNDIMAGE:<span style="color: #000000; font-weight: bold;">Class</span>;</pre></div></div>

<p>Let&#8217;s say that is done within a class named AssetsManager.  Then, internally, we actually have a class named &#8220;AssetsManager_BACKGROUNDIMAGE&#8221; created.  The name that comes after the underscore matches whatever you have given to that static member.</p>
<p>We can then write a generic handler function to grab the associated Bitmap image, given the asset name:</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
</pre></td><td class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> GetImage<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:Bitmap
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">name</span> = <span style="color: #0066CC;">name</span>.<span style="color: #0066CC;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">try</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> cls:<span style="color: #000000; font-weight: bold;">Class</span> = getDefinitionByName<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;AssetsManager_&quot;</span> + <span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #000000; font-weight: bold;">Class</span>;
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> cls<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as Bitmap;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">// ** else return a default 16x16 opaque white square bitmap **</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">16</span>,<span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></td></tr></table></div>

<p><strong>Line 3:</strong> This is optional, but it is a simple way to eliminate possible naming confusion.</p>
<p><strong>Line 4:</strong> Use a try-catch block, because getDefinitionByName() expects the class to exist, but it is possible that during development we have not embedded the assets yet, and this method is crafted to return a default 16&#215;16 opaque white square where the asset is missing.</p>
<p><strong>Line 6:</strong> Here it is, concatenating the helper class name, an underscore, and the given <code>name</code> parameter, we get the class name of the embedded bitmap asset.</p>
<p><strong>Line 7:</strong> If the class/asset exists, this line will be executed (instantiating and returning the requested Bitmap object), otherwise the try-catch block kicks in.</p>
<p>Example complete class code below:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package  
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Bitmap</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">BitmapData</span>;
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">utils</span>.<span style="color: #006600;">getDefinitionByName</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AssetsManager 
	<span style="color: #66cc66;">&#123;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// ** START EMBED **</span>
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/background.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 BACKGROUNDIMAGE:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/iconfileopen.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 ICONFILEOPEN:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
		<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/iconfileclose.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 ICONFILECLOSE:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
		<span style="color: #808080; font-style: italic;">// ** embed other assets as required **</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">// ** END EMBED **</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/**
		 * Returns a Bitmap display object identified by the specified name.
		 * @param	The name of the bitmap asset to return.  This name must match one of the 
		 * @return	A Bitmap display object.
		 */</span>
		<span style="color: #0066CC;">public</span> <span style="color: #0066CC;">static</span> <span style="color: #000000; font-weight: bold;">function</span> GetImage<span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">name</span>:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:Bitmap
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">name</span> = <span style="color: #0066CC;">name</span>.<span style="color: #0066CC;">toUpperCase</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #0066CC;">try</span>
			<span style="color: #66cc66;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">var</span> cls:<span style="color: #000000; font-weight: bold;">Class</span> = getDefinitionByName<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;AssetsManager_&quot;</span> + <span style="color: #0066CC;">name</span><span style="color: #66cc66;">&#41;</span> as <span style="color: #000000; font-weight: bold;">Class</span>;
				<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> cls<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as Bitmap;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #0066CC;">catch</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #808080; font-style: italic;">// ** else return a default 16x16 opaque white square bitmap **</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;">16</span>,<span style="color: #cc66cc;">16</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>The above makes it easy to add more assets later on, compared to just accessing the public static members directly.  What is more, if you are compiling a library of embedded images and distributing it as a SWC, this makes it so much easier to modify/update the library, and for other collaborators to use the assets.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/as3-referencing-embedded-assets-of-another-class-using-underscore/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Game Programming] Consider A Different Approach To Cards Shuffling</title>
		<link>http://www.ghostwire.com/blog/archives/game-programming-consider-a-different-approach-to-cards-shuffling/</link>
		<comments>http://www.ghostwire.com/blog/archives/game-programming-consider-a-different-approach-to-cards-shuffling/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 11:54:32 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Game Programming]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1864</guid>
		<description><![CDATA[Very commonly, computer programs (usually games) that have the need to simulate a shuffling of a deck of cards (or drawing a tile from a bag, etc.) will go the obvious way of putting the items in an array, and then randomize the order of the elements of the array. A common algorithm for doing [...]]]></description>
			<content:encoded><![CDATA[<p>Very commonly, computer programs (usually games) that have the need to simulate a shuffling of a deck of cards (or drawing a tile from a bag, etc.) will go the obvious way of putting the items in an array, and then randomize the order of the elements of the array.  A common algorithm for doing that is the<a href="http://en.wikipedia.org/wiki/Knuth_shuffle"> Fisher–Yates</a> shuffle (you can find a suitable implementation easily by googling).</p>
<p>The purpose of this post, however, is not to discuss &#8220;how&#8221; to shuffle arrays.  Rather, I would like to bring up the question of &#8220;why&#8221; (do it) in the first place.</p>
<p><span id="more-1864"></span>In the non-digital world, the shuffling of a deck of cards is mostly necessary given the circumstances &#8211; ie, for convenience.  In a card game, you shuffle the deck of cards to randomize the order of the cards, and players draw from the top (or bottom) of the deck in sequence.  Why do players draw from the top (or bottom) of the deck?  For practical reasons, of course.  Convenience.</p>
<p>Imagine a card game where the game designer decides that players must pick a card randomly from the deck each time they need to draw a card &#8211; the game will end up taking too long to play, drawing cards become tedious, and the game won&#8217;t be very popular.</p>
<p>In both methods of card drawing, the outcome is really the same &#8211; whether you (i) shuffle a deck of cards and then draw from the top of the deck sequentially, or (ii) leave a deck as it is and then randomly pick a card from the deck each time you need to draw a card, the probability of a particular card being drawn by a player is exactly the same.  Let&#8217;s take a look at a deck of 52 cards.  If you shuffle the deck rigorously, the chance of a card being positioned at the location it is shuffled into, and therefore being drawn at that particular position, is 1.92% (1/52).</p>
<p>Now, look at the other scenario.  Leave the deck as it is without shuffling.  When a player randomly picks a card from the deck, the probability of picking a particular card as the first card remains at 1.92% (1/52). What is the probability of a particular card to be drawn as the second card?  A common misconception is that with less cards left, the probability for subsequent cards are now skewed.  Not really.  Let&#8217;s look at the calculations.  First, for a card to be drawn as the second card, it must not be drawn as the first card &#8211; got that?  The chance of that happening is 98.08% (51/52).  Next, the chance of the card being drawn as the second card in the reduced deck of 51 cards is 1.96% (1/51).  The composite probability is&#8230; 51/52 x 1/51 = 1/52, which is still 1.92%!  You can go on to compute for the third card, which is 51/52 x 50/51 x 1/50 = 1/52, and so on.</p>
<p>Okay, we have established that the probability remains the same for both methods of card drawing.  So what?</p>
<p>Well, when it comes to programming, I would debate that it is unnecessary to shuffle a deck of cards.  Players no longer need the convenience here, so why not pick a card at random each time you need to draw a card?  This approach has a couple of advantages:</p>
<p>(i) Preempt cheating by memory peeking.  If you use a shuffled deck, you naturally store the sequence in memory, which means hackers can potentially look at the sequence.  If you generate a random number on demand, picking a card at random each time a card is to be drawn, nobody can have fore-knowledge of what is to come.</p>
<p>(ii) Fast.  You can jump right into a game session without expensive CPU overhead for shuffling arrays.  If you have a large deck, shuffling can be inefficient no matter which algorithm you use.  Instead of shuffling the deck, you just write the code to pick a card randomly from the remaining deck.  Hassle in the non-digital world, fast in the digital version.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// ActionScript 3.0</span>
<span style="color: #000000; font-weight: bold;">function</span> drawNext<span style="color: #66cc66;">&#40;</span>deck:<span style="color: #0066CC;">Array</span><span style="color: #66cc66;">&#41;</span>:<span style="color: #66cc66;">*</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> j:uint = deck.<span style="color: #0066CC;">length</span>;
	<span style="color: #000000; font-weight: bold;">var</span> r:uint = <span style="color: #0066CC;">Math</span>.<span style="color: #0066CC;">random</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">*</span> j;
	<span style="color: #000000; font-weight: bold;">var</span> c:<span style="color: #66cc66;">*</span> = deck<span style="color: #66cc66;">&#91;</span>r<span style="color: #66cc66;">&#93;</span>;
	deck.<span style="color: #0066CC;">splice</span><span style="color: #66cc66;">&#40;</span>r, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// removes item from array</span>
	<span style="color: #b1b100;">return</span> c;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Therefore, when translating a non-digital game into a digital one, take a step back and ponder over whether it is really necessary to implement the rules literally.  As long as the intended outcome (in this case the intended probability of each card being drawn at a certain position) is the same, it would probably be worthwhile exploring more efficient implementations.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/game-programming-consider-a-different-approach-to-cards-shuffling/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>FlashDevelop: Getting trace() Statements To Show In Output Panel</title>
		<link>http://www.ghostwire.com/blog/archives/flashdevelop-getting-trace-statements-to-show-in-output-panel/</link>
		<comments>http://www.ghostwire.com/blog/archives/flashdevelop-getting-trace-statements-to-show-in-output-panel/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 08:44:10 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[FlashDevelop]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1860</guid>
		<description><![CDATA[This is quite an obscure, little known, hidden-by-default feature, but the FlashDevelop IDE actually has a built-in Flash tracer. The plug-in is unfortunately not enabled by default, and new users of FlashDevelop often get frustrated wondering where to look for the output of their trace statements. To get the tracer to work: 1) Go to [...]]]></description>
			<content:encoded><![CDATA[<p>This is quite an obscure, little known, hidden-by-default feature, but the <a href="http://www.flashdevelop.org">FlashDevelop</a> IDE actually has a built-in Flash tracer.  The plug-in is unfortunately not enabled by default, and new users of FlashDevelop often get frustrated wondering where to look for the output of their trace statements.</p>
<p>To get the tracer to work:</p>
<p>1) Go to Tools -> Program Settings (F10).</p>
<p>2) In the Plugins list on the left of the dialog box, look for FlashLogViewer and click on it.</p>
<p>3) On the right panel, look for the &#8220;Start Tracking&#8221; property, click on the drop down box and select &#8220;OnBuildComplete&#8221; (it is set to &#8220;Manually&#8221; by default).</p>
<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/flashlogviewer.png" alt="" title="flashlogviewer" width="621" height="489" class="alignleft size-full wp-image-1861" /></p>
<p>The output of your trace statements are now shown in the Output Panel after you build your project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/flashdevelop-getting-trace-statements-to-show-in-output-panel/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[OSX] Goodbye, Spaces&#8230; Hello, Spark!</title>
		<link>http://www.ghostwire.com/blog/archives/osx-goodbye-spaces-hello-spark/</link>
		<comments>http://www.ghostwire.com/blog/archives/osx-goodbye-spaces-hello-spark/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 09:42:46 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[mac osx]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1827</guid>
		<description><![CDATA[This post may come across as blasphemous to ardent Mac fanatics, but I am hoping that OSX users who are in the same predicament as me may find it useful. I have finally disabled Spaces on Mac OSX. It&#8217;s a little painful to disable it, because I had considered it a very crucial feature, considering [...]]]></description>
			<content:encoded><![CDATA[<p>This post may come across as blasphemous to ardent Mac fanatics, but I am hoping that OSX users who are in the same predicament as me may find it useful.</p>
<p>I have finally disabled Spaces on Mac OSX.  It&#8217;s a little painful to disable it, because I had considered it a very crucial feature, considering that without it the desktop gets cluttered quickly with the way the Mac OS presents applications and their respective windows (all mixed together in one very confusing bucket).  However, the slide animation that occurs every time Spaces switches from one space to another has become really nauseating.</p>
<p>It was cool at first, but now it is painful to watch.</p>
<p>So much for Apple&#8217;s acclaimed emphasis on the &#8220;user experience&#8221;.  Does nobody in the UX team ever stop to think that not everyone likes gimmicky animation stuff for frequent tasks, and there should be an easy way to disable such animations?  Unfortunately, there is just no way to disable the animations &#8211; I hope to be proven wrong, but my searches have come up fruitless.  A <a href="http://www.google.com/search?q=mac+osx+disable+spaces+animation">quick google visit</a> shows there are other users who wish to get rid of the animation too (and apparently I am not the only one suffering from motion sickness, although most simply want to get rid of the animation just to save time, keeping multitasking slick and snappy).</p>
<p>So, now that I have disabled Spaces, what do I do now with the cluttered desktop?  I am currently solving the issue with a little AppleScript and implementation of keyboard shortcuts via <a href="http://www.shadowlab.org/Software/spark">Spark</a> &#8211; a free utility to create Hot Keys to launch applications and documents, execute AppleScript, etc.</p>
<p><span id="more-1827"></span>First, you can use simple AppleScript to hide all other applications except the one you are working on:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">tell application <span style="color: #ff0000;">&quot;Finder&quot;</span>
	<span style="color: #0066CC;">set</span> <span style="color: #0066CC;">visible</span> of every process whose <span style="color: #0066CC;">visible</span> is <span style="color: #000000; font-weight: bold;">true</span> <span style="color: #0066CC;">and</span> frontmost is <span style="color: #0066CC;">not</span> <span style="color: #000000; font-weight: bold;">true</span> to <span style="color: #000000; font-weight: bold;">false</span>
<span style="color: #0066CC;">end</span> tell</pre></div></div>

<p>If you are already using a Hot Key utility to execute other AppleScript, you already know the routine.  If not, you can download <a href="http://www.shadowlab.org/Software/spark">Spark</a>, launch it, and then assign the above AppleScript to a keyboard shortcut.<br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/SparkHideOthers.png" alt="" title="SparkHideOthers" width="621" height="550" class="alignleft size-full wp-image-1829" /></p>
<p>(click on the Shortcut input field and then type the keyboard shortcut to assign the Hot Key)</p>
<p>With the above, F1 has been assigned as the Hot Key &#8211; pressing F1 when any application has focus will hide all other windows except the currently active application (or in AppleScript&#8217;s terminology, &#8220;frontmost&#8221; application).</p>
<p>But that only got rid of the clutter, albeit momentarily (as the clutter builds up, I hit F1 again).</p>
<p>What about jumping around applications?  That was what Spaces allowed me to do, and now I need to replicate that functionality.  Luckily, it is easy enough to do that with Spark.  You can once again write AppleScript, such as the following:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">tell application <span style="color: #ff0000;">&quot;Finder&quot;</span>
	<span style="color: #0066CC;">set</span> <span style="color: #0066CC;">visible</span> of every process to <span style="color: #000000; font-weight: bold;">false</span>
<span style="color: #0066CC;">end</span> tell
&nbsp;
tell application <span style="color: #ff0000;">&quot;Xcode&quot;</span>
	activate
	<span style="color: #0066CC;">set</span> <span style="color: #0066CC;">visible</span> to <span style="color: #000000; font-weight: bold;">true</span>
<span style="color: #0066CC;">end</span> tell</pre></div></div>

<p>However, you don&#8217;t even need to do that &#8211; Spark allows you to assign Hot Keys to Applications, so let&#8217;s do that:</p>
<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/SparkApplicationLauncher.png" alt="" title="SparkApplicationLauncher" width="599" height="279" class="alignleft size-full wp-image-1830" /></p>
<p>As you can see, the above assigns Command-F1 to Xcode, and Command-F2 to Firefox.  With that set up, when you are in another application, hitting Command-F1 will jump to Xcode immediately.  If Xcode is not yet launched, it will automatically launch first.  Spark also provides the options for hiding all applications when your desired program is launched:<br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/SparkLauncherOptions.png" alt="" title="SparkLauncherOptions" width="611" height="368" class="alignleft size-full wp-image-1832" /></p>
<p>So, that is that.  A little manual work to assign frequently used applications to Hot Keys.  But at least it no longer gets dizzy working on Mac OSX now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/osx-goodbye-spaces-hello-spark/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>uiFrame: ActionScript 3.0 GroupBox</title>
		<link>http://www.ghostwire.com/blog/archives/uiframe-actionscript-3-0-groupbox/</link>
		<comments>http://www.ghostwire.com/blog/archives/uiframe-actionscript-3-0-groupbox/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 09:02:05 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Aspire UI]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Components]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1811</guid>
		<description><![CDATA[It is often overlooked, but the uiFrame component in the Aspire UI toolkit essentially has the same utility as the GroupBox in WPF (Windows Presentation Foundation). A GroupBox displays a border/frame around a group of controls, with or without a caption/title. This is typically done to provide visual feedback to end-users that a collection of [...]]]></description>
			<content:encoded><![CDATA[<p>It is often overlooked, but the <a href="http://www.ghostwire.com/aspireui/docs/usage/uiframe">uiFrame</a> component in the <a href="http://www.ghostwire.com/aspireui/">Aspire UI</a> toolkit essentially has the same utility as the GroupBox in WPF (Windows Presentation Foundation).</p>
<p>A GroupBox displays a border/frame around a group of controls, with or without a caption/title.  This is typically done to provide visual feedback to end-users that a collection of controls on a form is logically grouped.</p>
<p>When using the Aspire UI toolkit in ActionScript 3.0 projects, you can use the uiFrame component for the same results.</p>
<p><span id="more-1811"></span></p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// ActionScript 3.0</span>
<span style="color: #000000; font-weight: bold;">var</span> fruit0:uiCheckBox = <span style="color: #000000; font-weight: bold;">new</span> uiCheckBox<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Apple&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> fruit1:uiCheckBox = <span style="color: #000000; font-weight: bold;">new</span> uiCheckBox<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Banana&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">var</span> fruit2:uiCheckBox = <span style="color: #000000; font-weight: bold;">new</span> uiCheckBox<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Orange&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> fruitsBox:uiBox    = <span style="color: #000000; font-weight: bold;">new</span> uiBox<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
fruitsBox.<span style="color: #006600;">vertical</span>    = <span style="color: #000000; font-weight: bold;">true</span>;
fruitsBox.<span style="color: #006600;">spacing</span>    = <span style="color: #cc66cc;">4</span>;
&nbsp;
fruitsBox.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> uiText<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;You can choose one or more fruits!&quot;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
fruitsBox.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>fruit0<span style="color: #66cc66;">&#41;</span>;
fruitsBox.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>fruit1<span style="color: #66cc66;">&#41;</span>;
fruitsBox.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>fruit2<span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> frm:uiFrame = <span style="color: #000000; font-weight: bold;">new</span> uiFrame<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
frm.<span style="color: #006600;">content</span> = fruitsBox;
frm.<span style="color: #006600;">x</span> = <span style="color: #cc66cc;">10</span>;
frm.<span style="color: #006600;">y</span> = <span style="color: #cc66cc;">10</span>;
&nbsp;
frm.<span style="color: #006600;">title</span> = <span style="color: #000000; font-weight: bold;">new</span> uiText<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Fruits&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
addChild<span style="color: #66cc66;">&#40;</span>frm<span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/uiframe_xp.png" alt="" title="uiframe_xp" width="250" height="150" class="alignleft size-full wp-image-1813" /></p>
<p>Using the &#8220;graylic&#8221; theme, the result would be as follows:</p>
<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/uiframe_graylic.png" alt="" title="uiframe_graylic" width="223" height="153" class="alignleft size-full wp-image-1814" /></p>
<p>Notice that the caption (title) is left aligned by default.  You can adjust the alignment by specifying the <code>alignX</code> property:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">frm.<span style="color: #006600;">title</span> = <span style="color: #000000; font-weight: bold;">new</span> uiText<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;Fruits&quot;</span><span style="color: #66cc66;">&#41;</span>;
frm.<span style="color: #006600;">title</span>.<span style="color: #006600;">alignX</span> = <span style="color: #0066CC;">ALIGN</span>.<span style="color: #006600;">CENTER</span>;</pre></div></div>

<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/uiframe_xp_center.png" alt="" title="uiframe_xp_center" width="250" height="150" class="alignleft size-full wp-image-1815" /></p>
<p>Using the &#8220;classic&#8221; theme with background set to gray, the result would be as follows:</p>
<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/uiframe_classic.png" alt="" title="uiframe_classic" width="250" height="135" class="alignleft size-full wp-image-1817" /></p>
<p><!-- --><br />
<strong>Aspire UI Components</strong><br />
Aspire UI is a library of Actionscript 3.0 (AS3) classes for building flexible and lightweight UI elements in Adobe Flash applications. Key features of the components include easy skinning using PNG image files, automatic tab focus ordering, CSS text styles, and layout management.</p>
<p>This is a pure AS3 library with no dependency on the Flex framework.</p>
<p>For more information, please <a href="http://www.ghostwire.com/aspireui/">click here</a>.</p>
<p>You may experiment with the various features by <a href="http://www.ghostwire.com/aspireui/download">downloading the trial version</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/uiframe-actionscript-3-0-groupbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>uiColorPicker: Customizing The Colors Palette</title>
		<link>http://www.ghostwire.com/blog/archives/uicolorpicker-customizing-the-colors-palette/</link>
		<comments>http://www.ghostwire.com/blog/archives/uicolorpicker-customizing-the-colors-palette/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 07:08:06 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Aspire UI]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Components]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1784</guid>
		<description><![CDATA[In this post, we look at how the colors palette/swatch of the uiColorPicker control can be customized. By default, the component uses the following set of colors: We can define an alternative colors array for the popup palette: private static const COLORS_CONTINUOUS_TONE:Array = &#91; 0xCCFFFF, 0xCCCCFF, 0xCC99FF, 0xCC66FF, 0xCC33FF, 0xCC00FF, 0xFF00FF, 0xFF33FF, 0xFF66FF, 0xFF99FF, 0xFFCCFF, [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, we look at how the colors palette/swatch of the <a href="http://www.ghostwire.com/aspireui/docs/usage/uicolorpicker">uiColorPicker</a> control can be customized.</p>
<p><span id="more-1784"></span>By default, the component uses the following set of colors:<br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/uicolorpicker_dropshadow.png" alt="" title="uicolorpicker_dropshadow" width="295" height="250" class="alignleft size-full wp-image-1778" /></p>
<p><!-- --><br />
We can define an alternative <code>colors</code> array for the popup palette:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #0066CC;">static</span> const COLORS_CONTINUOUS_TONE:<span style="color: #0066CC;">Array</span> = <span style="color: #66cc66;">&#91;</span>
0xCCFFFF, 0xCCCCFF, 0xCC99FF, 0xCC66FF, 0xCC33FF, 0xCC00FF, 0xFF00FF, 0xFF33FF, 0xFF66FF, 0xFF99FF, 0xFFCCFF, 0xFFFFFF,
0xCCFFCC, 0xCCCCCC, 0xCC99CC, 0xCC66CC, 0xCC33CC, 0xCC00CC, 0xFF00CC, 0xFF33CC, 0xFF66CC, 0xFF99CC, 0xFFCCCC, 0xFFFFCC,
0xCCFF99, 0xCCCC99, 0xCC9999, 0xCC6699, 0xCC3399, 0xCC0099, 0xFF0099, 0xFF3399, 0xFF6699, 0xFF9999, 0xFFCC99, 0xFFFF99,
0xCCFF66, 0xCCCC66, 0xCC9966, 0xCC6666, 0xCC3366, 0xCC0066, 0xFF0066, 0xFF3366, 0xFF6666, 0xFF9966, 0xFFCC66, 0xFFFF66,
0xCCFF33, 0xCCCC33, 0xCC9933, 0xCC6633, 0xCC3333, 0xCC0033, 0xFF0033, 0xFF3333, 0xFF6633, 0xFF9933, 0xFFCC33, 0xFFFF33,
0xCCFF00, 0xCCCC00, 0xCC9900, 0xCC6600, 0xCC3300, 0xCC0000, 0xFF0000, 0xFF3300, 0xFF6600, 0xFF9900, 0xFFCC00, 0xFFFF00,
0x66FF00, 0x66CC00, 0x669900, 0x666600, 0x663300, 0x660000, 0x990000, 0x993300, 0x996600, 0x999900, 0x99CC00, 0x99FF00,
0x66FF33, 0x66CC33, 0x669933, 0x666633, 0x663333, 0x660033, 0x990033, 0x993333, 0x996633, 0x999933, 0x99CC33, 0x99FF33,
0x66FF66, 0x66CC66, 0x669966, 0x666666, 0x663366, 0x660066, 0x990066, 0x993366, 0x996666, 0x999966, 0x99CC66, 0x99FF66,
0x66FF99, 0x66CC99, 0x669999, 0x666699, 0x663399, 0x660099, 0x990099, 0x993399, 0x996699, 0x999999, 0x99CC99, 0x99FF99,
0x66FFCC, 0x66CCCC, 0x6699CC, 0x6666CC, 0x6633CC, 0x6600CC, 0x9900CC, 0x9933CC, 0x9966CC, 0x9999CC, 0x99CCCC, 0x99FFCC,
0x66FFFF, 0x66CCFF, 0x6699FF, 0x6666FF, 0x6633FF, 0x6600FF, 0x9900FF, 0x9933FF, 0x9966FF, 0x9999FF, 0x99CCFF, 0x99FFFF,
0x00FFFF, 0x00CCFF, 0x0099FF, 0x0066FF, 0x0033FF, 0x0000FF, 0x3300FF, 0x3333FF, 0x3366FF, 0x3399FF, 0x33CCFF, 0x33FFFF,
0x00FFCC, 0x00CCCC, 0x0099CC, 0x0066CC, 0x0033CC, 0x0000CC, 0x3300CC, 0x3333CC, 0x3366CC, 0x3399CC, 0x33CCCC, 0x33FFCC,
0x00FF99, 0x00CC99, 0x009999, 0x006699, 0x003399, 0x000099, 0x330099, 0x333399, 0x336699, 0x339999, 0x33CC99, 0x33FF99,
0x00FF33, 0x00CC33, 0x009933, 0x006633, 0x003333, 0x000033, 0x330033, 0x333333, 0x336633, 0x339933, 0x33CC33, 0x33FF33,
0x00FF00, 0x00CC00, 0x009900, 0x006600, 0x003300, 0x000000, 0x330000, 0x333300, 0x336600, 0x339900, 0x33CC00, 0x33FF00,
<span style="color: #66cc66;">&#93;</span>;</pre></div></div>

<p><!-- --><br />
And then assign the <code>colors</code> array as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> myColorPicker:uiColorPicker = <span style="color: #000000; font-weight: bold;">new</span> uiColorPicker<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
myColorPicker.<span style="color: #006600;">colors</span> = COLORS_CONTINUOUS_TONE;</pre></div></div>

<p><a href="http://www.ghostwire.com/blog/wp-content/uploads/uicolorpicker_continuous_tone_palette.png"><img src="http://www.ghostwire.com/blog/wp-content/uploads/uicolorpicker_continuous_tone_palette.png" alt="" title="uicolorpicker_continuous_tone_palette" width="250" height="230" class="alignleft size-full wp-image-1785" /></a></p>
<p><!-- --><br />
<strong>Aspire UI Components</strong><br />
Aspire UI is a library of Actionscript 3.0 (AS3) classes for building flexible and lightweight UI elements in Adobe Flash applications. Key features of the components include easy skinning using PNG image files, automatic tab focus ordering, CSS text styles, and layout management.</p>
<p>This is a pure AS3 library with no dependency on the Flex framework.</p>
<p>For more information, please <a href="http://www.ghostwire.com/aspireui/">click here</a>.</p>
<p>You may experiment with the various features by <a href="http://www.ghostwire.com/aspireui/download">downloading the trial version</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/uicolorpicker-customizing-the-colors-palette/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>uiColorPicker: Adding Drop Shadow To Popup Palette</title>
		<link>http://www.ghostwire.com/blog/archives/uicolorpicker-adding-drop-shadow-to-popup-palette/</link>
		<comments>http://www.ghostwire.com/blog/archives/uicolorpicker-adding-drop-shadow-to-popup-palette/#comments</comments>
		<pubDate>Sat, 27 Mar 2010 08:00:11 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Aspire UI]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Flash Components]]></category>
		<category><![CDATA[Skinning]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1776</guid>
		<description><![CDATA[The uiColorPicker control displays a single rectangular button that brings up a palette of pre-defined set of colors (also known as a color swatch). By default, this popup does not cast a drop shadow, as shown in the screenshot below: In this post, we look at how to get the popup to cast a drop [...]]]></description>
			<content:encoded><![CDATA[<p>The uiColorPicker control displays a single rectangular button that brings up a palette of pre-defined set of colors (also known as a color swatch).  By default, this popup does not cast a drop shadow, as shown in the screenshot below:<br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/uicolopicker_example.png" alt="" title="uicolopicker_example" width="295" height="230" class="alignleft size-full wp-image-1767" /></p>
<p>In this post, we look at how to get the popup to cast a drop shadow, by simply adding some directives in the &#8220;rules.xml&#8221; of the theme you are using.</p>
<p><span id="more-1776"></span>The uiColorPicker component uses three skin assets:<br />
ColorPicker.png<br />
ColorPickerFrame.png<br />
ColorPickerInput.png</p>
<p>The ColorPicker.png is the image that will be used to render the rectangular button.  This skin asset is mandatory.  If it is missing, the component will not show.</p>
<p>The ColorPickerInput.png is optional, affecting the look of the text input field in the popup palette.  This skin is usually pointed to the same skin asset used by the uiTextInput component:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColorPickerInput</span> <span style="color: #000066;">clone</span>=<span style="color: #ff0000;">&quot;TextInput&quot;</span> <span style="color: #000066;">prefs</span>=<span style="color: #ff0000;">&quot;width|74|focusPadding|1|padding|0&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>The ColorPickerFrame.png is the image that will be used to render the background of the popup palette.  You can specify styling directives for the popup, such as padding, in the &#8220;rules.xml&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColorPickerFrame</span> <span style="color: #000066;">edge</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">prefs</span>=<span style="color: #ff0000;">&quot;padding|3&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>Therefore, to get the popup to cast a drop shadow, all you need to do is to add the directive as such:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ColorPickerFrame</span> <span style="color: #000066;">edge</span>=<span style="color: #ff0000;">&quot;2&quot;</span> <span style="color: #000066;">prefs</span>=<span style="color: #ff0000;">&quot;padding|3|background|shadow,0x000000&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<p>The result will be as shown below:<br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/uicolorpicker_dropshadow.png" alt="" title="uicolorpicker_dropshadow" width="295" height="250" class="alignleft size-full wp-image-1778" /></p>
<p><!-- --><br />
<strong>Aspire UI Components</strong><br />
Aspire UI is a library of Actionscript 3.0 (AS3) classes for building flexible and lightweight UI elements in Adobe Flash applications. Key features of the components include easy skinning using PNG image files, automatic tab focus ordering, CSS text styles, and layout management.</p>
<p>This is a pure AS3 library with no dependency on the Flex framework.</p>
<p>For more information, please <a href="http://www.ghostwire.com/aspireui/">click here</a>.</p>
<p>You may experiment with the various features by <a href="http://www.ghostwire.com/aspireui/download">downloading the trial version</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/uicolorpicker-adding-drop-shadow-to-popup-palette/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using AspireUI Components with MDM Zinc 3.0</title>
		<link>http://www.ghostwire.com/blog/archives/using-aspireui-components-with-mdm-zinc-3-0/</link>
		<comments>http://www.ghostwire.com/blog/archives/using-aspireui-components-with-mdm-zinc-3-0/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 22:51:42 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Aspire UI]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Flash Components]]></category>
		<category><![CDATA[MDM]]></category>
		<category><![CDATA[Zinc]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1714</guid>
		<description><![CDATA[MDM Zinc™ 3.0 is a feature-rich Rapid Application Development Tool for turning SWFs into stunning commercial cross-platform desktop applications, screensavers, widgets, CD roms, DVD’s, kiosks and more. The AspireUI AS3 library uses PNG image files for component skinning, and this ease of skinning is a good fit for Zinc™ 3.0 projects, especially if you would [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.multidmedia.com">MDM Zinc™ 3.0</a> is a feature-rich Rapid Application Development Tool for turning SWFs into stunning commercial cross-platform desktop applications, screensavers, widgets, CD roms, DVD’s, kiosks and more. The <a href="http://www.ghostwire.com/aspireui/">AspireUI AS3 library</a> uses PNG image files for component skinning, and this ease of skinning is a good fit for Zinc™ 3.0 projects, especially if you would like to create applications that look like native desktop applications.  The toolkit currently comes with four component themes &#8211; &#8220;classic&#8221;, &#8220;xp&#8221;, &#8220;vista&#8221; and &#8220;graylic&#8221;.  The first three aforementioned themes are Windows OS lookalike themes.  </p>
<p>In this short tutorial, we will look at how you can use the AspireUI library in Zinc™ 3.0 projects, and how you can easily swap component themes by simply changing one line of code.</p>
<p><span id="more-1714"></span></p>
<p><strong>mdm.Application.path</strong><br />
When using Zinc™ 3.0, it is important to remember that relative paths to external assets do not work well.  To ensure that your Zinc™ 3.0 compiled applications work as expected, you should always prefix paths with <code>mdm.Application.path</code> so that the application knows where to look for external assets (to be loaded during run-time).</p>
<p>When using the AspireUI library in a normal Flash AS3 project, we would usually initialize the uiSkins manager as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">uiSkins.<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;default&quot;</span>, <span style="color: #ff0000;">&quot;assets/skins/&quot;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// use &quot;default&quot; theme folder from the relative path &quot;assets/skins/&quot;</span></pre></div></div>

<p>When coding for Zinc™ 3.0 projects, the following will be used:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">uiSkins.<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;default&quot;</span>, mdm.<span style="color: #006600;">Application</span>.<span style="color: #006600;">path</span> + <span style="color: #ff0000;">&quot;assets/skins/&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Likewise, in order for the uiImage class to work properly in Zinc™ 3.0 applications, the following path must be set:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">uiImage.<span style="color: #006600;">path</span> = mdm.<span style="color: #006600;">Application</span>.<span style="color: #006600;">path</span> + <span style="color: #ff0000;">&quot;assets/images/&quot;</span>;</pre></div></div>

<p>That will make it possible for <code>uiImage</code> instances to load from the &#8220;assets/images/&#8221; folder.  For example, the following will create a uiImage instance with image source loaded from &#8220;assets/images/icon.png&#8221;:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> imgIcon:uiImage = <span style="color: #000000; font-weight: bold;">new</span> uiImage<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;icon.png&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p><strong>MyZincApp Class</strong><br />
Let&#8217;s now look at a simple <code>MyZincApp</code> class:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">package
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #0066CC;">import</span> flash.<span style="color: #006600;">display</span>.<span style="color: #006600;">Sprite</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> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">containers</span>.<span style="color: #006600;">uiScrollPane</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">containers</span>.<span style="color: #006600;">uiWindow</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">controls</span>.<span style="color: #006600;">uiImage</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">enums</span>.<span style="color: #006600;">WINDOW</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">managers</span>.<span style="color: #006600;">uiCursors</span>;
	<span style="color: #0066CC;">import</span> com.<span style="color: #006600;">ghostwire</span>.<span style="color: #006600;">ui</span>.<span style="color: #006600;">managers</span>.<span style="color: #006600;">uiSkins</span>;
	<span style="color: #0066CC;">import</span> mdm.<span style="color: #66cc66;">*</span>;
&nbsp;
	<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyZincApp <span style="color: #0066CC;">extends</span> Sprite 
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">public</span> <span style="color: #000000; font-weight: bold;">function</span> MyZincApp<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: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span> init<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #b1b100;">else</span> addEventListener<span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">ADDED_TO_STAGE</span>, init<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> init<span style="color: #66cc66;">&#40;</span>evt:Event = <span style="color: #000000; font-weight: bold;">null</span><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;">ADDED_TO_STAGE</span>, init<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// in order to work with Zinc, we need to specify</span>
			<span style="color: #808080; font-style: italic;">// correct paths to external assets</span>
			uiSkins.<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;default&quot;</span>, mdm.<span style="color: #006600;">Application</span>.<span style="color: #006600;">path</span> + <span style="color: #ff0000;">&quot;assets/skins/&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			uiImage.<span style="color: #006600;">path</span> = mdm.<span style="color: #006600;">Application</span>.<span style="color: #006600;">path</span> + <span style="color: #ff0000;">&quot;assets/images/&quot;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// listen to uiSkins manager to get notified when</span>
			<span style="color: #808080; font-style: italic;">// theme assets have been fully loaded</span>
			uiSkins.<span style="color: #006600;">manager</span>.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">INIT</span>, main<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> main<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// ** initializes uiCursors class **</span>
			uiCursors.<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// ** initializes uiWindow class **</span>
			uiWindow.<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">stage</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// ** img window **</span>
			<span style="color: #000000; font-weight: bold;">var</span> img:uiImage = <span style="color: #000000; font-weight: bold;">new</span> uiImage<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;flower.jpg&quot;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> imgsp:uiScrollPane	= <span style="color: #000000; font-weight: bold;">new</span> uiScrollPane<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			imgsp.<span style="color: #006600;">fillX</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			imgsp.<span style="color: #006600;">fillY</span> = <span style="color: #000000; font-weight: bold;">true</span>;
			imgsp.<span style="color: #006600;">content</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>img<span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> imgWin:uiWindow	= <span style="color: #000000; font-weight: bold;">new</span> uiWindow<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			imgWin.<span style="color: #006600;">title</span>		= <span style="color: #ff0000;">&quot;flower.jpg&quot;</span>;
			imgWin.<span style="color: #006600;">content</span>.<span style="color: #006600;">addChild</span><span style="color: #66cc66;">&#40;</span>imgsp<span style="color: #66cc66;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">// ** end img window **</span>
&nbsp;
			imgWin.<span style="color: #006600;">open</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>After compiling the above class, you will get a SWF that you can then run through the Zinc Builder software to create a desktop application (for Windows, Mac or Linux).  If you run the compiled Zinc application, you will see something like the following:<br />
<a href="http://www.ghostwire.com/blog/wp-content/uploads/MyZincAppXP.png"><img src="http://www.ghostwire.com/blog/wp-content/uploads/MyZincAppXP.png" alt="" title="MyZincAppXP" width="606" height="260" class="alignleft size-full wp-image-1716" /></a></p>
<p><strong>Changing Theme I</strong><br />
Now, let&#8217;s see how we can easily change the component theme.  The themes are stored in their respective folders in the &#8220;assets/skins/&#8221; folder.  By changing one line of code, we can switch to using another theme:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;">uiSkins.<span style="color: #006600;">initialize</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;vista&quot;</span>, mdm.<span style="color: #006600;">Application</span>.<span style="color: #006600;">path</span> + <span style="color: #ff0000;">&quot;assets/skins/&quot;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>With that, we will now use the &#8220;vista&#8221; theme instead of the default &#8220;xp&#8221; theme.  After re-compiling the SWF and running the new SWF through the Zinc Builder software, we will see something like the following:<br />
<a href="http://www.ghostwire.com/blog/wp-content/uploads/MyZincAppVista.png"><img src="http://www.ghostwire.com/blog/wp-content/uploads/MyZincAppVista.png" alt="" title="MyZincAppVista" width="606" height="260" class="alignleft size-full wp-image-1717" /></a></p>
<p><strong>Changing Theme II</strong><br />
Next, we look at how we can change the theme without even changing any code, without re-compiling the SWF, and without re-building the Zinc application. We do this by swapping the contents of the &#8220;default&#8221; folder with the contents from the &#8220;classic&#8221; folder, and then run the Zinc application without re-building.  You will see something like the following:<br />
<a href="http://www.ghostwire.com/blog/wp-content/uploads/MyZincAppClassic.png"><img src="http://www.ghostwire.com/blog/wp-content/uploads/MyZincAppClassic.png" alt="" title="MyZincAppClassic" width="606" height="260" class="alignleft size-full wp-image-1718" /></a></p>
<p>The above is possible because by default, the AspireUI library uses run-time skin assets (and is what we are using in this introductory tutorial).  This means that by changing the PNG image assets in the &#8220;assets/skins/default&#8221; folder, you will change the look of your Zinc application.  The library also supports the option to embed the skin assets within the SWF, if so desired.  There is also a tool to package all the skin assets within a folder into one compressed binary file.</p>
<p><strong>Aspire UI Components</strong><br />
Aspire UI is a library of Actionscript 3.0 (AS3) classes for building flexible and lightweight UI elements in Adobe Flash applications. Key features of the components include easy skinning using PNG image files, automatic tab focus ordering, CSS text styles, and layout management. This is a pure AS3 library with no dependency on the Flex framework. You may experiment with the various features by <a href="http://www.ghostwire.com/aspireui/download">downloading the trial version</a>.</p>
<p><strong>MDM Zinc™ 3.0</strong><br />
MDM Zinc™ 3.0, available for Windows and Mac OSX, is the only development tool in its class to offer X-Platform, X-Compile™ to Windows, Mac OSX &#038; Linux Systems. Rapid Application Development for Adobe® Flash® and Flex®.  You may download MDM Zinc™ 3.0 Builder for Windows &#038; Mac OSX at:<br />
<a href="http://www.multidmedia.com/software/zinc/download/">http://www.multidmedia.com/software/zinc/download/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/using-aspireui-components-with-mdm-zinc-3-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Small Caps Fonts</title>
		<link>http://www.ghostwire.com/blog/archives/small-caps-fonts/</link>
		<comments>http://www.ghostwire.com/blog/archives/small-caps-fonts/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 11:29:44 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Others]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Fonts]]></category>
		<category><![CDATA[Typography]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1694</guid>
		<description><![CDATA[In typography, &#8220;small caps&#8221; refer to uppercase (capital) characters used in-lieu of lowercase (small) characters, where these uppercase characters are set at the same height as the lowercase characters. Small caps are typically used for titles, headlines, column headings, etc. They are also good for any text that you would usually use all capitals. This [...]]]></description>
			<content:encoded><![CDATA[<p>In typography, &#8220;small caps&#8221; refer to uppercase (capital) characters used in-lieu of lowercase (small) characters, where these uppercase characters are set at the same height as the lowercase characters.</p>
<p>Small caps are typically used for titles, headlines, column headings, etc.  They are also good for any text that you would usually use all capitals.  This is because the use of small caps makes the run of capital letters seem less jarring, and would also often require less space than all caps.</p>
<p>While many word processors and text formatting systems include an option to format text in small caps (which leaves uppercase letters as they are but converts lowercase letters to small caps), this is a feature that is lacking in most graphics editing software.</p>
<p>Some fonts have inherent small caps, ie they use smaller capital letters in place of the lowercase characters.  These fonts are useful when you wish to use small caps to bring distinction to your designs.</p>
<p>Here are some fonts with inherent small caps:</p>
<p><span id="more-1694"></span>The sample text used is:<br />
&#8220;The Quick Brown Fox Jumps Over The Lazy Fox&#8221;</p>
<ul>
<p><!-- --></p>
<li><strong>Berlin Small Caps</strong><br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/smallcaps_r16_c6.png" alt="Berlin Small Caps" title="Berlin Small Caps" width="317" height="33" class="alignleft size-full wp-image-1703" /></li>
</li>
<p><!-- --></p>
<li><strong>Copperplate Gothic Bold</strong><br />
<img class="size-full wp-image-1695 alignleft" title="Copperplate Gothic Bold" src="http://www.ghostwire.com/blog/wp-content/uploads/smallcaps_r2_c2.png" alt="Copperplate Gothic Bold" width="439" height="30" />
</li>
<p><!-- --></p>
<li><strong>Copperplate Gothic Light</strong><br />
<img class="alignleft size-full wp-image-1696" title="Copperplate Gothic Light" src="http://www.ghostwire.com/blog/wp-content/uploads/smallcaps_r4_c2.png" alt="Copperplate Gothic Light" width="424" height="29" />
</li>
<p><!-- --></p>
<li><strong>Lithos Pro Regular</strong><br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/smallcaps_r6_c4.png" alt="Lithos Pro Regular" title="Lithos Pro Regular" width="434" height="29" class="alignleft size-full wp-image-1698" />
</li>
<p><!-- --></p>
<li><strong>Orator Std</strong><br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/smallcaps_r8_c3.png" alt="Orator Std" title="Orator Std" width="457" height="28" class="alignleft size-full wp-image-1699" />
</li>
<p><!-- --></p>
<li><strong>Trajan Pro</strong><br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/smallcaps_r10_c5.png" alt="Trajan Pro" title="Trajan Pro" width="456" height="33" class="alignleft size-full wp-image-1700" />
</li>
<p><!-- --></p>
<li><strong>Pericles</strong><br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/smallcaps_r12_c8.png" alt="Pericles" title="Pericles" width="436" height="32" class="alignleft size-full wp-image-1701" />
</li>
<p><!-- --></p>
<li><strong>Pericles Light</strong><br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/smallcaps_r14_c7.png" alt="Pericles Light" title="Pericles Light" width="427" height="32" class="alignleft size-full wp-image-1702" /></p>
</ul>
<p><!-- --><br />
Please feel free to leave a comment to mention any other small caps font(s) not listed above.</p>
<p>Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/small-caps-fonts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[AS3] Serializing A Bundle Of Bitmaps As Data Objects</title>
		<link>http://www.ghostwire.com/blog/archives/as3-serializing-a-bundle-of-bitmaps-as-data-objects/</link>
		<comments>http://www.ghostwire.com/blog/archives/as3-serializing-a-bundle-of-bitmaps-as-data-objects/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 14:31:19 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash AS3]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[ByteArray]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1601</guid>
		<description><![CDATA[This post is a supplement to &#8220;Serializing Bitmaps (Storing BitmapData As Raw Binary/ByteArray)&#8221;. In that article, we looked at how to convert BitmapData to a ByteArray, save that ByteArray, and re-construct the BitmapData from the saved ByteArray. It is important to note that the technique saves the ByteArray &#8220;as is&#8221; in a flat binary file [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a supplement to <a href="http://www.ghostwire.com/blog/archives/as3-serializing-bitmaps-storing-bitmapdata-as-raw-binarybytearray/">&#8220;Serializing Bitmaps (Storing BitmapData As Raw Binary/ByteArray)&#8221;</a>. In that article, we looked at how to convert <code>BitmapData</code> to a <code>ByteArray</code>, save that <code>ByteArray</code>, and re-construct the <code>BitmapData</code> from the saved <code>ByteArray</code>.</p>
<p>It is important to note that the technique saves the <code>ByteArray</code> &#8220;as is&#8221; in a flat binary file without any header or any block of metadata &#8211; this means that the file will in itself not be able to communicate its data structure and therefore, proper usage of the data requires prior knowledge of how the data has been packed (we used the first four bytes for storing the value of the <code>width</code> of the image).  As a result, that method may be deemed as an &#8220;unorthodox&#8221; hack and unsuitable in team development.</p>
<p>In this post, we look at how you can employ the same basic idea while making the saved data more &#8220;consumable&#8221; by other developers.</p>
<p><span id="more-1601"></span><br />
<strong>Action Message Format (AMF)</strong><br />
ByteArray objects store ActionScript objects using the AMF format.  So instead of saving the binary bitmap data in raw form in the way we described previously, we will put the serialized data in an <code>Object</code> and write that object to a <code>ByteArray</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// assume you have Bitmap object &quot;bitmapImage&quot; you want to save</span>
&nbsp;
<span style="color: #808080; font-style: italic;">// convert the BitmapData to ByteArray</span>
<span style="color: #808080; font-style: italic;">// this time, do not pack any other data in the same ByteArray object</span>
<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #0066CC;">data</span>.<span style="color: #006600;">writeBytes</span><span style="color: #66cc66;">&#40;</span>bitmapImage.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">getPixels</span><span style="color: #66cc66;">&#40;</span>bitmapImage.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">rect</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// create a new data object</span>
<span style="color: #000000; font-weight: bold;">var</span> bmObj:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
bmObj.<span style="color: #0066CC;">width</span> = bitmapImage.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">width</span>;
bmObj.<span style="color: #0066CC;">height</span> = bitmapImage.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">height</span>;
bmObj.<span style="color: #0066CC;">data</span> = <span style="color: #0066CC;">data</span>;
&nbsp;
<span style="color: #808080; font-style: italic;">// create a new ByteArray object for saving</span>
<span style="color: #000000; font-weight: bold;">var</span> bytes:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
bytes.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>bmObj<span style="color: #66cc66;">&#41;</span>;
bytes.<span style="color: #006600;">compress</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>So that does it &#8211; you can now save the binary data normally (by posting it to a server script, via AIR local filesystem API, via SharedObject, via FP10 FileReference, etc.).  Although we are still saving our data in a flat binary file, the difference here is that developers consuming the data only need to know that they must read in an <code>Object</code> &#8211; they do not need to have the low-level knowledge of how exactly the data is packed.</p>
<p><!-- --><br />
<strong>ByteArray To BitmapData</strong><br />
Let&#8217;s look at how the binary data can now be consumed in an application.</p>
<p>First, load the file as normal:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> ldr:URLLoader	= <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
ldr.<span style="color: #006600;">dataFormat</span>	= URLLoaderDataFormat.<span style="color: #006600;">BINARY</span>; <span style="color: #808080; font-style: italic;">// ** make sure you do this **</span>
ldr.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, on_fileLoad<span style="color: #66cc66;">&#41;</span>;
ldr.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>IOErrorEvent.<span style="color: #006600;">IO_ERROR</span>, on_fileLoadError<span style="color: #66cc66;">&#41;</span>;
ldr.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>pathToBitmapDataFile<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>Process the loaded data:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_fileLoad<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">type</span> == Event.<span style="color: #006600;">COMPLETE</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> bytes:ByteArray = URLLoader<span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">data</span> as ByteArray;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>bytes<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">try</span>
			<span style="color: #66cc66;">&#123;</span>
				bytes.<span style="color: #006600;">uncompress</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #808080; font-style: italic;">// bytes is now the uncompressed byte array</span>
			<span style="color: #808080; font-style: italic;">// ... process bytes ...</span>
			<span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> = bytes.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// obj now has the properties &quot;width&quot;, &quot;height&quot; and &quot;data&quot; as saved previously</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> bmd:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>obj.<span style="color: #0066CC;">width</span>, obj.<span style="color: #0066CC;">height</span>, <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 32 bit transparent bitmap</span>
			bmd.<span style="color: #006600;">setPixels</span><span style="color: #66cc66;">&#40;</span>bmd.<span style="color: #006600;">rect</span>, obj.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #000000; font-weight: bold;">var</span> bm:Bitmap = <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd<span style="color: #66cc66;">&#41;</span>;
			addChild<span style="color: #66cc66;">&#40;</span>bm<span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p><!-- --><br />
<strong>Bundle of Bitmaps</strong><br />
What if you have multiple images you want to save and use later?  You can consider serializing the bitmaps and store them together in a single binary file.  To do that, we will give each image a unique id (such as the path of the image file if you are attempting to load and serialize external image files), store the serialized data in a hash, write that hash to a ByteArray, and then write that ByteArray to file.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// for storing the serialized images</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imgLibrary:<span style="color: #0066CC;">Object</span> = <span style="color: #66cc66;">&#123;</span> <span style="color: #66cc66;">&#125;</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> saveImage<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">String</span>, image:Bitmap<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>id == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">||</span> id == <span style="color: #ff0000;">&quot;&quot;</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>image == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		imgLibrary<span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span> = <span style="color: #000000; font-weight: bold;">null</span>; <span style="color: #808080; font-style: italic;">// ** remove previously stored data **</span>
		<span style="color: #b1b100;">return</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #0066CC;">data</span>:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #0066CC;">data</span>.<span style="color: #006600;">writeBytes</span><span style="color: #66cc66;">&#40;</span>image.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">getPixels</span><span style="color: #66cc66;">&#40;</span>image.<span style="color: #006600;">bitmapData</span>.<span style="color: #006600;">rect</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
	<span style="color: #808080; font-style: italic;">// create a new data object</span>
	<span style="color: #000000; font-weight: bold;">var</span> bmObj:<span style="color: #0066CC;">Object</span> = <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #0066CC;">Object</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	bmObj.<span style="color: #0066CC;">width</span> = image.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">width</span>;
	bmObj.<span style="color: #0066CC;">height</span> = image.<span style="color: #006600;">bitmapData</span>.<span style="color: #0066CC;">height</span>;
	bmObj.<span style="color: #0066CC;">data</span> = <span style="color: #0066CC;">data</span>;
&nbsp;
	imgLibrary<span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span> = bmObj; <span style="color: #808080; font-style: italic;">// ** will overwrite previously stored data **</span>
<span style="color: #66cc66;">&#125;</span>
&nbsp;
saveImage<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;iconA&quot;</span>, imageIconA<span style="color: #66cc66;">&#41;</span>;
saveImage<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;iconB&quot;</span>, imageIconB<span style="color: #66cc66;">&#41;</span>;
saveImage<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;iconC&quot;</span>, imageIconC<span style="color: #66cc66;">&#41;</span>;
<span style="color: #808080; font-style: italic;">// imgLibrary now contains three data objects each representing an image</span></pre></div></div>

<p>Now, write imgLibrary to file:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// ** must target Flash Player version 10+ **</span>
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_buttonClick<span style="color: #66cc66;">&#40;</span>evt:MouseEvent<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> bytes:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> ByteArray<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	bytes.<span style="color: #006600;">writeObject</span><span style="color: #66cc66;">&#40;</span>imgLibrary<span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// store width of image</span>
	bytes.<span style="color: #006600;">compress</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">new</span> FileReference<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">save</span><span style="color: #66cc66;">&#40;</span>bytes, <span style="color: #ff0000;">&quot;image.bmd&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// default name &quot;image.bmd&quot;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>In another application, we load the saved binary file as usual:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> ldr:URLLoader	= <span style="color: #000000; font-weight: bold;">new</span> URLLoader<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
ldr.<span style="color: #006600;">dataFormat</span>	= URLLoaderDataFormat.<span style="color: #006600;">BINARY</span>; <span style="color: #808080; font-style: italic;">// ** make sure you do this **</span>
ldr.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">COMPLETE</span>, on_fileLoad<span style="color: #66cc66;">&#41;</span>;
ldr.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>IOErrorEvent.<span style="color: #006600;">IO_ERROR</span>, on_fileLoadError<span style="color: #66cc66;">&#41;</span>;
ldr.<span style="color: #0066CC;">load</span><span style="color: #66cc66;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> URLRequest<span style="color: #66cc66;">&#40;</span>pathToFile<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</pre></div></div>

<p>And process and use the loaded binary data as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imgLibrary:<span style="color: #0066CC;">Object</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> on_fileLoad<span style="color: #66cc66;">&#40;</span>evt:Event<span style="color: #66cc66;">&#41;</span>:<span style="color: #0066CC;">void</span>
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">type</span> == Event.<span style="color: #006600;">COMPLETE</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">var</span> bytes:ByteArray = URLLoader<span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">target</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #0066CC;">data</span> as ByteArray;
		<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>bytes<span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #0066CC;">try</span>
			<span style="color: #66cc66;">&#123;</span>
				bytes.<span style="color: #006600;">uncompress</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
			<span style="color: #66cc66;">&#123;</span>
			<span style="color: #66cc66;">&#125;</span>
			<span style="color: #808080; font-style: italic;">// bytes is now the uncompressed byte array</span>
			<span style="color: #808080; font-style: italic;">// ... process bytes ...</span>
			imgLibrary = bytes.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
			<span style="color: #808080; font-style: italic;">// imgLibrary is now initialized and contains data objects each representing a bitmap image</span>
		<span style="color: #66cc66;">&#125;</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>After populating the imgLibrary hash, you can use a method like the one below to query it:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getImage<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:Bitmap
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>id == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">||</span> id == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">||</span> imgLibrary == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">||</span> imgLibrary<span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #0066CC;">Object</span> = imgLibrary<span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span>;
	<span style="color: #0066CC;">try</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// obj now has the properties &quot;width&quot;, &quot;height&quot; and &quot;data&quot; as saved previously</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> bmd:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>obj.<span style="color: #0066CC;">width</span>, obj.<span style="color: #0066CC;">height</span>, <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 32 bit transparent bitmap</span>
		bmd.<span style="color: #006600;">setPixels</span><span style="color: #66cc66;">&#40;</span>bmd.<span style="color: #006600;">rect</span>, obj.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
 		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd<span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;
getImage<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">&quot;iconA&quot;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// returns a Bitmap with BitmapData constructed from saved byte array</span></pre></div></div>

<p>The <code>getImage()</code> method can also be improved such that the <code>ByteArray-to-BitmapData</code> conversion is only done once per image:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> getImage<span style="color: #66cc66;">&#40;</span>id:<span style="color: #0066CC;">String</span><span style="color: #66cc66;">&#41;</span>:Bitmap
<span style="color: #66cc66;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>id == <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #66cc66;">||</span> id == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">||</span> imgLibrary == <span style="color: #000000; font-weight: bold;">null</span> <span style="color: #66cc66;">||</span> imgLibrary<span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span> == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">var</span> obj:<span style="color: #66cc66;">*</span> = imgLibrary<span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span>;
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>obj is BitmapData<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>BitmapData<span style="color: #66cc66;">&#40;</span>obj<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
&nbsp;
	<span style="color: #0066CC;">try</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #808080; font-style: italic;">// obj now has the properties &quot;width&quot;, &quot;height&quot; and &quot;data&quot; as saved previously</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">var</span> bmd:BitmapData = <span style="color: #000000; font-weight: bold;">new</span> BitmapData<span style="color: #66cc66;">&#40;</span>obj.<span style="color: #0066CC;">width</span>, obj.<span style="color: #0066CC;">height</span>, <span style="color: #000000; font-weight: bold;">true</span>, <span style="color: #cc66cc;">0</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #808080; font-style: italic;">// 32 bit transparent bitmap</span>
		bmd.<span style="color: #006600;">setPixels</span><span style="color: #66cc66;">&#40;</span>bmd.<span style="color: #006600;">rect</span>, obj.<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
		imgLibrary<span style="color: #66cc66;">&#91;</span>id<span style="color: #66cc66;">&#93;</span> = bmd;
&nbsp;
 		<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">new</span> Bitmap<span style="color: #66cc66;">&#40;</span>bmd.<span style="color: #006600;">clone</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>Note: If you are confident that the <code>BitmapData</code> is not going to be modified by instances, remove the <code>clone()</code> calls above &#8211; it will save memory since that means all <code>Bitmap</code> instances with the same <code>id</code> will be using the exact same <code>BitmapData</code>.</p>
<p><!-- --><br />
<strong>Embedding Image Asset(s)</strong><br />
After you have saved the binary file, remember that you are not limited to using it only as an external resource &#8211; you can also embed the file into your SWF:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">// ActionScript 3.0</span>
<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/images/icons.bin&quot;</span>, mimeType=<span style="color: #ff0000;">&quot;application/octet-stream&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 iconsBundle:<span style="color: #000000; font-weight: bold;">Class</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">var</span> imgLibrary:<span style="color: #0066CC;">Object</span>;
&nbsp;
<span style="color: #0066CC;">private</span> <span style="color: #000000; font-weight: bold;">function</span> initIcons<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> bytes:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> iconsBundle<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> as ByteArray;
	<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>bytes<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">try</span>
		<span style="color: #66cc66;">&#123;</span>
			bytes.<span style="color: #006600;">uncompress</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #66cc66;">&#125;</span>
		<span style="color: #0066CC;">catch</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066CC;">e</span>:<span style="color: #0066CC;">Error</span><span style="color: #66cc66;">&#41;</span>
		<span style="color: #66cc66;">&#123;</span>
			<span style="color: #808080; font-style: italic;">// data not compressed</span>
		<span style="color: #66cc66;">&#125;</span>
		imgLibrary = bytes.<span style="color: #006600;">readObject</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
		<span style="color: #808080; font-style: italic;">// imgLibrary is now initialized and contains data objects each representing a bitmap image</span>
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/as3-serializing-a-bundle-of-bitmaps-as-data-objects/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

