<?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>robskelly.com &#187; ActionScript</title>
	<atom:link href="http://blog.robskelly.com/category/actionscript/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.robskelly.com</link>
	<description>Flash, Flex, Geography and GIS</description>
	<lastBuildDate>Fri, 19 Mar 2010 06:10:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Real-time Weather with Flash and Java</title>
		<link>http://blog.robskelly.com/2010/01/real-time-weather-with-flash-and-java/</link>
		<comments>http://blog.robskelly.com/2010/01/real-time-weather-with-flash-and-java/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 09:54:45 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FLEX]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Weather]]></category>

		<guid isPermaLink="false">http://blog.robskelly.com/?p=138</guid>
		<description><![CDATA[This is a real-time weather station I built using an AAG electronica instrument and an EEE 701 for the server.
I coded the server in Java using Apache&#8217;s Mina library for non-blocking sockets. The client is FLEX, and uses Socket (rather than HTTP). The webcam service consists essentially of a Java class that reads the video4linux [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 250px"><img title="1-Wire Weather Station" src="http://farm3.static.flickr.com/2438/3669141694_3675abdb40_m.jpg" alt="1-Wire Weather Station" width="240" height="197" /><p class="wp-caption-text">1-Wire Weather Station</p></div>
<p>This is a real-time weather station I built using an <a title="AAG" target="_blank" href="http://www.aag.com.mx/aagusa/index.html">AAG electronica</a> instrument and an <a target="_blank" title="EEE PC" href="http://en.wikipedia.org/wiki/ASUS_Eee_PC">EEE 701</a> for the server.</p>
<p>I coded the server in <a title="Java" href="http://java.sun.om" target="_blank">Java</a> using <a title="Mina" href="http://mina.apache.org/" target="_blank">Apache&#8217;s Mina</a> library for non-blocking sockets. The client is <a title="FLEX" href="http://www.adobe.com/products/flex/" target="_blank">FLEX</a>, and uses Socket (rather than HTTP). The webcam service consists essentially of a Java class that reads the video4linux data as raw RGB and saves it to a JPEG which is then streamed over the socket along with all the other data (I built the server to be pluggable, so each of these little add-ons is a plugin that shares the stream with the other plugins). The archival data lives in <a title="MySQL" href="http://www.mysql.com/" target="_blank">MySQL</a>.</p>
<p><span id="more-138"></span></p>
<p>I&#8217;ve more or less lost interest in this project so it&#8217;s not pretty, but on windy days, it is fairly enjoyable to watch! The server itself can be used for just about anything, from a <a title="Weather Station" href="http://weather.robskelly.com" target="_blank">weather station</a>, to a <a title="GPS Sat Tracker" href="http://gps.robskelly.com" target="_blank">GPS satellite tracker</a>, to the user map that adorns the top-left corner of this site.</p>
<div id="station"></div>
<p><script type="text/javascript">
embed("/samples/weather/weather_client.swf","/samples/weather/weather.jpg","station",'100%',400);
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2010/01/real-time-weather-with-flash-and-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Earthquake Map</title>
		<link>http://blog.robskelly.com/2010/01/flex-earthquake-map/</link>
		<comments>http://blog.robskelly.com/2010/01/flex-earthquake-map/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 09:36:03 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FLEX]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[Maps]]></category>

		<guid isPermaLink="false">http://blog.robskelly.com/?p=132</guid>
		<description><![CDATA[Shows the world&#8217;s earthquakes during the last 24 hours. Blue markers are small magnitude quakes, red markers are large magnitude.
Data updates every 30 seconds and comes from here: http://earthquake.usgs.gov/earthquakes/catalogs/


embed("/samples/quake/Quakes.swf","/samples/quake/quakemap.jpg","quakemap",'100%',300);

]]></description>
			<content:encoded><![CDATA[<p>Shows the world&#8217;s earthquakes during the last 24 hours. Blue markers are small magnitude quakes, red markers are large magnitude.</p>
<p>Data updates every 30 seconds and comes from here: <a href="http://http://earthquake.usgs.gov/earthquakes/catalogs/">http://earthquake.usgs.gov/earthquakes/catalogs/</a></p>
<div id="quakemap"></div>
<p><script type="text/javascript">
embed("/samples/quake/Quakes.swf","/samples/quake/quakemap.jpg","quakemap",'100%',300);
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2010/01/flex-earthquake-map/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>AppendToGatewayUrl</title>
		<link>http://blog.robskelly.com/2009/06/appendtogatewayurl/</link>
		<comments>http://blog.robskelly.com/2009/06/appendtogatewayurl/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 23:08:09 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[BlazeDS]]></category>
		<category><![CDATA[FLEX]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.robskelly.com/?p=93</guid>
		<description><![CDATA[If you&#8217;re using BlazeDS and seeing an error involving a callback called &#8220;AppendToGatewayUrl&#8221; this might help.
AppendToGatewayUrl modifies the gateway of a NetConnection object with the session id (in this case &#8220;jsessionid&#8221;) of the current session. If you reconnect with this value appended to the gateway URL, your session can be identified, even on clients that [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re using BlazeDS and seeing an error involving a callback called &#8220;AppendToGatewayUrl&#8221; this might help.</p>
<p>AppendToGatewayUrl modifies the gateway of a NetConnection object with the session id (in this case &#8220;jsessionid&#8221;) of the current session. If you reconnect with this value appended to the gateway URL, your session can be identified, even on clients that do not use cookies.</p>
<p>There are two ways to handle this:</p>
<ul style="list-style:none;">
<li>set NetConnection.client to an object that implements the AppendToGatewayUrl function, or;</li>
<li>subclass NetConnection to implement it (since NetConnection.client points to the NetConnection instance by default, you can not reassign the client field if you want this method to work).</li>
</ul>
<p>There&#8217;s one caveat to both approaches, though. It has been my experience that if you call NetConnection.connect while you are receiving a response to bundled remote methods, the data may be lost or a &#8220;Client.Data.UnderFlow&#8221; error thrown. This occurs because AppendToGatewayUrl gets called after the first result, and the immediate call to NetConnection.connect aborts the rest of the transfer.</p>
<p>Here&#8217;s a sample implementation of option A:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="kw3">public</span> <span class="kw2">class</span> Sample<span class="br0">&#123;</span></p>
<p>&nbsp; <span class="kw3">private</span> <span class="kw2">var</span> conn : <span class="kw3">NetConnection</span>;</p>
<p>&nbsp; <span class="kw3">public</span> <span class="kw2">function</span> Sample<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; conn = <span class="kw2">new</span> <span class="kw3">NetConnection</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; conn .<span class="me1">client</span> = <span class="kw3">this</span>;<br />
&nbsp; &nbsp; conn .<span class="kw3">connect</span><span class="br0">&#40;</span><span class="st0">&#8216;http://localhost/gateway&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw3">public</span> <span class="kw2">function</span> AppendToGatewayUrl<span class="br0">&#40;</span>extra:<span class="kw3">String</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; conn .<span class="kw3">connect</span><span class="br0">&#40;</span>conn.<span class="me1">uri</span> + extra<span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw3">public</span> <span class="kw2">function</span> <span class="kw3">load</span><span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; conn .<span class="kw3">call</span><span class="br0">&#40;</span><span class="st0">&#8217;service.load&#8217;</span>,<span class="kw2">new</span> Responder<span class="br0">&#40;</span>loadResult,<span class="kw3">error</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw3">private</span> <span class="kw2">function</span> loadResult<span class="br0">&#40;</span>value:<span class="sy0">*</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&#8216;value&#8217;</span>,value<span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p>&nbsp; <span class="kw3">private</span> <span class="kw2">function</span> <span class="kw3">error</span><span class="br0">&#40;</span>err:<span class="sy0">*</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw3">trace</span><span class="br0">&#40;</span><span class="st0">&#8216;error&#8217;</span>,err.<span class="kw3">message</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
</div>
<p>To get around the problem with bundled calls, you could save the session id in a field and reconnect before the next call.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2009/06/appendtogatewayurl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Does Flash Delete your Timeline Code?</title>
		<link>http://blog.robskelly.com/2009/06/why-does-flash-delete-your-timeline-code/</link>
		<comments>http://blog.robskelly.com/2009/06/why-does-flash-delete-your-timeline-code/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 19:21:52 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.robskelly.com/?p=86</guid>
		<description><![CDATA[If you&#8217;ve tried to load one swf into another and found that the loaded clip&#8217;s timeline code has disappeared, you&#8217;re not alone. Fortunately, the explanation is simple.
Usually what happens is, you&#8217;ve tried to cast the reference to the loaded swf to its document type, like so:

var page : MyDocumentClass = loader.content as MyDocumentClass;
page.doSomeMethod&#40;&#41;;

If doSomeMethod, for [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve tried to load one swf into another and found that the loaded clip&#8217;s timeline code has disappeared, you&#8217;re not alone. Fortunately, the explanation is simple.</p>
<p>Usually what happens is, you&#8217;ve tried to cast the reference to the loaded swf to its document type, like so:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="kw2">var</span> page : MyDocumentClass = loader.<span class="me1">content</span> as MyDocumentClass;<br />
page.<span class="me1">doSomeMethod</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</div>
<p>If doSomeMethod, for example, plays an animation on the timeline that you have governed with &#8220;stop&#8221; commands, or that calls methods in the document class, you&#8217;ll find that it doesn&#8217;t work. </p>
<p>Why? Because you&#8217;ve embedded the class definition in the parent movie, and it doesn&#8217;t know about the timeline code. Think about it: adding timeline code to a movie effectively makes that movie a subclass of its document class. When you embed a reference to the document class in the parent, the version associated with the child movie (with the timeline code) isn&#8217;t used.</p>
<p>An associated problem is that you&#8217;ve defeated some of the key reasons for modularizing your sites &#8211; to make updates easier, and load code only when it&#8217;s needed, not before. Embedding the document classes of your loaded movies defeats the former &#8211; because you have to recompile the parent as well as the child when you update the child, and the latter &#8211; because you&#8217;re loading all the child classes in the parent.</p>
<p>How to solve the problem, then? use <em>interfaces</em>. Make all of your document classes implement a single interface and make absolutely sure that no references to the document classes exist anywhere in the parent movie.</p>
<p>For example, here&#8217;s a child movie class:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="kw3">public</span> <span class="kw2">class</span> MyChild <span class="kw3">extends</span> <span class="kw3">MovieClip</span> <span class="kw3">implements</span> IChild<span class="br0">&#123;</span><br />
&nbsp; <span class="kw3">public</span> <span class="kw2">function</span> transitionIn<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; <span class="kw3">gotoAndPlay</span><span class="br0">&#40;</span><span class="st0">&#8217;somewhere&#8217;</span><span class="br0">&#41;</span>;<br />
&nbsp; <span class="br0">&#125;</span><br />
<span class="br0">&#125;</span></div>
</div>
<p>As you can see, MyChild implements IChild, an interface:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="kw3">public</span> <span class="kw3">interface</span> IChild <span class="kw3">extends</span> IEventDispatcher<span class="br0">&#123;</span><br />
&nbsp; &nbsp;<span class="kw2">function</span> transitionIn<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw3">void</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Now, in your parent movie, you&#8217;ll use something like this:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="kw3">private</span> <span class="kw2">function</span> movieLoaded<span class="br0">&#40;</span>evt:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; <span class="kw2">var</span> child : IChild = loader.<span class="me1">content</span> as IChild;<br />
&nbsp; child.<span class="me1">transitionIn</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>Notice that you&#8217;re calling a method on the interface, not the document class. In fact, the parent movie should be completely agnostic where the doc classes are concerned. The interface is enough.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2009/06/why-does-flash-delete-your-timeline-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Update: Using PixelBender to Crunch Numbers</title>
		<link>http://blog.robskelly.com/2009/03/update-using-pixelbender-to-crunch-numbers/</link>
		<comments>http://blog.robskelly.com/2009/03/update-using-pixelbender-to-crunch-numbers/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 07:13:56 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FLEX]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.robskelly.com/?p=79</guid>
		<description><![CDATA[I didn&#8217;t realize it, but there&#8217;s a bug in PixelBender for Flash when using image4 input. In my case, I have x-y coordinates, and I was trying to operate on two at a time using image4. Can&#8217;t do it (yet). The kernel craps out after 60 elements. 
Of course, you&#8217;re not allowed to output 2- [...]]]></description>
			<content:encoded><![CDATA[<p>I didn&#8217;t realize it, but there&#8217;s a bug in PixelBender for Flash when using image4 input. In my case, I have x-y coordinates, and I was trying to operate on two at a time using image4. Can&#8217;t do it (yet). The kernel craps out after 60 elements. </p>
<p>Of course, you&#8217;re not allowed to output 2- or 1-element pixels, so you have to use image3 for input. What to do? It&#8217;s simple really: Say you have a Vector of numbers representing pairs (coordinates, in my case). The first pixel with contain x,y,x and the second y,x,y and so on. All you have to do is check the current pixel&#8217;s x-coordinate (assuming the height of your PixelBender input is set to 1) and do the calculations in one or the other order. </p>
<p>Note that in PixelBender, the x,y of the pixel (as reported by outCoord()) is the <em>midpoint</em> of the pixel, so x=0.5,1.5,2.5 and so on. To determine which order to take the calculations in, you just need to know whether x is even or odd.</p>
<p><span id="more-79"></span></p>
<p>Kernel Code:</p>
<div class="codesnip-container" >void evaluatePixel(){<br />
  // get the output coordinate<br />
  float2 coord = outCoord();<br />
  // get the 3 float values represented by the current pixel<br />
  float3 value = sample(src,coord);<br />
  //  check if the current pixel x-coordinate is even.<br />
  if(mod(coord[0]-0.5,2.0)==0){<br />
    // if the current pixel x-coord is even:<br />
    value[0] = cos(value[0]);  // operate on the input x-coordinate<br />
    value[1] = sin(value[1]);  // operate on the input y-coordinate<br />
    value[2] = cos(value[2]);  // operate on the input x-coordinate<br />
  }else{<br />
    // if the current pixel x-coord is odd:<br />
    value[0] = sin(value[0]);  // operate on the input y-coordinate<br />
    value[1] = cos(value[1]);  // operate on the input x-coordinate<br />
    value[2] = sin(value[2]);  // operate on the input y-coordinate<br />
  }<br />
  out = value;<br />
}</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2009/03/update-using-pixelbender-to-crunch-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Pixel Bender for Math in Flash/FLEX</title>
		<link>http://blog.robskelly.com/2009/02/using-pixel-bender-for-math-in-flashflex/</link>
		<comments>http://blog.robskelly.com/2009/02/using-pixel-bender-for-math-in-flashflex/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 21:15:42 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FLEX]]></category>
		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.robskelly.com/?p=58</guid>
		<description><![CDATA[Pixel Bender has applications other than manipulating images in Flash/FLEX. While working on some map projection experiments, I decided to look for a way to offload some of the computations to avoid freezing up the display or simply taking too long. Turns out, Pixel Bender not only does math several times faster than Flash, it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://labs.adobe.com/technologies/pixelbender/" title="Adobe Labs: Pixel Bender">Pixel Bender</a> has applications other than manipulating images in <a href="http://www.adobe.com/products/flash/" title="Adobe: Flash">Flash</a>/<a href="http://www.adobe.com/products/flex/" title="Adobe: Flex">FLEX</a>. While working on some map projection experiments, I decided to look for a way to offload some of the computations to avoid freezing up the display or simply taking too long. Turns out, Pixel Bender not only does math several times faster than Flash, it can also be run asynchronously!</p>
<p><span id="more-58"></span></p>
<p>There are a few tricks to using it, though:</p>
<p>Pixel Bender can only accept floats. If you want to operate on doubles, you might be able to work out something with a ByteArray (which is also permitted as Shader input) and Pixel Bender code, but that&#8217;s beyond the scope of this article, if it&#8217;s even possible.</p>
<p>Though you can feed a Vector of Numbers into your kernel, they are treated internally as pixels. A pixel is an array of floats with one to four elements, but the output pixel cannot have less than three elements. What this means is that you&#8217;ll be feeding three or four Numbers into the kernel at a time, executing a computation on each, then returning the results as a 3- or 4-element pixel. In the case of the map projections, I&#8217;m feeding in four numbers at a time representing two lat/lon sets. </p>
<p>Because you&#8217;ll be operating on chunks of three or four Numbers, the length of your vector must be a multiple of the size of each pixel. For example, if your vector is ten elements long, you must either stop after processing three pixels, or pad out the vector to a length of 12.</p>
<p>Because Pixel Bender considers the data you pass to be a 2-dimensional grid, you have to compute a width and height value for your data. You can use 1 for the height, but only if your data set is small. The kernel will throw an error, saying that the input is too large, otherwise. The best way to fit it all in is to break your data up into a square.</p>
<p>So let&#8217;s see an example. Say you want to compute the square root of a list of Numbers. You create a Vector.<Number> to store them. Assuming nVec is your vector:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="co1">// The number of pixels (assuming a 3-element pixel). </span><br />
<span class="co1">// Since our length is 100, the number of pixels isn&#8217;t going to be </span><br />
<span class="co1">// whole, but we won&#8217;t worry about that just yet.</span><br />
<span class="kw2">var</span> count : <span class="kw3">Number</span> = nVec.<span class="kw3">length</span><span class="sy0">/</span><span class="nu0">3</span>;</p>
<p><span class="co1">// Calculate the width of the grid. We round it up, because the</span><br />
<span class="co1">// width and height have to be whole numbers.</span><br />
<span class="kw2">var</span> w : uint = <span class="kw3">Math</span>.<span class="kw3">ceil</span><span class="br0">&#40;</span><span class="kw3">Math</span>.<span class="kw3">sqrt</span><span class="br0">&#40;</span>count<span class="br0">&#41;</span><span class="br0">&#41;</span>; <span class="co1">// w = 6</span></p>
<p><span class="co1">// Calculate the height of the grid.</span><br />
<span class="kw2">var</span> h : uint = <span class="kw3">Math</span>.<span class="kw3">ceil</span><span class="br0">&#40;</span>count<span class="sy0">/</span>w<span class="br0">&#41;</span>; <span class="co1">// h = 6</span></p>
<p><span class="co1">// Multiplying width (6) by height (6) gives us 36, which</span><br />
<span class="co1">// is more than our total number of pixels. We have to pad our vector.</span><br />
<span class="co1">// The length of the vector is going to be 36*3, or 108.</span><br />
<span class="co1">// Chose your padding carefully, because these values will be</span><br />
<span class="co1">// used in the computation. I&#8217;ll use 0 here.</span><br />
<span class="kw1">while</span><span class="br0">&#40;</span>nVec.<span class="me1">length</span><span class="sy0">&lt;</span>w<span class="sy0">*</span>h<span class="sy0">*</span>3<span class="br0">&#41;</span><br />
&nbsp; &nbsp; &nbsp;nVec.<span class="kw3">push</span><span class="br0">&#40;</span>0<span class="br0">&#41;</span>;</p>
<p><span class="co1">// Create and configure your Shader. Here, shaderCls is </span><br />
<span class="co1">// the embedded .pbj file.</span><br />
<span class="kw2">var</span> shader : Shader = <span class="kw2">new</span> Shader<span class="br0">&#40;</span><span class="kw2">new</span> shaderCls<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
shader .<span class="kw3">data</span>.<span class="me1">src</span>.<span class="kw3">width</span> &nbsp;= w;<br />
shader .<span class="kw3">data</span>.<span class="me1">src</span>.<span class="kw3">height</span> = h;<br />
shader .<span class="kw3">data</span>.<span class="me1">src</span>.<span class="me1">input</span> &nbsp;= nVec;</p>
<p><span class="co1">// Create the ShaderJob. The second parameter is the output</span><br />
<span class="co1">// vector for computed values. I&#8217;m using the same vector, because I</span><br />
<span class="co1">// want the new values to replace the old ones.</span><br />
<span class="kw2">var</span> job : ShaderJob = <span class="kw2">new</span> ShaderJob<span class="br0">&#40;</span>shader,nVec,w,h<span class="br0">&#41;</span>;</p>
<p><span class="co1">// Start the computation. Passing true into the start method</span><br />
<span class="co1">// will execute the computations synchronously. False or nothing</span><br />
<span class="co1">// will start asynchronous execution. You&#8217;ll have to use a listener</span><br />
<span class="co1">// to detect the completion of the calculations.</span><br />
job.<span class="kw3">start</span><span class="br0">&#40;</span><span class="kw2">true</span><span class="br0">&#41;</span>;</div>
</div>
<p>The shader kernel can be loaded with URLLoader, or embedded and passed to the shader as a class instance. To embed the pbj file, you&#8217;ll do something like this:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="br0">&#91;</span>Embed<span class="br0">&#40;</span>source=<span class="st0">&quot;MyKernel.pbj&quot;</span>,mimeType=<span class="st0">&quot;application/octet-stream&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="kw3">private</span> <span class="kw2">var</span> shaderCls : <span class="kw2">Class</span>;</div>
</div>
<p>Here&#8217;s the Pixel Bender kernel:</p>
<div class="codesnip-container" ><languageVersion : 1.0;></p>
<p>kernel SQRTKernel<br />
<<br />
    namespace : &#8220;com.robskelly&#8221;;<br />
    vendor : &#8220;Rob Skelly&#8221;;<br />
    version : 1;<br />
    description : &#8220;Calculates the square root of a list of number.&#8221;<br />
><br />
{<br />
    input image3 src;<br />
    output pixel3 dst;</p>
<p>    void evaluatePixel(){<br />
        // the input pixel. this is really a list of 3 floats.<br />
        pixel3 px = sample(src,outCoord());<br />
        // run the sqrt on each float in the pixel<br />
        px[0] = sqrt(px[0]);<br />
        px[1] = sqrt(px[1]);<br />
        px[2] = sqrt(px[2]);<br />
        // assign the pixel to the output pixel<br />
        dst = px;<br />
    }<br />
}</p></div>
<p>So, does using Pixel Bender for math really help? Yes! In my simple tests, using Pixel Bender for collections of Numbers larger than a few hundred is at least 3x as fast and much better still for larger sets and more complex calculations. There is some overhead associated with setting up the shader objects, but depending on what you&#8217;re doing, the savings are definitely worth it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2009/02/using-pixel-bender-for-math-in-flashflex/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>A GPX Parser in ActionScript 3</title>
		<link>http://blog.robskelly.com/2009/01/a-gpx-parser-in-actionscript-3/</link>
		<comments>http://blog.robskelly.com/2009/01/a-gpx-parser-in-actionscript-3/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 06:14:58 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[GIS]]></category>
		<category><![CDATA[GPS]]></category>
		<category><![CDATA[Maps]]></category>

		<guid isPermaLink="false">http://blog.robskelly.com/?p=38</guid>
		<description><![CDATA[GPX is the standard XML format used to store routes, tracks, waypoints and other data for GPS units.
I&#8217;m working on a parser in AS3 that will load a GPX file and expose all the information inside as ActionScript objects. See a test using Google Maps below.
Click &#8220;Load&#8221; to load the file from my server (this [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.topografix.com/gpx.asp" title="GPX Format Specification" target="_blank">GPX</a> is the standard XML format used to store routes, tracks, waypoints and other data for GPS units.</p>
<p>I&#8217;m working on a parser in AS3 that will load a GPX file and expose all the information inside as ActionScript objects. See a test using <a href="http://maps.google.com" title="Google Maps" target="_blank">Google Maps</a> below.</p>
<p>Click &#8220;Load&#8221; to load the file from my server (this is a file containing a short bike ride around Victoria, BC), or click &#8220;Browse&#8230;&#8221; to load your own GPX file.</p>
<p>I haven&#8217;t tested this very extensively, so if your file has features that mine doesn&#8217;t, it may fail. If it does, please leave a comment! I&#8217;ll be uploading this to <a href="http://code.google.com/p/dijital-as3-lib/" title="Google Code" target="_blank">Google Code</a> as soon as I do some more tests.</p>
<div id="gpxparse"></div>
<p><script type="text/javascript">
    embed("/samples/gpx/gpx_sample.swf","/samples/gpx/gpxparse.jpg","gpxparse","100%",300);
</script></p>
<p>Note: you&#8217;ll need Flash Player 10 to use the browse button.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2009/01/a-gpx-parser-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>On-the-fly Localization</title>
		<link>http://blog.robskelly.com/2008/08/on-the-fly-localization/</link>
		<comments>http://blog.robskelly.com/2008/08/on-the-fly-localization/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 20:10:09 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Localization]]></category>

		<guid isPermaLink="false">http://robskelly.com/blog/?p=7</guid>
		<description><![CDATA[So, what if you want your users to be able to change locales on-the-fly? I&#8217;ve put together a simple component that loads and manages translations via XML.

Here&#8217;s how it works&#8230;
Somewhere in your code, you must set up your languages:
import com.robskelly.text.LocalTextField;

LocalTextField.addLanguage('en_us','lang/en_us.xml');
LocalTextField.addLanguage('es','lang/es.xml');
Now you can set a language:
LocalTextField.setLanguage('en_us');
LocalTextField won&#8217;t load the language file until you call setLanguage.
LocalTextField itself [...]]]></description>
			<content:encoded><![CDATA[<p>So, what if you want your users to be able to change locales on-the-fly? I&#8217;ve put together a simple component that loads and manages translations via XML.</p>
<div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="370" height="250" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="id" value="myId" /><param name="src" value="samples/lang/lang.swf" /><embed id="myId" type="application/x-shockwave-flash" width="370" height="250" src="samples/lang/lang.swf"></embed></object></div>
<p><span id="more-7"></span>Here&#8217;s how it works&#8230;</p>
<p>Somewhere in your code, you must set up your languages:</p>
<pre lang="actionscript">import com.robskelly.text.LocalTextField;

LocalTextField.addLanguage('en_us','lang/en_us.xml');
LocalTextField.addLanguage('es','lang/es.xml');</pre>
<p>Now you can set a language:</p>
<pre lang="actionscript">LocalTextField.setLanguage('en_us');</pre>
<p>LocalTextField won&#8217;t load the language file until you call setLanguage.</p>
<p>LocalTextField itself is a component that wraps a flash.text.TextField instance. You can drag an instance of LocalTextField onto the stage, set its ID parameter, and off you go!</p>
<p>The language files are XML and look like this:</p>
<pre lang="xml">&lt;strings&gt;
	&lt;string id="1"&gt;This is a string.&lt;/string&gt;
	&lt;string id="2"&gt;This is also a string.&lt;/string&gt;
	&lt;string id="3" html="true"&gt;This is a string with &lt;b&gt;HTML&lt;b /&gt;&lt;/string&gt;
&lt;/strings&gt;</pre>
<p>Download a sample <a title="Download LocalTextField sample." href="files/lang.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2008/08/on-the-fly-localization/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing Character Set Embedding in a Flash Document</title>
		<link>http://blog.robskelly.com/2008/08/changing-character-set-embedding-in-a-flash-document/</link>
		<comments>http://blog.robskelly.com/2008/08/changing-character-set-embedding-in-a-flash-document/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 17:35:07 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Localization]]></category>

		<guid isPermaLink="false">http://robskelly.com/blog/?p=6</guid>
		<description><![CDATA[Here&#8217;s a little JSFL script that you can use to change the character-set embedding in all the input and dynamic TextFields in an entire Flash document. When you run it, it&#8217;ll pick the active document and pop up a prompt asking for the character-set IDs.
This is a pipe-delimited string of integers, so for one character [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little JSFL script that you can use to change the character-set embedding in all the input and dynamic TextFields in an entire Flash document. When you run it, it&#8217;ll pick the active document and pop up a prompt asking for the character-set IDs.</p>
<p><span id="more-6"></span>This is a pipe-delimited string of integers, so for one character set, say, &#8220;Basic Latin,&#8221; enter:</p>
<p><img style="margin: 10px;" src="http://blog.robskelly.com/files/prompt1.jpg" alt="Character Embed Range Prompt" width="263" height="140" /></p>
<p>For more than one character set, say, &#8220;Basic Latin,&#8221; plus &#8220;Armenian,&#8221; enter:</p>
<p><img style="margin: 10px;" src="http://blog.robskelly.com/files/prompt2.jpg" alt="Character Embed Range Prompt" width="263" height="140" /></p>
<p>This script uses the IDs from the UnicodeTable.xml file in C:\Documents and Settings\[username]\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\FontEmbedding. You can create your own character sets by copying or adding glyphRange elements.</p>
<p>For example, I wanted to extend the Basic Latin character set with some European characters. I simply copied the Basic Latin glyphRange element and gave it a new name and ID. Then I opened the charmap utility in Windows (C:\WINDOWS\system32\charmap.exe) and found the Unicode codes for the characters I wanted. The codes in charmap are in the format &#8220;0+0000.&#8221; Just change the &#8220;+&#8221; to an &#8220;x.&#8221; Since the characters in charmap are listed in order of their Unicode codes, you can use the first and last IDs of a range of characters and all those in between will be included. Here&#8217;s my &#8220;Basic Latin plus European&#8221; glyphRange:</p>
<pre lang="xml">&lt;glyphRange name="Basic Latin Plus European" id="30" &gt;
&lt;!-- Ranges copied from "Basic Latin" --&gt;
&lt;range min="0x0020" max ="0x002F" /&gt;
&lt;range min="0x0030" max ="0x0039" /&gt;
&lt;range min="0x003A" max ="0x0040" /&gt;
&lt;range min="0x0041" max ="0x005A" /&gt;
&lt;range min="0x005B" max ="0x0060" /&gt;
&lt;range min="0x0061" max ="0x007A" /&gt;
&lt;range min="0x007B" max ="0x007E" /&gt;
&lt;!-- New ranges --&gt;
&lt;range min="0x00C0" max="0x0259" /&gt;
&lt;range min="0x1E80" max="0x1EF9" /&gt;
&lt;/glyphRange&gt;</pre>
<p>Download the script <a title="Download ReplaceTextFormat.zip" href="http://blog.robskelly.com/files/ReplaceTextFormat.zip">here</a>.<br />
Place the file in C:\Documents and Settings\[username]\Local Settings\Application Data\Adobe\Flash CS3\en\Configuration\Commands and run it from the &#8220;Commands&#8221; menu in Flash.</p>
<p><strong>Update:</strong> If you get an error like this: </p>
<pre>
At line 1 of file "/Users/dan/Downloads/ReplaceTextFormat.jsfl":
TypeError: fl.findObjectInDocByType is not a function
</pre>
<p>there&#8217;s a quick fix. Find the file ObjectFindAndSelect.jsfl in en/Configuration/Javascript and edit the function FlashUtils_findObjectInTimeline, adding this in the first line of the body (around line 29):</p>
<pre lang="javascript">
if(!objTimeline)return;
</pre>
<p>This method performs a bunch of operations on that object but fails to check if it&#8217;s null first. According to a user in the <a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00004151.html" title="Livedocs">comments on the livedoc entry for fl.findObjectInDocByType()</a>, pngs in the fla timeline will cause objTimeline to be null. I tested it with a png and, by golly, it&#8217;s true. Thanks Dan!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2008/08/changing-character-set-embedding-in-a-flash-document/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic Font Loading in Flash 9</title>
		<link>http://blog.robskelly.com/2008/06/dynamic-font-loading-in-flash-9/</link>
		<comments>http://blog.robskelly.com/2008/06/dynamic-font-loading-in-flash-9/#comments</comments>
		<pubDate>Thu, 19 Jun 2008 01:22:15 +0000</pubDate>
		<dc:creator>Rob</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[FLEX]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Localization]]></category>
		<category><![CDATA[font embedding]]></category>

		<guid isPermaLink="false">http://robskelly.com/blog/?p=3</guid>
		<description><![CDATA[One of the biggest headaches in localizing Flash sites is setting up to dynamically load and easily use embedded fonts. Recently, in order to build a site that will need localization for an as-yet-undecided number of countries, I finally decided to dive in and solve this problem once and for all.

There are several problems with [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest headaches in localizing Flash sites is setting up to dynamically load and easily use embedded fonts. Recently, in order to build a site that will need localization for an as-yet-undecided number of countries, I finally decided to dive in and solve this problem once and for all.</p>
<p><span id="more-3"></span></p>
<p>There are several problems with creating loadable font modules for Flash:</p>
<ul>
<li>If you embed fonts in a TextField, there&#8217;s no way to access the Font instance or class from the swf.</li>
<li>If you create a font library symbol, there&#8217;s no way to alter the character set, other than changing your machine&#8217;s locale.</li>
<li>If you set the same font in a library symbol and a TextField, the charset in the symbol will actually override that in the TextField, and an incomplete charset will be baked into the swf (whaa?)</li>
</ul>
<p>So, how do you create an accessible font in an swf? <strong>FLEX!</strong></p>
<p>Flex allows you to specify specific charsets for embedded fonts, and requires that you define a class for the embedded font. The font can easily be retrieved from the swf after loading. Here&#8217;s a usage example.</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="co1">// load an swf that has a font embedded in it (see below)</span><br />
<span class="kw2">function</span> loadFont<span class="br0">&#40;</span>fontURL:<span class="kw3">String</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> loader : Loader = <span class="kw2">new</span> Loader<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loader .<span class="me1">contentLoaderInfo</span>.<span class="me1">addEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">INIT</span>,fontLoaded<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; loader .<span class="kw3">load</span><span class="br0">&#40;</span><span class="kw2">new</span> URLRequest<span class="br0">&#40;</span>fontURL<span class="br0">&#41;</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></p>
<p><span class="co1">// when the swf is loaded&#8230;</span><br />
<span class="kw2">function</span> fontLoaded<span class="br0">&#40;</span>evt:Event<span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// get the loader</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> loader : Loader = <span class="br0">&#40;</span>evt.<span class="kw3">target</span> as LoaderInfo<span class="br0">&#41;</span>.<span class="me1">loader</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// remove events</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; loader .<span class="me1">contentLoaderInfo</span>.<span class="me1">removeEventListener</span><span class="br0">&#40;</span>Event.<span class="me1">INIT</span>,fontLoaded<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// cast the loader content to the IFontSource type. IFontSource defines a getFont() method that</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// we can use to retrieve the font. DO NOT use the swf&#8217;s actual main class here. if the main class</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// is referenced anywhere in the current swf, things will break down (a subject for another lecture&#8230;)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> fontSource : IFontSource = <span class="br0">&#40;</span>loader.<span class="me1">content</span> as IFontSource<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// retrieve the font class from the swf.</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> <span class="kw3">font</span> : <span class="kw2">Class</span> = fontSource.<span class="me1">getFont</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// register the loaded font with the fonts list. </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">Font</span>.<span class="me1">registerFont</span><span class="br0">&#40;</span><span class="kw3">font</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>The font is now registered in the current swf and ready for use.</p>
<p>Now you can do this:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="co1">// create and populate a text field using the given text and font (which we loaded in the previous listing)</span><br />
<span class="kw2">function</span> fillTextField<span class="br0">&#40;</span><span class="kw3">text</span>:<span class="kw3">String</span>,<span class="kw3">font</span>:<span class="kw3">String</span><span class="br0">&#41;</span>:<span class="kw3">void</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// prepare a new text field</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">var</span> <span class="kw3">textField</span> : <span class="kw3">TextField</span> = <span class="kw2">new</span> <span class="kw3">TextField</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">textField</span>.<span class="kw3">width</span> &nbsp;= <span class="nu0">200</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">textField</span>.<span class="kw3">height</span> = <span class="nu0">25</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// create and assign a TextFormat using the submitted font name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">textField</span>.<span class="me1">defaultTextFormat</span> = <span class="kw2">new</span> <span class="kw3">TextFormat</span><span class="br0">&#40;</span><span class="kw3">font</span>,12,0<span class="br0">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// embed the font</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">textField</span>.<span class="kw3">embedFonts</span> = <span class="kw2">true</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// etc&#8230;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">textField</span>.<span class="kw3">text</span> = <span class="kw3">text</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; addChild<span class="br0">&#40;</span><span class="kw3">textField</span><span class="br0">&#41;</span>;<br />
<span class="br0">&#125;</span></div>
</div>
<p>There&#8217;s only one catch here. You have to be careful what font name you use. It must be the font&#8217;s internal name. Fortunately, there&#8217;s an easy way to retrieve it:</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="co1">// instantiate the font</span><br />
<span class="kw2">var</span> <span class="kw3">font</span> : <span class="kw3">Font</span> = <span class="kw2">new</span> MySpecialFont<span class="br0">&#40;</span><span class="br0">&#41;</span>;<br />
<span class="co1">// retrieve the font&#8217;s internal name</span><br />
<span class="kw2">var</span> fontName : <span class="kw3">String</span> = <span class="kw3">font</span>.<span class="me1">fontName</span>;</div>
</div>
<p>You can use fontName in the TextFormat object.</p>
<p>Now, some code:</p>
<p>Create an interface that your target movie will use to retrieve fonts.</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="kw3">public</span> <span class="kw3">interface</span> IFontSource<span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">function</span> getFont<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw2">Class</span>;</p>
<p><span class="br0">&#125;</span></div>
</div>
<p>Now make an abstract class for the font swfs. This will be a base class for the MXML application. You can use an interface in the application&#8217;s default declaration, but if you inherit from Sprite, you can drop some baggage.</p>
<div class="codesnip-container" >
<div class="actionscript codesnip" style="font-family:monospace;"><span class="kw3">public</span> <span class="kw2">class</span> FontSource <span class="kw3">extends</span> Sprite <span class="kw3">implements</span> IFontSource<span class="br0">&#123;</span></p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">public</span> <span class="kw2">function</span> getFont<span class="br0">&#40;</span><span class="br0">&#41;</span>:<span class="kw2">Class</span><span class="br0">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// not implemented yet&#8230;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">null</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></p>
<p><span class="br0">&#125;</span></div>
</div>
<p>Now, create an mxml file that implements everything. The application inherits from FontSource.</p>
<div class="codesnip-container" >
<div class="xml codesnip" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;utf-8&quot;</span><span class="re2">?&gt;</span></span><br />
<span class="sc3"><span class="re1">&lt;font:FontSource</span></span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">xmlns:mx</span>=<span class="st0">&quot;http://www.adobe.com/2006/mxml&quot;</span> </span><br />
<span class="sc3">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">xmlns:font</span>=<span class="st0">&quot;*&quot;</span><span class="re2">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;mx:Script<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc2">&lt;![CDATA[</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [Embed(systemFont=&quot;Bwhebb&quot;,fontName=&quot;hebrew&quot;,mimeType=&quot;application/x-font&quot;,unicodeRange=&quot;Hebrew&quot;)]</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public var hebrew : Class;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; public override function getFont():Class{</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return hebrew;</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span class="sc2">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ]]&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/mx:Script<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
<span class="sc3"><span class="re1">&lt;/font:FontSource<span class="re2">&gt;</span></span></span></div>
</div>
<p>The new swf contains the font class (with glyphs) and a mechanism to retrieve it.</p>
<p>In order to publish the font swf, you have to edit your [flex sdk]/frameworks/flex-config.xml file so that it contains the appropriate character ranges. Some charsets are already provided in the [flex sdk]/frameworks/flash-unicode-table.xml file. You simply copy and paste elements from this file (or create your own) and paste them into flex-config.xml.</p>
<p>In flash-unicode-table.xml, you&#8217;ll copy the language-range element (in this case, all uppercase latin characters):</p>
<div class="codesnip-container" >
<div class="xml codesnip" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;flash-unicode-table<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;language-range<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;lang<span class="re2">&gt;</span></span></span>Uppercase<span class="sc3"><span class="re1">&lt;/lang<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;range<span class="re2">&gt;</span></span></span>U+0020,U+0041-U+005A<span class="sc3"><span class="re1">&lt;/range<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/language-range<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/flash-unicode-table<span class="re2">&gt;</span></span></span></div>
</div>
<p>Paste the copied element into flex-config.xml:</p>
<div class="codesnip-container" >
<div class="xml codesnip" style="font-family:monospace;"><span class="sc3"><span class="re1">&lt;flex-config<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;languages<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;language-range<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;lang<span class="re2">&gt;</span></span></span>Uppercase<span class="sc3"><span class="re1">&lt;/lang<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;range<span class="re2">&gt;</span></span></span>U+0020,U+0041-U+005A<span class="sc3"><span class="re1">&lt;/range<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/language-range<span class="re2">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/languages<span class="re2">&gt;</span></span></span><br />
<span class="sc3"><span class="re1">&lt;/flex-config<span class="re2">&gt;</span></span></span></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robskelly.com/2008/06/dynamic-font-loading-in-flash-9/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
