<?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"
	>

<channel>
	<title>Kevin Hoyt</title>
	<atom:link href="http://blog.kevinhoyt.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.kevinhoyt.org</link>
	<description>On the desktop, on the web, on the device ... On the Platform</description>
	<pubDate>Sun, 16 Nov 2008 04:16:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
	<language>en</language>
			<item>
		<title>Determining Image Type and Dimensions</title>
		<link>http://blog.kevinhoyt.org/2008/11/14/determining-image-type-and-dimensions/</link>
		<comments>http://blog.kevinhoyt.org/2008/11/14/determining-image-type-and-dimensions/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 16:04:13 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/?p=265</guid>
		<description><![CDATA[If you have followed my blog for long, you will know that I am a bit obsessed with image processing.  It has been a while since I have posted anything on the topic, so I thought it was about time to revisit the subject.  I have a customer that has been doing a [...]]]></description>
			<content:encoded><![CDATA[<p>If you have followed my blog for long, you will know that I am a bit obsessed with image processing.  It has been a while since I have posted anything on the topic, so I thought it was about time to revisit the subject.  I have a customer that has been doing a lot with image processing, and they wanted to know how to get dimensions of an image file without having to load it onto the display list first.  While JPEG files can sometimes contain EXIF data, the customer also wanted sizing information for GIF and PNG files.<br />
<span id="more-265"></span><br />
I am most familiar with the JPEG specification, but as I looked at the complexities of the <a href="http://www.w3.org/Graphics/GIF/spec-gif89a.txt">GIF</a> and <a href="http://www.w3.org/TR/2003/REC-PNG-20031110/">PNG</a> file formats, I found that GIF was much easier than the <a href="http://www.w3.org/Graphics/JPEG/jfif3.pdf">JPEG</a> format.  For that reason, I started with GIF.  The GIF format does a really good job of telling you right up front that the format you are viewing is a GIF file.  The first six bytes are all characters that spell out “GIF” followed by the version, which is either “87a” or “89a”.</p>
<p>When I opened a GIF file up in <a href="http://www.suavetech.com/0xed/0xed.html">0xED</a>, I saw that the next few bytes seemed to reflect what I suspected was the image dimensions.  A quick check against the specification revealed exactly that - two unsigned shorts, width and height respectively.  Wow, that was easy.  Supplied a ByteArray of the image file contents, to get at this information requires only the following code to verify that the file is indeed a GIF and to determine its dimensions.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedByte</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">start</span> == <span style="color: #000000; font-weight:bold;">71</span> <span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">data</span>.<span style="color: #004993;">position</span> = <span style="color: #000000; font-weight:bold;">6</span>;
	<span style="color: #004993;">data</span>.<span style="color: #004993;">endian</span> = <span style="color: #004993;">Endian</span>.<span style="color: #004993;">LITTLE_ENDIAN</span>;
&nbsp;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Width: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedShort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Height: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedShort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I had never looked at the PNG format at all, so I was curious as to what it held for me in terms of complexity.  Though the specification is not written particularly clearly, it is still much more concise than the JPEG format.  I soon discovered that PNG files start with the same <a href="http://www.w3.org/TR/PNG/#5PNG-file-signature">eight bytes</a> that include, among other things, the characters “PNG”.  After those eight bytes comes a series of chunks.</p>
<p><a href="http://www.w3.org/TR/PNG/#5Chunk-layout">Chunks</a> are defined simply enough.  They start with a four byte integer that says how big the chunk is supposed to be.  After the length of the chunk comes four bytes that say the type of chunk being described.  Usually in these file formats, there is almost always a chunk that contains the width and height, so I scanned the chunk types in the specification.  What I found is that after the initial eight bytes of a PNG file, the first chunk is always a “<a href="http://www.w3.org/TR/PNG/#11IHDR">header</a>” block, which contains width and height as four bytes each.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedByte</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">start</span> == <span style="color: #000000; font-weight:bold;">137</span> <span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">data</span>.<span style="color: #004993;">position</span> = <span style="color: #000000; font-weight:bold;">16</span>;
&nbsp;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Width: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedInt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Height: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedInt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Now back to the JPEG file format, which I have now discovered is one seriously messed up format.  It strikes me that it ever gained the popularity that it did.  Anyways, JPEG images are designed to hold meta information.  Sometimes that is there, sometimes not.  That meta information is most commonly seen as <a href="http://park2.wakwak.com/~tsuruzoh/Computer/Digicams/exif-e.html">EXIF</a> data, but that too may also not be there.  In that case there is a subset of called JFIF which actually proceeds EXIF.</p>
<p>The JPEG image, like the PNG image is dived up into chunks as well, but the format of those chunks may actually vary from vendor to vendor.  EXIF as an example fills the meta area of a JPEG file, but its format is one that’s generally agreed on by camera vendors, and not specifically called about in the JPEG specification.  When I create a JPEG from <a href="http://www.adobe.com/go/fireworks">Fireworks CS4</a>, I even noticed that it crams a bunch of XML in the meta area - in short, it seems to create JPEG images with it’s own little piece of data.</p>
<p>This is all acceptable of course, and specifically allowed for by the specification, but makes parsing JPEG files incredibly tedious.</p>
<p>It seemed that somebody had probably already done this somewhere, so in looking for some pointers, I headed to ye olde Google.  After a little searching I ran across a <a href="http://www.64lines.com/jpeg-width-height">snippet</a> that scanned the JPEG block for a specific 0xFFC0 segment.  The first four bytes of this segment, two unisigned bytes each, contains the width and height of the JPEG file.  After a little experimenting I found that this approach actually disregarded the meta information block altogether and worked on JPEG images whether they had EXIF, JFIF, or other meta information.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> format<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0;
<span style="color: #6699cc; font-weight: bold;">var</span> marker<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0;
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">start</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedByte</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">start</span> == <span style="color: #000000; font-weight:bold;">255</span> <span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #004993;">data</span>.<span style="color: #004993;">endian</span> = <span style="color: #004993;">Endian</span>.<span style="color: #004993;">BIG_ENDIAN</span>;
	<span style="color: #004993;">data</span>.<span style="color: #004993;">position</span> = <span style="color: #000000; font-weight:bold;">3</span>;
	format = <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedByte</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">while</span><span style="color: #000000;">&#40;</span> marker <span style="color: #000000; font-weight: bold;">!</span>= 0xC0 <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #004993;">start</span> = <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedShort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span>;
		<span style="color: #004993;">data</span>.<span style="color: #004993;">position</span> = <span style="color: #004993;">data</span>.<span style="color: #004993;">position</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">start</span>;
		marker = <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedByte</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #004993;">data</span>.<span style="color: #004993;">position</span> = <span style="color: #004993;">data</span>.<span style="color: #004993;">position</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">3</span>;
&nbsp;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Height: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedShort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span> <span style="color: #990000;">&quot;Width: &quot;</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">data</span>.<span style="color: #004993;">readUnsignedShort</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You’ll notice that throughout this description, I have never called out how I was getting the data.  Perhaps because I wanted to play around more with Flash Player 10 local file IO, I first implemented this as a web application running on Flash Player.  Once I had the project completed, it occurred to me that since I was dealing with the ByteArray from the file, that it could be done with AIR as well.  </p>
<p>Rather than call out a specific runtime, I created a function that will take a ByteArray of an image file, and return to you the type of image file (GIF, PNG or JPG) as well as the width and height of the file.  If you have Flash Player 10, you can try this functionality out right below this paragraph.  Simply click the button, select one or more image files, and Flash Player 10 will read the data and tell you what you selected!</p>
<p><object width="500" height="200"><param name="movie" value="http://blog.kevinhoyt.org/wp-content/imagesizes/ImageSizes.swf"><embed src="http://blog.kevinhoyt.org/wp-content/imagesizes/ImageSizes.swf" width="500" height="200"></embed></object></p>
<p>It wouldn’t take much work of course to run this same method in an application running in <a href="http://www.adobe.com/go/air">Adobe AIR</a>.  A little more work and you could even run it as JavaScript inside Adobe AIR.  I’ve made the source code for the Flash Player version above available for <a href="/wp-content/imagesizes/srcview/ImageSizes.zip">download</a>.  If you implement it in AIR with AS3 or JavaScript, please leave a comment and let me know!  There’s a variety of sample/test images included in the download as well.  I think I’ve tested it pretty thoroughly, but if you find any images it doesn’t work for, also please leave a comment and let me know.</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/11/14/determining-image-type-and-dimensions/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reading iCalendar Files with Flash Player 10</title>
		<link>http://blog.kevinhoyt.org/2008/11/07/reading-icalendar-files-with-flash-player-10/</link>
		<comments>http://blog.kevinhoyt.org/2008/11/07/reading-icalendar-files-with-flash-player-10/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 23:07:41 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/?p=257</guid>
		<description><![CDATA[There are many compelling features in Flash Player 10, but if you are a nut about data (like me), then local file IO is probably the one that gets your attention.  It turns out that using this new feature couldn’t be easier.  There’s a couple new methods on the FileReference class and you [...]]]></description>
			<content:encoded><![CDATA[<p>There are many compelling features in Flash Player 10, but if you are a nut about data (like me), then local file IO is probably the one that gets your attention.  It turns out that using this new feature couldn’t be easier.  There’s a couple new methods on the FileReference class and you are off to the races.  I wanted to test this functionality out myself, so I built a little application to read <a href="http://en.wikipedia.org/wiki/Icalendar">iCalendar</a> files.<br />
<span id="more-257"></span><br />
<em>I want to be clear that this example is not intended to be a practical implementation of parsing iCalendar files.  While I reviewed the <a href="http://tools.ietf.org/html/rfc2445">RFC 2445</a> standard, I only grabbed the few pieces I needed for events and this specific display.  I also tested only against a specific set of sample data.  The real value of this example is in the specifics around file access.</em></p>
<p>The first thing you need to know about local file IO is that any access to the system must be driven by a user click interaction.  You are not free to go about opening files at random, or without user permission.  You can also only perform one local access per click and cannot chain the system access.  For example, you can’t save some data, and then immediately open some other file without first getting user another click event from the user.</p>
<p>The next thing to know about local file IO is that the methods are designed to work with a ByteArray object.  This is pretty clever as it gives you the flexibility to read and write any file type whether it be text, or something more complicated like an image file.  RFC 2445 files are text-based and easily human readable.  You can <a href="http://blog.kevinhoyt.org/wp-content/Nov032008.ics">download the test file</a> I used, my actual schedule for the week of Nov 3, 2008, or create your own, but for reference, here’s some sample data.</p>
<pre>
BEGIN:VCALENDAR
...
BEGIN:VEVENT
SEQUENCE:2
TRANSP:OPAQUE
UID:61BC7865-E5CF-4C7A-89A7-45B91592143B
DTSTART;TZID=America/Denver:20081103T130000
DTSTAMP:20081102T202730Z
SUMMARY:DEN to LGA
CREATED:20081102T202722Z
DTEND;TZID=America/Denver:20081103T170000
END:VEVENT
...
END:VCALENDAR
</pre>
<p>Now onto the actual implementation details.  You will first need to provide a means for the user to indicate that they want to open a local file.  In my application, I use the “+” icon in the upper right hand corner of the application.  It’s just a MovieClip instance, and I’ve registered a listener for the MouseEvent.CLICK event.  When that listener gets fired, we can prompt the user to select a local file using the FileReference.browse() method, but before we got hat far, we have some other work to do first.</p>
<p>All of these operations happen asynchronously.  When the user select a file from the browse dialog, an Event.SELECT event will be fired.  That lets us know where we can read the local data.  Reading the data though, also happens asynchronously, so we’ll need to also register for the Event.COMPLETE event, which will get fired with the local file has been loaded into a ByteArray for further processing.  You’ll find that ByteArray object on the FileReference.data property once local access has finished.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #6699cc; font-weight: bold;">var</span> ical<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">FileReference</span> = <span style="color: #0033ff; font-weight: bold;">null</span>;
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doAdded<span style="color: #000000;">&#40;</span> event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  ical = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">FileReference</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
  ical.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span>.<span style="color: #004993;">SELECT</span>, doSelect <span style="color: #000000;">&#41;</span>;
  ical.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span>.<span style="color: #004993;">COMPLETE</span>, doComplete <span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doSelect<span style="color: #000000;">&#40;</span> event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  ical.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doComplete<span style="color: #000000;">&#40;</span> event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
  <span style="color: #6699cc; font-weight: bold;">var</span> lines<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Array</span> = <span style="color: #0033ff; font-weight: bold;">null</span>;
  <span style="color: #6699cc; font-weight: bold;">var</span> file<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">String</span> = <span style="color: #0033ff; font-weight: bold;">null</span>;		
&nbsp;
  file = ical.<span style="color: #004993;">data</span>.<span style="color: #004993;">readMultiByte</span><span style="color: #000000;">&#40;</span> ical.<span style="color: #004993;">data</span>.<span style="color: #004993;">length</span>, US_ASCII <span style="color: #000000;">&#41;</span>;
  lines = file.<span style="color: #004993;">split</span><span style="color: #000000;">&#40;</span> CR_LF <span style="color: #000000;">&#41;</span>;			
&nbsp;
  <span style="color: #009900;">// ...</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The ByteArray class has a ByteArray.readMultiByte() method on it for reading strings.  You might go about using this method in any number of manner, but in this case, I just read in the all available data in the ByteArray instance as a giant string.  From there I can use the string methods to parse the details.  The RFC 2445 standard uses a carriage return and line feed marker to indicate a new line, which I use to split the string up initially.  Then I run through the lines and parse all the relevant data (again using more string manipulation).</p>
<p><object width="320" height="400"><param name="movie" value="http://blog.kevinhoyt.org/wp-content/fp10-icalendar.swf"><embed src="http://blog.kevinhoyt.org/wp-content/fp10-icalendar.swf" width="320" height="400"></embed></object></p>
<p>The great thing about using ByteArray by default is that it allows you to work with both text files and binary files.  For example, there’s no reason that an application couldn’t read or write an image file.  Other file types such as <a href="http://alivepdf.bytearray.org/">PDF</a> or SWF also seem as though they’d be particularly compelling.  Or, if you just want to write out some text, you can do that too.  It’s very flexible for your specific situation.</p>
<p>Though I didn’t use it in this example, the FileReference.save() method behaves a little differently.  Rather than have your user select the file first, you actually need to build the ByteArray object you intend to write to the local system up front.  That ByteArray instance will be passed to the FileReference.save() method.  From there the user will select where they want to put the file.  As soon as they’ve selected a destination, that ByteArray data will be written instantly.</p>
<p>There’s clearly a vast amount of potential with this feature.  Image simply not having to bounce simple data off a server anymore whenever you want to save a file locally?  The shortcoming for now being that there are few libraries in ActionScript for the countless file types that are in existence.  Perhaps now that this feature is available, we’ll see more developers create such libraries.  In the meantime, you can <a href="http://blog.kevinhoyt.org/wp-content/fp10-icalendar.zip">download the source</a> for my example.  If you expand upon it, and create a full implementation for iCalendar files, please drop me a comment and let me know.</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/11/07/reading-icalendar-files-with-flash-player-10/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Lots of Flash, Flex, and Zend, PHP Samples</title>
		<link>http://blog.kevinhoyt.org/2008/10/23/um-lots-of-flash-flex-and-zend-php-samples/</link>
		<comments>http://blog.kevinhoyt.org/2008/10/23/um-lots-of-flash-flex-and-zend-php-samples/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 21:29:19 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Flash]]></category>

		<category><![CDATA[Flex]]></category>

		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/?p=250</guid>
		<description><![CDATA[What?  PHP, Zend and Adobe goodness.  Why?  Because I’m obsessive compulsive and can’t stop myself from iterating over a problem every which way possible.  Depending on how you count it, there’s somewhere between 13 and 54 different Flash,  and/or Flex examples included in the attached archive - that doesn’t even [...]]]></description>
			<content:encoded><![CDATA[<p>What?  PHP, Zend and Adobe goodness.  Why?  Because I’m obsessive compulsive and can’t stop myself from iterating over a problem every which way possible.  Depending on how you count it, there’s somewhere between 13 and 54 different Flash,  and/or Flex examples included in the <a href="/wp-content/php-samples.zip">attached archive</a> - that doesn’t even count the different PHP examples (also included).  I started these examples in support of the Adobe and Zend <a href="http://www.zend.com/en/company/news/press/zend-to-collaborate-with-adobe">announcements</a> related to Flex Builder and AMF.  With some help from <a href="http://wadearnold.com/blog/">Wade Arnold</a> along the way, it’s now a rather overwhelming collection.<br />
<span id="more-250"></span><br />
<strong>ActionScript</strong></p>
<p>I know who you are!  You’re that guy that uses Flex Builder, but not the Flex framework.  It’s true!  It happens!  I’ll avoid the political mire that is editors in the Flash world, and just say that this example shows you how to connect to a “HelloWorld” PHP object from a pure ActionScript project developed with Flex Builder, but without the use of the Flex framework via Zend AMF.  </p>
<p><strong>Charts</strong></p>
<p>It became plenty obvious to me early on that charting solutions in the PHP world are lame.  Busting out bitmaps on demand?  Calculating dimensions, drawing lines, figuring out ranges?  Whatever!  These examples walk you through building really effective and powerful charts using the Flex Charting components.  It starts simply enough with getting some data into a LineChart.  Then we add data tips.  Then we add styles.  Then we add formatting.  Then we add filtering.  Then we add alternating views via a ViewStack.  Then we pimp it out and bring the full Zend Framework web site look and feel into a fully interactive data visualization application.</p>
<p><img src="/wp-content/zend-charts.jpg" width="600" height="428" /></p>
<p><strong>Data</strong></p>
<p>You know, because what’s a Flex application without some data?  I developed all these samples on MAMP, which includes MySQL.  If you’re using the same port information and default user name and password for your development/testing environment, then you’ll be good to go.  If you’re not, and you want to just drop the data into your own configuration, I’ve provided you with the example data in XML format, as well as a SQL dump that includes the table schema.</p>
<p><strong>Desktop</strong></p>
<p>It can seem counter intuitive at times, I know.  Didn’t we move to the web to get away from the desktop?  Regardless of the shift, there are still good reasons that the desktop matters to web developers, and when you want to go there, you can do so easily, and cross-platform with Adobe AIR.  These examples, take a Flex-based application, that connects to a PHP data access object (DAO) via Zend AMF to the desktop with Adobe AIR.  You’ll start with a basic web version, just shoved into an AIR window.  Then you’ll add native drag and drop to upload a vCard file.  Then you’ll check to see if the network is even available.  Then you’ll just work offline entirely using the embedded SQLite database that’s part of AIR.  Sample vCards provided!</p>
<p><img src="/wp-content/air-php-flex.jpg" width="580" height="477" /></p>
<p><strong>External</strong></p>
<p>Nobody likes code that’s hard to maintain.  So what’s the first thing you’ll do to take that old-school procedural code and make it maintainable?  That’s right, you’ll pull all the core logic out to a separate PHP file and then include that file wherever you need that functionality.  That’s what this example shows.  On the server, in PHP-land, all the core database access is put aside in it’s own comfy script.  That script is then included in numerous additional PHP files that expose functionality as XML.  To help you get along, there’s incremental builds for every step of the flex application - from getting that initial set of data to a complete CRUD application.</p>
<p><strong>Flash</strong></p>
<p>Did you know that the Flash authoring environment has included components for a long time?  They’re of a different nature than the Flex components, but they are there; great for one-off application style functionality in any otherwise immersive experience you might be creating.  Presented here are two complete applications that use those components, and the supporting FLA files for Flash CS3 and Flash CS4.  One of the applications connects to PHP via XML, while the other via Zend AMF.  I make heavy use of the “document class” concept, so prepare yourself for ActionScript 3 goodness.</p>
<p><img src="/wp-content/flash-cs4-php.jpg" width="600" height="452" /></p>
<p><strong>Hello AMF</strong></p>
<p>What could be better than good old fashioned “hello world?”  The “ActionScript” example goes at Zend AMF using a pure ActionScript project.  This example uses the Flex framework to connect to that “HelloWorld” PHP class Zend AMF.  Sometimes you just need the basics to get you going, and if all the staged builds and various approaches have you down, this is the place to start.</p>
<p><strong>Hello Text</strong></p>
<p>You don’t see it done too often, but there’s no reason that our service calls from Flex have to be XML, SOAP or AMF.  If you’d prefer to just get a bunch of text back, and process that data yourself, then be our guest.  This example shows connecting Flex to a PHP endpoint that returns a plain text string.  In this example, that value is just dumped to the screen, but you could use this approach to deal with comma-separated values (CSV) or any other text that might be provided by a service endpoint you don’t control.</p>
<p><strong>Hello XML</strong></p>
<p>This is the de facto standard when it comes to services and Flash.  You send a query string out with your HTTP request, and you get XML data back.  Flash Player of course has really good XML manipulation via ECMAScript for XML (E4X).  In this example, you’ll pass that query string to a PHP resource, that will process it and return some data in XML.  Quick, two guesses, what the response will say!</p>
<p><strong>Inline</strong></p>
<p>You weren’t always the magic code man that you are today.  You had to start somewhere.  Or perhaps you’re maintaining code that was somebody else’s starting point.  The most common way to get going before you understand the value of modularity and code reuse is to cram everything into one PHP file and just get the job done.  This example covers that situation.  If you’re inclined to shove everything into one PHP script, this example builds out a complete CRUD application using XML as a return format to satisfy every brute force craving you might have.</p>
<p><strong>Object</strong></p>
<p>Yes!  It’s true!  PHP can be object oriented!  I still hear biases that PHP is procedural, and this example sets out to prove that wrong.  On the PHP side you’ll get patterned to death by creating a DAO that uses a Factory (helper) to connect to a database, and then uses value objects (VO) in place of the traditional associative arrays.  That well constructed object oriented infrastructure is then used to return XML to a Flex client.  On the client side, once again, staged builds of a complete CRUD application are provided to gently walk you along learning Flex.</p>
<p><strong>Remoting</strong></p>
<p>AMF in general likes objects, and Zend AMF is no exception.  In the “Object” example, there’s an additional PHP script for each CRUD operation.  That means more work for you to expose you’re wonderfully OO code as dumb XML.  XML in it’s own right is just downright heavy too - especially as it applies to the enterprise.  In this example we’ll take the classes from the “Object” example and expose them via Zend AMF to a Flex application.  Just because I can, staged builds are included here too, to walk you along building a Flex application with complete CRUD operations.</p>
<p><strong>REST</strong></p>
<p>You say “tomato” and I say “tomato” &#8230; Er, something like that.  The Zend Framework includes REST server functionality.  While it’s not true REST, and uses the old query string in, XML out approach, we’re still talking XML, which is what we want when we’re building Flex applications.  There are two examples here that use the Zend REST server functionality.  Leveraging the externalized script from the “External” example, we can immediately expose that functionality as XML.  You get one example that does that, but the problem is that the result isn’t in a format that’s especially friendly to iteration.  Then there’s another example that shows customizing the XML response from the Zend REST server to be more palatable to an SOA application.  And yes, staged builds for complete CRUD functionality are provided here too.</p>

<div class="wp_syntax"><div class="code"><pre class="xml xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;getContacts</span> <span style="color: #000066;">generator</span>=<span style="color: #ff0000;">&quot;zend&quot;</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key_0<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;firstname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Ryan<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/firstname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Stewart<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;email<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>rstewart@adobe.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/email<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mobile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>123-456-7890<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mobile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key_0<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key_1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;firstname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Mike<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/firstname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;lastname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Downey<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/lastname<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;email<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>mdowney@adobe.com<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/email<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mobile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>111-222-3333<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mobile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key_1<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>success<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/status<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/getContacts<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><strong>Upload</strong></p>
<p>Flash Player has included the ability to upload and download files for a while.  The great thing about this functionality is that it allows you to specify a single or multiple file mode, and also lets you filter out files that you don’t want the user to select.  While the upload/download is going, you also get progress reports.  It’s among the most common uses for Flash, and as such here’s an example of how to use the upload functionality from a Flex application to a PHP endpoint.  This example expects you to upload a vCard (samples provided) to PHP, which then parses the data, puts a record in the database, and returns the details about the new record back to the client for display.</p>
<p><img src="/wp-content/upload-dialog-php.jpg" width="598" height="480" /></p>
<p>The problem with examples like these is that there’s just never enough time to iterate over the code in every possible way (despite my obsession).  Still on my list include using the Zend Framework MVC component to provide alternative presentations for the same logic, as well as real-time support using a custom socket server (written in PHP as well of course).  I see a little chat and collaboration in my future.  I’ll make another post to update the code when I get there.  In the meantime, if there’s an example of functionality you’d like to see, then leave a comment a let me know!</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/10/23/um-lots-of-flash-flex-and-zend-php-samples/feed/</wfw:commentRss>
		</item>
		<item>
		<title>jQuery Conference 2008 Audio</title>
		<link>http://blog.kevinhoyt.org/2008/10/08/jquery-conference-2008-audio/</link>
		<comments>http://blog.kevinhoyt.org/2008/10/08/jquery-conference-2008-audio/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 22:19:42 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/?p=241</guid>
		<description><![CDATA[I had the honor and privilege to attend and present at jQuery Conference 2008 the weekend before The Ajax Experience in Boston.  I wasn’t sure what to expect going in, but found the event well attended.  The sessions were broken into two tracks, beginner and advanced, filled with authorities on jQuery.  I [...]]]></description>
			<content:encoded><![CDATA[<p>I had the honor and privilege to attend and present at <a href="http://jquery.com/blog/2008/08/31/jquery-conference-2008-agenda/">jQuery Conference 2008</a> the weekend before <a href="http://ajaxexperience.techtarget.com/east/index.html">The Ajax Experience</a> in Boston.  I wasn’t sure what to expect going in, but found the event well attended.  The sessions were broken into two tracks, beginner and advanced, filled with authorities on jQuery.  I took my little audio recorder with me to the event, and walked away with three sessions to share.<br />
<span id="more-241"></span><br />
<strong>Learning jQuery</strong> (<a href="/wp-content/interviews/learning-jquery.mp3">audio</a>)</p>
<p>In this session, <a href="http://www.karlswedberg.com/">Karl Swedberg</a>, author of the well-known “<a href="http://www.learningjquery.com/">Learning jQuery</a>” book gets you started with jQuery.  Karl had a number of projector problems up front, so this session isn’t as long as the other two.  As you would expect, this session is a very gentle introduction to using jQuery.  Karl started off with his own slides, and then moved into using some available from John Resig.  I really felt like Karl hit his stride about the last fifteen minutes, but unfortunately ran out of time.  This is one of those sessions I wish had gone on for another hour.</p>
<p><strong>Introduction to jQuery UI</strong> (<a href="/wp-content/interviews/jquery-ui.mp3">audio</a>)</p>
<p>If you follow jQuery, you’ll know that there has been working on a user interface suite of components called <a href="http://ui.jquery.com/">jQuery UI</a>.  The UI project is still very much in its infancy, and has lots of room to grow, but in this session <a href="http://rdworth.org/blog/">Richard Worth</a> gives a good introduction to where the team is so far.  The occasional one-off comment about why the project is architected one way versus another was probably the most valuable part for me.  <a href="http://www.adobe.com/products/dreamweaver/">Dreamweaver CS4</a> supports  OpenAjax Metadata <a href="http://www.openajax.org/member/wiki/OpenAjax_Metadata_Specification_Widget_Metadata">Specification</a> Widget Metadata, and you can expect to see a number of the jQuery UI components available as extensions (and more from other frameworks).</p>
<p><strong>Building Your First Plug-In</strong> (<a href="/wp-content/interviews/jquery-plugins.mp3">audio</a>)</p>
<p>My favorite feature of jQuery is that it is very unobtrusive to my workflow.  If find that the minimalist approach works very well for me when building <a href="http://www.adobe.com/products/air/">Adobe AIR</a> applications.  My second favorite feature then is the plug-in architecture, which has created a vibrant community.  If you’re looking for some feature for your application, chances are that a plug-in already exists.  Probably the most thorough session I attended during the conference, <a href="http://malsup.com/jquery/">Mike Alsup</a> walks you through all the details of making your own plug-ins for jQuery.</p>
<p>There was much to like about the conference.  I like the location (Boston), the timing (just before The Ajax Experience), the content (jQuery), the community, the meals (breakfast, lunch and dinner), the venue (MIT STATA), and more.  One area that I thought the conference might improve is to have an intermediate track.  There were a few cases where the beginner was too beginner, and the advanced too advanced.  It would have been great to find a middle ground for sessions as well.  Other than that, I look forward to attending next year.  </p>
<p><img alt="" src="/wp-content/campout-v1.jpg" title="Campout Screenshot" class="alignnone" width="600" height="340" /></p>
<p>In the meantime, you can <a href="/wp-content/campout-jquery.zip">download</a> the jQuery/AIR example I put together for the conference.  The application is an early version of a desktop application I&#8217;ve been working on to monitor a specific set of RSS feeds - those from my reports.  It includes all the assets necessary to roll the web-based version of the application (using PHP on the server) to a desktop application using Adobe AIR.  The bits in the archive are in that final state and includes custom chrome, local file IO, system notifications and network detection - all using jQuery and AIR.  Enjoy!</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/10/08/jquery-conference-2008-audio/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Flash 9-Slice Meets CSS 3</title>
		<link>http://blog.kevinhoyt.org/2008/10/06/flash-9-slice-meets-css-3/</link>
		<comments>http://blog.kevinhoyt.org/2008/10/06/flash-9-slice-meets-css-3/#comments</comments>
		<pubDate>Mon, 06 Oct 2008 17:04:01 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/?p=233</guid>
		<description><![CDATA[Here’s the problem.  You have an image that measures 100 pixels wide by 100 pixels high.  You want to use that as the border for content that measures 300 pixels wide by 300 pixels high.  What do you do?  Well, you chop that image up and then try to position the [...]]]></description>
			<content:encoded><![CDATA[<p>Here’s the problem.  You have an image that measures 100 pixels wide by 100 pixels high.  You want to use that as the border for content that measures 300 pixels wide by 300 pixels high.  What do you do?  Well, you chop that image up and then try to position the corners in the appropriate space without distorting them, and then fill out the rest with the parts that won’t be distorted by stretching.  Or, you have your software do that for you.  This is what’s called 9-slice in Flash Player, and is coming to a browser near you via the CSS 3 specification.<br />
<span id="more-233"></span><br />
Before we get into the details, let’s revisit the whole “chop that image up” statement.  Below is an example of an image that represents the “skin” or border appearance of a panel control in my application.  The image itself measures 104 x 126 pixels.  That doesn’t mean that all your panels need to be 104 x 126, just that you’ll probably have to do some additional work to get it to fit.  </p>
<p><img alt="" src="/wp-content/desktop_panel.jpg" title="Desktop Panel" class="alignnone" width="104" height="126" /></p>
<p>The popular convention is to chop off the segments that need to stay the same, and can’t be distorted.  Then you can take the areas that can be repeated, or stretched, without distortion impacting how they look.  This is generally accomplished by slicing the image up into three top segments, three middle segments, and three bottom segments using your favorite image editor.  The result is nine separate images.  We can then reassemble the image files to fit whatever size we may need, and the result will appear to not have been distorted.</p>
<p><img alt="" src="/wp-content/desktop_panel_slices.jpg" title="Desktop Panel Sliced" class="alignnone" width="150" height="150" /></p>
<p>In the case of Flash, this technique was added as a feature with Flash Player 8 called 9-slice.  Using tooling or ActionScript, you can specify where the slice guidelines fall, and then Flash will handle slicing the guides, stretching the images appropriately, and then reassemble all the parts at the final dimensions.  In Flash CS4 you can find this on your symbol properties, and then selecting to enable “9-slice.”  You will then see slicing guides on your symbols.  Try it!  Take the transform tool and resize a rounded rectangle.  If you’ve set the guides correctly, the rounded corners will retain their radius.</p>
<p><img alt="" src="/wp-content/flash_transforms.gif" title="Examples of Slicing" class="alignnone" width="600" height="175" /></p>
<p>In HTML/CSS there’s no such feature.  Well, there was no such feature until browsers started implementing <a href="http://www.w3.org/TR/2008/WD-css3-background-20080910/">CSS 3</a>.  CSS 3 includes a variety of new background and border features, one of which is the “<a href="http://www.w3.org/TR/2008/WD-css3-background-20080910/#the-border-image">border-image</a>” property.  The border image property expects you to (a) specify border widths and then (b) specify an image to use.  You’ll also tell CSS where you want the slicing to occur on the border image.  You can even tell CSS how you want the parts that do get distorted to actually distort.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* top right bottom left */</span>	
<span style="color: #cc00cc;">#chrome</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>;
	<span style="color: #000000; font-weight: bold;">bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span>;
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span>;
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span>;
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span>;
	<span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">59</span> <span style="color: #cc66cc;">17</span> <span style="color: #cc66cc;">17</span> <span style="color: #cc66cc;">17</span>; 
	-webkit-border-image<span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/desktop_panel.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #cc66cc;">59</span> <span style="color: #cc66cc;">17</span> <span style="color: #cc66cc;">17</span> <span style="color: #cc66cc;">17</span> stretch stretch;	
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>CSS 3 isn’t complete.  It’s also not broadly available as browsers that support it haven’t been on the market that long.  That doesn’t mean that this is just wasted knowledge - especially as it pertains to <a href="http://www.adobe.com/go/air">Adobe AIR</a>.  One of the browsers that does support this functionality already is Safari.  Safari uses WebKit as it’s rendering engine.  The same WebKit in built into Adobe AIR.  That means you can use this style property in Adobe AIR (as well as many others you’ll find in the CSS 3 specification).</p>
<p>One of my favorite way to use this is to skin custom window chrome and custom button chrome.  Going all the way back to that panel image I mentioned earlier, even though it is only 104 x 126 pixels, I can now have the browser slice and dice it to fit whatever size the window of my AIR application may be (certainly larger than 104 x 126).  I also don’t particularly like the AIR default button look/feel, nor do I like making a fixed size/labeled image for every button in my application.  Using CSS 3 border image, I can take an image and apply it to fit any size of button.</p>
<p><img alt="" src="/wp-content/css-chrome.jpg" title="AIR custom chrome with CSS3" class="alignnone" width="363" height="285" /><br />
(<a href="/wp-content/css-chrome-template.zip">download</a> this custom chrome template)</p>
<p>The big picture here is that Flash Player has been slicing images for a while now.  We’re now seeing that innovation roll into standards.  Somebody had to go first, and Flash took that step.  It was the same with the image tag in HTML, which at the time was hotly debated when it was added by Netscape.  It’s also important to remember though that standards invite a larger group to contribute to an innovation.  CSS 3 as an example accounts for several manners of treating the way the slices are applied to a border (stretch, repeat and round) which Flash does not.  It’s important to recognize that standards and proprietary innovation both have their place.</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/10/06/flash-9-slice-meets-css-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adobe Does Ajax (Experience)</title>
		<link>http://blog.kevinhoyt.org/2008/09/24/adobe-does-ajax-experience/</link>
		<comments>http://blog.kevinhoyt.org/2008/09/24/adobe-does-ajax-experience/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 17:15:28 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[AIR]]></category>

		<category><![CDATA[Ajax]]></category>

		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/?p=226</guid>
		<description><![CDATA[I find pretty regularly that developers tend to confuse Adobe and Flash.  Adobe is a company.  Flash is a technology.  Flash is just one of the 70+ technologies that Adobe, the company, makes.  JavaScript developers that ignore the rest of what Adobe has to offer because of its association with Flash, [...]]]></description>
			<content:encoded><![CDATA[<p>I find pretty regularly that developers tend to confuse Adobe and Flash.  Adobe is a company.  Flash is a technology.  Flash is just one of the 70+ technologies that Adobe, the company, makes.  JavaScript developers that ignore the rest of what Adobe has to offer because of its association with Flash, do themselves a great disservice.  As a point in case, Adobe is sponsoring and presenting at the two most well known Ajax conferences this year.<br />
<span id="more-226"></span><br />
The first conference is <a href="http://ajaxexperience.techtarget.com/html/index.html">The Ajax Experience</a> in Boston, MA on September 29 through October 1.  I’ll be present at this conference to introduce the framework summits for <a href="http://ajaxexperience.techtarget.com/east/html/frameworks.html#jQuery">jQuery</a>, <a href="http://ajaxexperience.techtarget.com/east/html/frameworks.html#Dojo">Dojo</a> and <a href="http://ajaxexperience.techtarget.com/east/html/frameworks.html#Prototype">Prototype</a>.  While there I’ll be presenting two sessions; one on what’s new in <a href="http://ajaxexperience.techtarget.com/east/html/quality.html#KHoytDream">Dreamweaver CS4</a> and the other on getting started building your first application with <a href="http://ajaxexperience.techtarget.com/east/html/client.html#KHoytAir">Adobe AIR</a>.  I also have an interview scheduled with <a href="http://galbraiths.org/blog/">Ben Galbraith</a> and <a href="http://almaer.com/blog/">Dion Almaer</a> to talk about everything from “Flex versus Ajax” to “open source Flash.”  Adobe will also be recording all of the 50+ sessions for redistribution.</p>
<p>Although certainly not as large an event, I’ll also be at <a href="http://jquery.com/blog/2008/08/31/jquery-conference-2008-agenda/">jQuery Conference</a> the preceding Sunday.  I’m excited to learn more about jQuery, but I’ll also be there to show off my latest application called “What Now” and talk about how jQuery and Adobe AIR made it possible.  While I’m still refining the application (yes, with only a few days to go), here’s an early sneak peak at one of the screens.  The application includes features such as custom chrome, running as a background process, system notifications, local data storage, network availability detection and more.</p>
<p><img src="http://blog.kevinhoyt.org/wp-content/uploads/whatnow-alpha.jpg" alt="" title="What Now Alpha" width="500" height="348" class="aligncenter size-full wp-image-227" /></p>
<p>The second major conference at which you’ll find Adobe, the company, is the<a href="http://ajaxworld.com/"> AJAXWorld RIA Conference</a>.  I won’t be at AJAXWorld this time around, my first time missing the conference in a few years, but another Kevin will be on hand to give a keynote presentation - <a href="http://ajaxworld.com/general/keynotes1008.htm">Kevin Lynch</a>, CTO at Adobe.  I’m not going to spill the beans about Kevin’s presentation, but he doesn’t like to take the stage without having an announcement to make.  </p>
<p>To my earlier point, the reason for Adobe being at these conferences isn’t about converting JavaScript developers to Flash.  The reason is that Adobe has a mission to change the way people engage with ideas and information.  We have runtimes, tools, servers and services to facilitate every aspect of that mission for every type of designer and developer.  On the JavaScript side of the house this might mean everything from Adobe’s involvement in <a href="http://opensource.adobe.com/wiki/display/site/Projects#Projects-ProjectsTamarin">Tamarin</a> (let’s not forget where all these speed improvements in JavaScript are coming from), <a href="http://www.adobe.com/products/dreamweaver/?promoid=BPDEC">Dreamweaver CS4</a> with amazing new CSS and JavaScript features, to <a href="http://www.adobe.com/products/coldfusion/">ColdFusion’s</a> most excellent Ajax forms and JSON support, to emerging efforts like <a href="https://acrobat.com/#/share/ShareBegin">Adobe Share</a> with its REST <a href="http://learn.adobe.com/wiki/display/acds/Document+Services;jsessionid=D353D188FD1E8855478AC98E8E3885B8">API</a>.</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/09/24/adobe-does-ajax-experience/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Adobe, Zend and Ed Finkler</title>
		<link>http://blog.kevinhoyt.org/2008/09/22/adobe-zend-and-ed-finkler/</link>
		<comments>http://blog.kevinhoyt.org/2008/09/22/adobe-zend-and-ed-finkler/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 15:11:10 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/?p=221</guid>
		<description><![CDATA[Last week Adobe and Zend made a couple of really great announcements.  The first was official addition of AMF (remoting) to the Zend Framework via Zend AMF.  If you’re an AMFPHP fan, you’ll be happy to hear that Wade Arnold is heavily involved in this project.  The other announcement was the two [...]]]></description>
			<content:encoded><![CDATA[<p>Last week <a href="http://www.adobe.com/">Adobe</a> and <a href="http://www.zend.com/en/">Zend</a> made a couple of really great announcements.  The first was official addition of <a href="http://download.macromedia.com/pub/labs/amf/amf3_spec_121207.pdf">AMF</a> (remoting) to the <a href="http://framework.zend.com/">Zend Framework</a> via Zend AMF.  If you’re an <a href="http://www.amfphp.org/">AMFPHP</a> fan, you’ll be happy to hear that <a href="http://www.wadearnold.com/blog/">Wade Arnold</a> is heavily involved in this project.  The other announcement was the two companies working together to have <a href="http://www.adobe.com/products/flex/features/flex_builder/">Flex Builder</a> run inside <a href="http://www.zend.com/en/products/studio/">Zend Studio</a>.  We still have some QE work to do here, but this promises a seamless workflow for rich client developers.<br />
<span id="more-221"></span><br />
<a href="http://theflashblog.com/">Lee Brimelow</a> and myself were on hand for most of the Zend Conference in Santa Clara, CA, and spent a substantial amount of time in the exhibit hall answering questions about Adobe, Flex and AMF, and what they have to do with PHP.  Probably the most common question was simply “what is Flex?”  I think everybody has their way of describing Flex in a very succinct manner, but for Lee it was “Flash for developers” and for me it was “PowerBuilder for the web.”  It all depends on the background of the person that’s asking of course (and answering), but that’s generally enough to lay the foundations for a more elaborate explanation and discussion.</p>
<p>While at the conference, I tried to attend a few sessions.  The booth traffic was enough though that getting out of the exhibit hall proved challenging at times.  Since the exhibits closed up on Wednesday night, but there was still more conference on Thursday, I decided that’d be my first, best, and potentially only chance to sit in on a session.  As luck would have it, the first session I ran across was one by <a href="http://funkatron.com/">Ed Finkler</a> entitled “Building Desktop RIAs with PHP, HTML, &#038; JavaScript in AIR.”  I’m pretty sure he was going for a title that completely filled the first slide.</p>
<p>Although I was unable to attend, I do know that Ed also presented other topics including another one that included Adobe AIR at the Zend un-conference.  If you’re not familiar with Ed, he has an application called <a href="http://funkatron.com/spaz">Spaz</a>, built on <a href="http://www.adobe.com/products/air/">Adobe AIR</a>.  Spaz is an award-winning Twitter client written using HTML, JavaScript and CSS.  It has been a real treat to watch it evolve since AIR has been available.  </p>
<p>I really like that during Ed’s session at Zend Con that he repeatedly emphasized AIR’s focus on security, and how developers and framework teams should stop using dangerous practices such as reliance on the eval() method.  Ed’s tie back into PHP here was that “PHP is your server-side buddy” with a picture of <a href="http://en.wikipedia.org/wiki/Jay_and_Silent_Bob">Jay and Silent Bob</a>.  Showing off a new, and somewhat controversial <a href="http://dearzend.com/">application</a>, Ed talked about how the Flash APIs in AIR can give you some image manipulation abilities.  Since Ed doesn’t know Flash however, he sends images to PHP to be manipulated.  That’s a great point about AIR being built on web technologies - use what you know.</p>
<p>Ed has made his <a href="http://www.slideshare.net/funkatron/building-desktop-rias-with-php-html-javascript-in-air-presentation">slides</a> available, and I was also able to record the session <a href="http://blog.kevinhoyt.org/wp-content/interviews/air-and-php.mp3">audio</a>.</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/09/22/adobe-zend-and-ed-finkler/feed/</wfw:commentRss>
<enclosure url="http://blog.kevinhoyt.org/wp-content/interviews/air-and-php.mp3" length="57245343" type="audio/mpeg" />
		</item>
		<item>
		<title>Ignite Denver and a Cigar BOF at MAX?</title>
		<link>http://blog.kevinhoyt.org/2008/09/16/ignite-denver-and-a-cigar-bof-at-max/</link>
		<comments>http://blog.kevinhoyt.org/2008/09/16/ignite-denver-and-a-cigar-bof-at-max/#comments</comments>
		<pubDate>Tue, 16 Sep 2008 17:10:41 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[Entertainment]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/?p=215</guid>
		<description><![CDATA[Last week I got to attend and present at the first annual Ignite Denver.  The geek crowd made a strong showing, nearing almost one-hundred (100) at Fado’s Irish Pub.  My most memorable moments involve the Irish band who was clueless as to who in their right mind would get so excited about a [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I got to attend and present at the first annual <a href="http://ignitedenver.blogspot.com/">Ignite Denver</a>.  The geek crowd made a strong showing, nearing almost one-hundred (100) at <a href="http://www.fadoirishpub.com/">Fado’s Irish Pub</a>.  My most memorable moments involve the Irish band who was clueless as to who in their right mind would get so excited about a presentation.  As <a href="http://www.johnwilker.com/j/index.cfm">John Wilker</a> noted after the event, clearly they didn’t know the presentation topics included everything from “<a href="http://www.slideshare.net/jwilker/ignite-denver-ignite-a-cigar-presentation">Ignite a Cigar</a>” to “<a href="http://www.slideshare.net/jwilker/ignite-denver-swearing-in-french-presentation/">How to Swear in French</a>.”<br />
<span id="more-215"></span><br />
The slides are all <a href="http://www.slideshare.net/jwilker/tags/ignitedenver">available</a> from the event.  I recorded the audio of most of the presentations, and it sounds like despite the background noise of a pub, some of it may actually be salvageable.  I’ll try and get to that in due time, but I thought I’d also post a more comprehensive version of my presentation “<a href="http://www.slideshare.net/jwilker/ignite-denver-ignite-a-cigar-presentation">Ignite a Cigar</a>.”  This deck is the original outline that I eventually slimmed up to a five-minute script, and contains a lot of the information that may not otherwise come out in the final Ignite deck.  </p>
<div style="width:425px;text-align:left" id="__ss_600361"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/khoyt/ignite-a-cigar-technical-presentation?type=powerpoint" title="Ignite a Cigar (Technical)">Ignite a Cigar (Technical)</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=ignite-a-cigar-technical-1221539420401132-9&#038;stripped_title=ignite-a-cigar-technical-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=ignite-a-cigar-technical-1221539420401132-9&#038;stripped_title=ignite-a-cigar-technical-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View SlideShare <a style="text-decoration:underline;" href="http://www.slideshare.net/khoyt/ignite-a-cigar-technical-presentation?type=powerpoint" title="View Ignite a Cigar (Technical) on SlideShare">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own.</div>
</div>
<p>It’s true that this was really my coming out as a cigar smoker.  It has been a past time of mine for a long time, but I’ve rarely found others in this political climate with whom I can enjoy a fine stogie.  Over the past year, I’ve found more and more that Adobe developers and designers are turning to cigars as a luxury item and an opportunity to talk geek with each other.  As <a href="http://en.wikipedia.org/wiki/William_Thackeray">William Thackeray</a> said:</p>
<blockquote><p>I vow and believe that the cigar has been one of the greatest creature comforts of my life &#8212; a kind companion, a gentle stimulant, an amiable anodyne, a cementer of friendship.</p></blockquote>
<p>With that in mind, I am very seriously considering hosting a Cigar BOF at <a href="http://max.adobe.com/na/experience/#?s=0&#038;p=0">MAX</a>.  As you probably know, California and indeed San Francisco itself isn’t a particularly friendly environment for smokers.  Rather than host this BOF in the Moscone, which would mean no smoking, what I’d really like to do is arrange a specific venue just for us.  There are a couple places that are open to cigar smokers in San Francisco, but I can’t commit to reservations if there’s not enough interest.</p>
<p>So &#8230; Of the roughly five-thousand of you attending MAX this year in San Francisco, how many would be interested in a Cigar BOF event?  Geeks and cigars is sure to be a fantastic event, but I won’t be able to pull it off without your support.  So sound off!  Leave a comment!  Let me know if you’re interested in attending.  Knowing just how serious you are would also be helpful.  There’s an off chance that I may be able to get a tobacconist to throw in a discount or sponsorship, so throw in a reference to your favorite cigar as well!  Of late I&#8217;ve been on a big <a href="http://www.epinions.com/reviews/Romeo_Y_Julieta_Churchill_Tubo">Romeo y Julieta 1875 en Tubo</a> kick myself.</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/09/16/ignite-denver-and-a-cigar-bof-at-max/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Basic Computer Vision and Flash Player 10</title>
		<link>http://blog.kevinhoyt.org/2008/08/25/basic-computer-vision-and-flash-player-10/</link>
		<comments>http://blog.kevinhoyt.org/2008/08/25/basic-computer-vision-and-flash-player-10/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 20:29:26 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/2008/08/25/basic-computer-vision-and-flash-player-10/</guid>
		<description><![CDATA[After a bit of a delay, I’m finally beginning to play with Flash Player 10.  It was a bit of a false start for me when the betas first hit the streets because tooling options weren’t particularly polished, and I still had Flash Player 9 projects on my to-do list.  Another big question [...]]]></description>
			<content:encoded><![CDATA[<p>After a bit of a delay, I’m finally beginning to play with <a href="http://labs.adobe.com/technologies/flashplayer10/">Flash Player 10</a>.  It was a bit of a false start for me when the betas first hit the streets because tooling options weren’t particularly polished, and I still had Flash Player 9 projects on my to-do list.  Another big question was where to start.  Like most people I landed on the new 2.5D features, and then tried to add something new using a web camera to control the rotation of a display object.<br />
<span id="more-211"></span><br />
Image processing has always been a favorite subject of mine.  I don’t have the math or computer science skills to really make it sing, but I manage just the same.  For this example I wanted to leverage basic <a href="http://en.wikipedia.org/wiki/Computer_vision">computer vision</a>.  I would have the web camera capture a specific color and then track that color throughout the coverage area.  Depending on where the color was found to be most dominant in the images from the web camera, 2.5D rotations would be made to an image (otherwise displayed as a pane).</p>
<p>The first step is to provide an area for the user to provide a color sample.  I chose a 10 x 10 pixel space, and represented that on the screen as a little square in the middle of the web camera display.  When something enters that space, the color across the 100 pixels is averaged.  When you get the color you want, you can press the space bar to “lock in” your color average.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> sampleImage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> bmpd<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span> VIDEO_WIDTH, VIDEO_HEIGHT <span style="color: #000000;">&#41;</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> capture<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span> CAPTURE_WIDTH, CAPTURE_HEIGHT <span style="color: #000000;">&#41;</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> pixel<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> r<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> g<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">b</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> totalr<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> totalg<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> totalb<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;			
&nbsp;
	bmpd.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span> video <span style="color: #000000;">&#41;</span>;
	capture.<span style="color: #004993;">copyPixels</span><span style="color: #000000;">&#40;</span> 
		bmpd, 
		<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Rectangle</span><span style="color: #000000;">&#40;</span> 
			sample.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> video.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span>, 
			sample.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> video.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span>, 
			CAPTURE_WIDTH <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span>, 
			CAPTURE_HEIGHT <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #000000; font-weight:bold;">1</span> <span style="color: #000000;">&#41;</span>, 
		<span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">Point</span><span style="color: #000000;">&#40;</span> 0, 0 <span style="color: #000000;">&#41;</span> 
	<span style="color: #000000;">&#41;</span>;
&nbsp;
	swatch.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
	swatch.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span>, 0xFF0000, 0 <span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> h<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0; h <span style="color: #000000; font-weight: bold;">&lt;</span> capture.<span style="color: #004993;">height</span>; h<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> w<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0; w <span style="color: #000000; font-weight: bold;">&lt;</span> capture.<span style="color: #004993;">width</span>; w<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			pixel = capture.<span style="color: #004993;">getPixel</span><span style="color: #000000;">&#40;</span> w, h <span style="color: #000000;">&#41;</span>;
&nbsp;
			r = <span style="color: #000000;">&#40;</span> pixel <span style="color: #000000; font-weight: bold;">&amp;</span> 0xFF0000 <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">16</span>;
			totalr = totalr <span style="color: #000000; font-weight: bold;">+</span> r;
&nbsp;
			g = <span style="color: #000000;">&#40;</span> pixel <span style="color: #000000; font-weight: bold;">&amp;</span> 0x00FF00 <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">8</span>;
			totalg = totalg <span style="color: #000000; font-weight: bold;">+</span> g;
&nbsp;
			<span style="color: #004993;">b</span> = pixel <span style="color: #000000; font-weight: bold;">&amp;</span> 0x0000FF;					
			totalb = totalb <span style="color: #000000; font-weight: bold;">+</span> <span style="color: #004993;">b</span>;					
&nbsp;
			swatch.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span> w <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">10</span>, h <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">10</span> <span style="color: #000000;">&#41;</span>;
			swatch.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span> pixel <span style="color: #000000;">&#41;</span>;
			swatch.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span> w <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">10</span>, h <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight:bold;">10</span>, <span style="color: #000000; font-weight:bold;">9</span>, <span style="color: #000000; font-weight:bold;">9</span> <span style="color: #000000;">&#41;</span>;
			swatch.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	r = <span style="color: #004993;">Math</span>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span> totalr <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">&#40;</span> capture.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">*</span> capture.<span style="color: #004993;">height</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
	g = <span style="color: #004993;">Math</span>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span> totalg <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">&#40;</span> capture.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">*</span> capture.<span style="color: #004993;">height</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">b</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">round</span><span style="color: #000000;">&#40;</span> totalb <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">&#40;</span> capture.<span style="color: #004993;">width</span> <span style="color: #000000; font-weight: bold;">*</span> capture.<span style="color: #004993;">height</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;			
&nbsp;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
&nbsp;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span> 0, 0 <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span>, 0x838383 <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span> 0xE8E8E8 <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span> 0, 0, <span style="color: #000000; font-weight:bold;">24</span>, <span style="color: #000000; font-weight:bold;">20</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;			
&nbsp;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">moveTo</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">3</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">lineStyle</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">1</span>, 0xFF0000, 0 <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">beginFill</span><span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span> 0x000000 | r <span style="color: #000000; font-weight: bold;">&lt;&lt;</span> <span style="color: #000000; font-weight:bold;">16</span> | g <span style="color: #000000; font-weight: bold;">&lt;&lt;</span> <span style="color: #000000; font-weight:bold;">8</span> | <span style="color: #004993;">b</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">drawRect</span><span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">3</span>, <span style="color: #000000; font-weight:bold;">19</span>, <span style="color: #000000; font-weight:bold;">15</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #004993;">select</span>.<span style="color: #004993;">graphics</span>.<span style="color: #004993;">endFill</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;			
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>At that point the application start sampling the entire image for the strongest impression of that color average.  I was originally sampling 10 x 10 pixel areas and averaging, but found accuracy and ease of use increased significantly when I just looked for the closest match to every pixel in the web camera’s coverage area.  This does of course mean that the smaller the web camera space, the more performance you will get.  To small however, and the plane becomes difficult to control.  I landed at 160 x 120 and 24 frames per second.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> processImage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> bmpd<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">BitmapData</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">BitmapData</span><span style="color: #000000;">&#40;</span> VIDEO_WIDTH, VIDEO_HEIGHT <span style="color: #000000;">&#41;</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> average<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">distance</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> percent<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0;			
	<span style="color: #6699cc; font-weight: bold;">var</span> r1<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000;">&#40;</span> <span style="color: #004993;">color</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">16</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span> 0xFF;
	<span style="color: #6699cc; font-weight: bold;">var</span> g1<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #000000;">&#40;</span> <span style="color: #004993;">color</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">8</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span> 0xFF;
	<span style="color: #6699cc; font-weight: bold;">var</span> b1<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = <span style="color: #004993;">color</span> <span style="color: #000000; font-weight: bold;">&amp;</span> 0xFF;
	<span style="color: #6699cc; font-weight: bold;">var</span> r2<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> g2<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> b2<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">uint</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> rotX<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0;
	<span style="color: #6699cc; font-weight: bold;">var</span> rotY<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0;
&nbsp;
	bmpd.<span style="color: #004993;">draw</span><span style="color: #000000;">&#40;</span> video <span style="color: #000000;">&#41;</span>;
&nbsp;
	closest.<span style="color: #004993;">color</span> = 0;
	closest.<span style="color: #004993;">distance</span> = <span style="color: #000000; font-weight:bold;">1000</span>;
	closest.<span style="color: #004993;">x</span> = 0;
	closest.<span style="color: #004993;">y</span> = 0;			
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> h<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0; h <span style="color: #000000; font-weight: bold;">&lt;</span> video.<span style="color: #004993;">height</span>; h<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0033ff; font-weight: bold;">for</span><span style="color: #000000;">&#40;</span> <span style="color: #6699cc; font-weight: bold;">var</span> w<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Number</span> = 0; w <span style="color: #000000; font-weight: bold;">&lt;</span> video.<span style="color: #004993;">width</span>; w<span style="color: #000000; font-weight: bold;">++</span> <span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>			
			average = bmpd.<span style="color: #004993;">getPixel</span><span style="color: #000000;">&#40;</span> w, h <span style="color: #000000;">&#41;</span>;
&nbsp;
			r2 = <span style="color: #000000;">&#40;</span> average <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">16</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span> 0xFF;
			g2 = <span style="color: #000000;">&#40;</span> average <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight:bold;">8</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">&amp;</span> 0xFF;
			b2 = average <span style="color: #000000; font-weight: bold;">&amp;</span> 0xFF;
&nbsp;
			<span style="color: #004993;">distance</span> = <span style="color: #004993;">Math</span>.<span style="color: #004993;">sqrt</span><span style="color: #000000;">&#40;</span> 
				<span style="color: #004993;">Math</span>.<span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span> r2 <span style="color: #000000; font-weight: bold;">-</span> r1, <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> 
				<span style="color: #004993;">Math</span>.<span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span> g2 <span style="color: #000000; font-weight: bold;">-</span> g1, <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">+</span> 
				<span style="color: #004993;">Math</span>.<span style="color: #004993;">pow</span><span style="color: #000000;">&#40;</span> b2 <span style="color: #000000; font-weight: bold;">-</span> b1, <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span> 
			<span style="color: #000000;">&#41;</span>;
&nbsp;
			<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> closest.<span style="color: #004993;">distance</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #004993;">distance</span> <span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				closest.<span style="color: #004993;">distance</span> = <span style="color: #004993;">distance</span>;
				closest.<span style="color: #004993;">x</span> = w;
				closest.<span style="color: #004993;">y</span> = h;
				closest.<span style="color: #004993;">color</span> = average;
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	sample.<span style="color: #004993;">x</span> = video.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">+</span> closest.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">5</span>;
	sample.<span style="color: #004993;">y</span> = video.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">+</span> closest.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">5</span>;
&nbsp;
	<span style="color: #009900;">// Rotation on x-axis</span>
	percent = closest.<span style="color: #004993;">y</span> <span style="color: #000000; font-weight: bold;">/</span> video.<span style="color: #004993;">height</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> percent <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0.50</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		photo.rotationX = <span style="color: #000000; font-weight:bold;">360</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span> MAX_ROTATION <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0.50</span> <span style="color: #000000; font-weight: bold;">-</span> percent <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> percent <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">0.50</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		photo.rotationX  = <span style="color: #000000;">&#40;</span> MAX_ROTATION <span style="color: #000000; font-weight: bold;">*</span> percent <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span> MAX_ROTATION <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
		photo.rotationX = 0;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #009900;">// Rotation on y-axis</span>
	percent = closest.<span style="color: #004993;">x</span> <span style="color: #000000; font-weight: bold;">/</span> video.<span style="color: #004993;">width</span>;
&nbsp;
	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> percent <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight:bold;">0.50</span> <span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		photo.rotationY  = <span style="color: #000000;">&#40;</span> MAX_ROTATION <span style="color: #000000; font-weight: bold;">*</span> percent <span style="color: #000000;">&#41;</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span> MAX_ROTATION <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight:bold;">2</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span> percent <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight:bold;">0.50</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
		photo.rotationY = <span style="color: #000000; font-weight:bold;">360</span> <span style="color: #000000; font-weight: bold;">-</span> <span style="color: #000000;">&#40;</span> MAX_ROTATION <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000; font-weight:bold;">0.50</span> <span style="color: #000000; font-weight: bold;">-</span> percent <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;
	<span style="color: #000000;">&#125;</span> <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #000000;">&#123;</span>
		photo.rotationY = 0;
	<span style="color: #000000;">&#125;</span>			
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>There’s a lot of tweaking that can go on here to improve the result.  As an example, generally HSB values work better than RGB, but RGB is easier for me to grasp mentally, so I started there.  Then there’s the definition of “closest” color match.  Tracking would also likely be smoother if I focused on an area of the screen that represented the overall closest color match versus just a pixel.  That’s being said, if you have Flash Player 10 (and a web camera), here’s what I came up with for your viewing pleasure.</p>
<p><em>Note: A special thanks goes out to one of my colleagues, <a href="http://www.webkitchen.be">Serge Jespers</a>, for discovering that you may need to change the privacy settings on the Flash Player to allow access to your web camera from this domain in order for this example to work.  To enable web camera usage, right click on the application and select &#8220;Settings&#8230;&#8221;.</em></p>
<p><object width="550" height="550"><param name="movie" value="http://blog.kevinhoyt.org/wp-content/bump.swf"><embed src="http://blog.kevinhoyt.org/wp-content/bump.swf" width="550" height="550"></embed></object></p>
<p><em>Update: I added the ability to &#8220;push&#8221; and &#8220;pull&#8221; the image based on the closeness of the object to the web camera.  This is done by monitoring how much of the color is present in the web camera&#8217;s viewable space, and is highly subjective depending on the contrast of the selected color value.  For this reason, push/pull is off by default and can be enabled by selecting the check box in the lower left-hand corner.</em></p>
<p>This all works best if you a) use a high contrast color such as a neon green b) bring the object close for initial sampling (spacebar) and then c) pull the object back relatively far such as to reduce the overall footprint in the web camera display.  I couldn’t figure out what to do with the web camera/color selection area once an initial selection had been made, so if you have any feedback, I’d very much welcome your thoughts.  In general, I just found it easier to control the image (whatever has been recently loaded onto Flickr) if the web camera was still front and center.</p>
<table>
<tr>
<td>
<img src='http://blog.kevinhoyt.org/wp-content/uploads/color-bump-sampling.jpg' alt='color-bump-sampling.jpg' />
</td>
<td>
<img src='http://blog.kevinhoyt.org/wp-content/uploads/color-bump-processing.jpg' alt='color-bump-processing.jpg' />
</td>
</tr>
</table>
<p>Rotating display objects in Flash Player 10 is just like the standard rotation property we all know and enjoy using today, but there’s now rotationX and rotationY.  The hard part is that you have to maintain the z-ordering yourself.  I would expect that the community will be quick to pick up this shortcoming when the final release of Flash Player 10 (and related tooling) is available.  </p>
<p>While its not an amazing new 3D library or game, my first little footsteps into Flash Player 10 have been really fun.  Even my four year old daughter enjoys making the picture move with her hands - and her colorful toys laying around the house have made great test subjects.  Not bad for an afternoon of work and the industry leading innovation of Flash Player 10!  If you want the source code, I am making that available for <a href="http://blog.kevinhoyt.org/wp-content/color-bump.zip">download</a> as usual.</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/08/25/basic-computer-vision-and-flash-player-10/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Building a Basic IP Address Service</title>
		<link>http://blog.kevinhoyt.org/2008/08/14/building-a-basic-ip-address-service/</link>
		<comments>http://blog.kevinhoyt.org/2008/08/14/building-a-basic-ip-address-service/#comments</comments>
		<pubDate>Thu, 14 Aug 2008 18:53:25 +0000</pubDate>
		<dc:creator>Kevin Hoyt</dc:creator>
		
		<category><![CDATA[ActionScript]]></category>

		<category><![CDATA[ColdFusion]]></category>

		<category><![CDATA[Flash]]></category>

		<guid isPermaLink="false">http://blog.kevinhoyt.org/2008/08/14/building-a-basic-ip-address-service/</guid>
		<description><![CDATA[I was doing some casual end of day surfing the other day when I ran across Rich Tretola’s blog post on getting a user’s IP address into Flash.  What I really liked about Rich’s implementation was the simplicity of the approach - put the IP in the containing HTML.  When I wanted to [...]]]></description>
			<content:encoded><![CDATA[<p>I was doing some casual end of day surfing the other day when I ran across <a href="http://blog.everythingflex.com/2008/08/07/get-ipaddress-into-flash/">Rich Tretola’s</a> blog post on getting a user’s IP address into Flash.  What I really liked about Rich’s implementation was the simplicity of the approach - put the IP in the containing HTML.  When I wanted to solve this same problem in a past project, my first reaction was to build a service, because, well, everything is a service these days.  Here’s my little IP service, built on <a href="http://www.adobe.com/products/coldfusion/">ColdFusion</a>, and a little ActionScript to use it.<br />
<span id="more-208"></span><br />
Getting the IP address of a client is remarkably easy when you handle it at the server.  Most server technologies capture this information as some fashion of server variable.  In the case of the IP address in ColdFusion, you’ll find this information on the CGI structure in the REMOTE_ADDR property.  If you <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_d-e_08.html">CFDUMP</a> the <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/Expressions_8.html">CGI structure</a>, you’ll often from the IP in other properties as well.  I simply chose the REMOTE_ADDR property because it seemed more consistent.</p>

<div class="wp_syntax"><div class="code"><pre class="coldfusion" style="font-family:monospace;">&lt;cfoutput&gt;#CGI.REMOTE_ADDR#&lt;/cfoutput&gt;</pre></div></div>

<p>Simply getting the IP wasn’t enough for me though, and I wanted to provide some additional value.  A quick search around the web landed me with several “geo IP” <a href="http://www.webservicex.net/geoipservice.asmx?WSDL">services</a> that map an IP to a specific geography.  Calling a web service from ColdFusion is a matter of using the <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_i_10.html">CFINVOKE</a> tag, specifying the URL to the WSDL of the web service, and the operation (called “method” in ColdFusion) on that service that you want to call.  It’s also helpful to specify a return variable.</p>

<div class="wp_syntax"><div class="code"><pre class="coldfusion" style="font-family:monospace;">&lt;cfinvoke returnvariable=&quot;geoip&quot; webservice=&quot;http://www.webservicex.net/geoipservice.asmx?WSDL&quot; method=&quot;GetGeoIP&quot;&gt;
	&lt;cfinvokeargument name=&quot;IPAddress&quot; value=&quot;#CGI.REMOTE_ADDR#&quot; /&gt;
&lt;/cfinvoke&gt;</pre></div></div>

<p>In the case of this geo-IP web service, you’ll get a few pieces of information back, most notable is the name of the country from which the IP originates and the respective country code.  That’s three pieces of information to hand back, and since Flash does such an excellent job with XML, I chose to go that direction.  I little fiddling with the data and I landed at a schema I like, into which I simply dumped the return values from the web service call.</p>

<div class="wp_syntax"><div class="code"><pre class="coldfusion" style="font-family:monospace;">&lt;result&gt;
	&lt;ip&gt;&lt;cfoutput&gt;#geoip.getIP()#&lt;/cfoutput&gt;&lt;/ip&gt;
    &lt;country name=&quot;&lt;cfoutput&gt;#geoip.getCountryName()#&lt;/cfoutput&gt;&quot; code=&quot;&lt;cfoutput&gt;#geoip.getCountryCode()#&lt;/cfoutput&gt;&quot; /&gt;
&lt;/result&gt;</pre></div></div>

<p>I think there’s a tendency for this to get a little confusing.  The above ColdFusion code builds a service that can be called by any client capable of handling XML as a result format.  This little service itself however, actually leverages another web service.  Let’s call it composite web services.  That’s the great thing about web services; they open the door for you to mix and match the data in your own new and interesting ways.  Who knows, somebody else may use this ColdFusion <a href="http://apps.kevinhoyt.org/kevin/apps/ip/ipservice.cfm">service</a> in their own service, making the service chain nested three levels.</p>
<p>On to consuming this service from ActionScript.  If you’re using <a href="http://www.adobe.com/products/flex/">Flex</a>, this is an <a href="http://livedocs.adobe.com/flex/3/langref/mx/rpc/http/mxml/HTTPService.html">HTTPService</a> call where HTTPService.resultFormat is E4X.  Put a result handler on there as well, and you’re off to the races.  Since this is really more about Flash in general however, I’m going to talk about using <a href="http://livedocs.adobe.com/flex/3/langref/flash/net/URLLoader.html">URLLoader</a>, which is really what HTTPService uses under the covers.</p>
<p>To interact with this service, you instantiate a new URLLoader object, add the event listener for Event.COMPLETE, so you know when the data has been returned, and then call URLLoader.load() passing a <a href="http://livedocs.adobe.com/flex/3/langref/flash/net/URLRequest.html">URLRequest</a> instance.  The URLRequest instance contains the URL that acts as the endpoint for this service.  While my little ColdFusion service here is public, I make no garuntees about it being around forever.  If you like what I’ve done here, you should probably look to create a similar service on a server you control.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = <span style="color: #0033ff; font-weight: bold;">null</span>;
&nbsp;
<span style="color: #004993;">loader</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLLoader</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">loader</span>.<span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">Event</span>.<span style="color: #004993;">COMPLETE</span>, doIPComplete <span style="color: #000000;">&#41;</span>;
<span style="color: #004993;">loader</span>.<span style="color: #004993;">load</span><span style="color: #000000;">&#40;</span> <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">URLRequest</span><span style="color: #000000;">&#40;</span> IP_SERVICE <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span>;</pre></div></div>

<p>When the results come back, the event handler that you specified on the URLLoader will be called.  In this case, I know we’re dealing with XML, so I create a new XML object from the raw text string contained in the URLLoader.data property.  From there I can use E4X to quickly access the pieces of data in which I am interested.  Note that the root node is actually a given, and doesn’t need to be specified on the XML object.  So rather than “result.result.country.@name” we can simply say “result.country.@name” where the first “result” is actually the variable name.</p>

<div class="wp_syntax"><div class="code"><pre class="actionscript3 actionscript3" style="font-family:monospace;"><span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> doIPComplete<span style="color: #000000;">&#40;</span> event<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">Event</span> <span style="color: #000000;">&#41;</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">loader</span><span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">URLLoader</span> = event.<span style="color: #004993;">currentTarget</span> <span style="color: #0033ff; font-weight: bold;">as</span> <span style="color: #004993;">URLLoader</span>;
	<span style="color: #6699cc; font-weight: bold;">var</span> result<span style="color: #000000; font-weight: bold;">:</span><span style="color: #004993;">XML</span> = <span style="color: #0033ff; font-weight: bold;">new</span> <span style="color: #004993;">XML</span><span style="color: #000000;">&#40;</span> <span style="color: #004993;">loader</span>.<span style="color: #004993;">data</span> <span style="color: #000000;">&#41;</span>;
&nbsp;
	ip.<span style="color: #004993;">text</span> = result.ip;
	country.<span style="color: #004993;">text</span> = result.country.@<span style="color: #004993;">name</span>;
	<span style="color: #004993;">code</span>.<span style="color: #004993;">text</span> = result.country.@<span style="color: #004993;">code</span>;			
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>It seems obvious that the next step would be to wrap this in it’s own class that can be easily reused.  I’m lazy I guess then, because since this is but a few lines of code it barely seems worth the effort.  Since JavaScript doesn’t have the ability to reach across domains, it would probably also make sense to provide a little script that could be included in HTML.  If you build a JavaScript wrapper, let me know and I’ll put it up on the server as well.  Or if you build an ActionScript class wrapper, let me know so I can help share your work.  In the meantime, here’s the <a href="/wp-content/ip-address.zip">source code</a> for both the ColdFusion part and the ActionScript application.  An example application is also available for <a href="http://apps.kevinhoyt.org/kevin/ip/">viewing</a>.</p>
<noscript>Tags:<a href="http://www.saveonrefinance.com" title="Current Mortgage Rates">Current Mortgage Rates</a></noscript>]]></content:encoded>
			<wfw:commentRss>http://blog.kevinhoyt.org/2008/08/14/building-a-basic-ip-address-service/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
