<?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>Thu, 22 Apr 2010 03:33:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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, 0xFFFFFF,
0xCCFFCC, 0xCCCCCC, 0xCC99CC, 0xCC66CC, [...]]]></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>0</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.  [...]]]></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 without [...]]]></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>
		<item>
		<title>uiWindow: Background Drop Shadow + Glow Effect</title>
		<link>http://www.ghostwire.com/blog/archives/uiwindow-background-drop-shadow-glow-effect/</link>
		<comments>http://www.ghostwire.com/blog/archives/uiwindow-background-drop-shadow-glow-effect/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 16:02:47 +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[Filters]]></category>
		<category><![CDATA[Flash Components]]></category>
		<category><![CDATA[Themes]]></category>
		<category><![CDATA[Window]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1600</guid>
		<description><![CDATA[The default behavior of the uiWindow container is to cast a drop shadow when it is active in the foreground, and not do so when it is inactive or when it is maximized to fill the stage.  This behavior is determined by the component instance&#8217;s background property value.

Default Shadow
The following is the default background [...]]]></description>
			<content:encoded><![CDATA[<p>The default behavior of the <a href="http://www.ghostwire.com/aspireui/docs/usage/uiwindow">uiWindow</a> container is to cast a drop shadow when it is active in the foreground, and not do so when it is inactive or when it is maximized to fill the stage.  This behavior is determined by the component instance&#8217;s <code>background</code> property value.</p>
<p><span id="more-1600"></span><br />
<strong>Default Shadow</strong><br />
The following is the default <code>background</code> property value for all <code>uiWindow</code> instances:<br />
<code>{shadow_up:0x000000, shadow_up_maximized:-1};</code><br />
That tells the instance it should render a drop shadow of color 0&#215;000000 when its visual state is &#8220;up&#8221;, and not render any drop shadow when its visual state is &#8220;up_maximized&#8221; (when it is maximized, the drop shadow cannot be seen so applying the effect will be pointless).</p>
<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/winxp.png" alt="winxp" title="winxp" width="480" height="416" class="alignleft size-full wp-image-1608" /></p>
<p><!-- --><br />
<strong>Always Cast Drop Shadow</strong><br />
To make a <code>uiWindow</code> instance <em>always</em> cast a drop shadow, you can set its background property as below:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> win:uiWindow = <span style="color: #000000; font-weight: bold;">new</span> uiWindow<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
win.<span style="color: #0066CC;">background</span> = <span style="color: #66cc66;">&#123;</span>shadow:0x000000<span style="color: #66cc66;">&#125;</span>;</pre></div></div>

<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/winxp_always.png" alt="winxp_always" title="winxp_always" width="480" height="416" class="alignleft size-full wp-image-1610" /></p>
<p><!-- --><br />
<strong>Never Cast Drop Shadow</strong><br />
To make a <code>uiWindow</code> instance <em>never</em> cast a drop shadow, you can set its background property to <code>null</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> win:uiWindow = <span style="color: #000000; font-weight: bold;">new</span> uiWindow<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
win.<span style="color: #0066CC;">background</span> = <span style="color: #000000; font-weight: bold;">null</span>;</pre></div></div>

<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/winxp_none.png" alt="winxp_none" title="winxp_none" width="480" height="416" class="alignleft size-full wp-image-1611" /></p>
<p><!-- --><br />
<strong>Glow Effect</strong><br />
As of v1.3.0+, you can also get the <code>uiWindow</code> instance (any <code>uiComponent</code>, actually) to cast a glow effect:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> win:uiWindow = <span style="color: #000000; font-weight: bold;">new</span> uiWindow<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
win.<span style="color: #0066CC;">background</span> = <span style="color: #66cc66;">&#123;</span>glow_up:0x000000, glow_up_maximized:-<span style="color: #cc66cc;">1</span><span style="color: #66cc66;">&#125;</span>;</pre></div></div>

<p><img src="http://www.ghostwire.com/blog/wp-content/uploads/wingraylic_glow.png" alt="wingraylic_glow" title="wingraylic_glow" width="480" height="416" class="alignleft size-full wp-image-1616" /></p>
<p><!-- --><br />
<strong>Drop Shadow + Glow</strong><br />
In the &#8220;vista&#8221; theme, the <code>uiWindow</code> instances use drop shadow + glow effects:<br />
<img src="http://www.ghostwire.com/blog/wp-content/uploads/winvista.png" alt="winvista" title="winvista" width="480" height="416" class="alignleft size-full wp-image-1609" /></p>
<p>See: <a href="http://www.ghostwire.com/blog/archives/aspire-ui-components-theme-vista-released/">&#8220;vista&#8221; themed uiWindow demo</a></p>
<p><!-- --><br />
<strong>Specifying Default uiWindow Background Property</strong><br />
If you wish to override the default background property value, ie set the default value for all <code>uiWindow</code> instances, you can do so by defining it in the theme folder&#8217;s &#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;Window</span> <span style="color: #000066;">edge</span>=<span style="color: #ff0000;">&quot;5,5,5&quot;</span> <span style="color: #000066;">slices</span>=<span style="color: #ff0000;">&quot;up,out,up_maximized,out_maximized&quot;</span> <span style="color: #000066;">prefs</span>=<span style="color: #ff0000;">&quot;padding|5|background|shadow_up,0,shadow_up_maximized,-1,glow,0,glowDepth,12,glow_up_maximized,-1&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span></pre></div></div>

<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 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.</p>
<p>You may experiment with the various features by <a href="/aspireui/download/">downloading the trial version</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/uiwindow-background-drop-shadow-glow-effect/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>uiImage: Preloading External Bitmap Images</title>
		<link>http://www.ghostwire.com/blog/archives/uiimage-preloading-external-bitmap-images/</link>
		<comments>http://www.ghostwire.com/blog/archives/uiimage-preloading-external-bitmap-images/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 12:58:14 +0000</pubDate>
		<dc:creator>sunny</dc:creator>
				<category><![CDATA[Aspire UI]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[BitmapData]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Flash Components]]></category>

		<guid isPermaLink="false">http://ghostwire.com/blog/?p=576</guid>
		<description><![CDATA[The uiImage class is used to display an image, the source of which can either be a MovieClip symbol in the library, or an external SWF/GIF/JPG/PNG file.
When using external bitmap images (GIF/JPG/PNG), the uiImage class will load from the external source only once and use cached data if the same source is requested subsequently again [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.ghostwire.com/aspireui/docs/usage/uiimage">uiImage</a> class is used to display an image, the source of which can either be a MovieClip symbol in the library, or an external SWF/GIF/JPG/PNG file.</p>
<p>When using external bitmap images (GIF/JPG/PNG), the <code>uiImage</code> class will load from the external source only once and use cached data if the same source is requested subsequently again by the same or other <code>uiImage</code> instances.  This is efficient because the same <code>BitmapData</code> is used across different <code>uiImage</code> instances that use the same image source.  This is why image icons in Aspire UI scrollable lists do not suffer from the &#8220;flickering&#8221; symptom (which you will experience when using Flash/Flex components).</p>
<p><span id="more-576"></span>The <code>uiImage</code> class does not have any specific API for preloading external bitmap images.  However, you can preload images easily using a dummy <code>uiImage</code> object:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><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: #66cc66;">&#41;</span>;
img.<span style="color: #006600;">source</span> = <span style="color: #ff0000;">&quot;ImageToPreload.png&quot;</span>;</pre></div></div>

<p>The loading of an external image begins once the &#8220;source&#8221; property is set, even if the <code>uiImage</code> instance is never actually added to the display list.</p>
<p>It may also be worthwhile to note that as of v1.2.4, the <code>uiImage</code> class will load an external resource only once, even if multiple instances request the same resource at the same time before it has been loaded.  In other words, only one connection to an external image source will be made.  Once the image is loaded, all instances using that same source will be updated.</p>
<p><code>uiImage</code> dispatches an <code>Event.CHANGE</code> event when the external image is fully loaded, therefore you can listen to this event to be notified when the (pre)loading has completed.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><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: #66cc66;">&#41;</span>;
img.<span style="color: #006600;">addEventListener</span><span style="color: #66cc66;">&#40;</span>Event.<span style="color: #006600;">CHANGE</span>, on_imgLoad<span style="color: #66cc66;">&#41;</span>;
img.<span style="color: #006600;">source</span> = <span style="color: #ff0000;">&quot;ImageToPreload.png&quot;</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> on_imgLoad<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>
    evt.<span style="color: #0066CC;">target</span>.<span style="color: #006600;">removeEventListener</span><span style="color: #66cc66;">&#40;</span>evt.<span style="color: #0066CC;">type</span>, on_imgLoad<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #808080; font-style: italic;">// </span>
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<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 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.</p>
<p>You may experiment with the various features by <a href="/aspireui/download/">downloading the trial version</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/uiimage-preloading-external-bitmap-images/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[AS3] Embedding Binary XML</title>
		<link>http://www.ghostwire.com/blog/archives/as3-embedding-binary-xml/</link>
		<comments>http://www.ghostwire.com/blog/archives/as3-embedding-binary-xml/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 06:12:54 +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[ByteArray]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.ghostwire.com/blog/?p=1554</guid>
		<description><![CDATA[This post is a supplement to &#8220;Saving XML As Binary&#8221;.  I neglected to mention in that post that you can, if so desired, embed the binary XML within your SWF instead of loading it during run-time.  That means you still get to keep the XML externally, not as part of your application code, [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a supplement to <a href="http://www.ghostwire.com/blog/archives/as3-saving-xml-as-binary/">&#8220;Saving XML As Binary&#8221;</a>.  I neglected to mention in that post that you can, if so desired, embed the binary XML within your SWF instead of loading it during run-time.  That means you still get to keep the XML externally, not as part of your application code, so that the code and data can still be kept separate and maintained more easily.</p>
<p>However, it must be mentioned that embedding a text XML within SWF will get it compressed as part of the SWF compression anyway.  Therefore, if compression is the only motivation, don&#8217;t convert the XML to binary and embed the binary version &#8211; it does not make sense.  But if you wish to do some data encryption, then the additional work may be appropriate.</p>
<p><span id="more-1554"></span><br />
<strong>Embedding External Data</strong><br />
You can embed any external source, including any external XML file, within your SWF using the [Embed] tag:</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>
&nbsp;
<span style="color: #808080; font-style: italic;">// assuming you have an XML file named &quot;data.xml&quot; in folder &quot;assets/data/&quot;</span>
&nbsp;
<span style="color: #66cc66;">&#91;</span>Embed<span style="color: #66cc66;">&#40;</span>source=<span style="color: #ff0000;">&quot;assets/data/data.xml&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 binaryXML:<span style="color: #000000; font-weight: bold;">Class</span>;</pre></div></div>

<p><!-- --><br />
<strong>Back To XML</strong><br />
You can then instantiate the binary data and convert it back to XML in your code:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> xmlData:<span style="color: #0066CC;">XML</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> bytes:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> binaryXML<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: #66cc66;">&#125;</span>
	xmlData = <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span>bytes<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>NOTE: The above code will be able to handle both binary XML and text XML files.</p>
<p><!-- --><br />
<strong>ROT128 Encrypted Binary XML</strong><br />
If you had performed <a href="http://www.ghostwire.com/blog/archives/as3-applying-rot128-encryption-on-binary-xml/">ROT128 encryption</a> on the binary XML, you decrypt it accordingly before calling <code>uncompress()</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">var</span> xmlData:<span style="color: #0066CC;">XML</span>;
&nbsp;
<span style="color: #000000; font-weight: bold;">var</span> bytes:ByteArray = <span style="color: #000000; font-weight: bold;">new</span> binaryXML<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: #808080; font-style: italic;">// BEGIN ROT128</span>
	<span style="color: #000000; font-weight: bold;">var</span> j:<span style="color: #0066CC;">int</span> = <span style="color: #0066CC;">data</span>.<span style="color: #0066CC;">length</span>;
	<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>j--<span style="color: #66cc66;">&#41;</span>
	<span style="color: #66cc66;">&#123;</span>
		<span style="color: #0066CC;">data</span><span style="color: #66cc66;">&#91;</span>j<span style="color: #66cc66;">&#93;</span> += <span style="color: #cc66cc;">128</span>;
	<span style="color: #66cc66;">&#125;</span>
	<span style="color: #808080; font-style: italic;">// END ROT128</span>
	bytes.<span style="color: #006600;">uncompress</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;
	xmlData = <span style="color: #0066CC;">XML</span><span style="color: #66cc66;">&#40;</span>bytes<span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span></pre></div></div>

<p>NOTE: The above code assumes the data is binary and ROT128 encrypted; it will not be able to handle text XML.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ghostwire.com/blog/archives/as3-embedding-binary-xml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
