<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fraser Crosbie - Calgary Flash, Flex &#38; Web Developer &#187; code</title>
	<atom:link href="http://www.flashdev.ca/article/tag/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flashdev.ca</link>
	<description>Web developer specializing in rich internet applications. Located in Calgary, Alberta, Canada</description>
	<lastBuildDate>Thu, 09 Jun 2011 17:47:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Loading and Saving External XML Data in AIR (Apollo)</title>
		<link>http://www.flashdev.ca/article/loading-and-saving-xml-data-in-air-apollo/</link>
		<comments>http://www.flashdev.ca/article/loading-and-saving-xml-data-in-air-apollo/#comments</comments>
		<pubDate>Tue, 03 Jul 2007 22:59:31 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[ActionScript 3.0 Tutorial]]></category>
		<category><![CDATA[AIR (Apollo) Tutorial]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[Apollo]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Flash]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/article/loading-and-saving-xml-data-in-air-apollo/</guid>
		<description><![CDATA[I just finished an AIR (Apollo) application that loads and saves data from an external XML file. I figured I would share the code to accomplish this task as there is not a lot of Apollo info around at this time. First off lets start with loading an XML file and reading its contents. I [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished an AIR (Apollo) application that loads and saves data from an external XML file. I figured I would share the code to accomplish this task as there is not a lot of Apollo info around at this time.</p>
<p>First off lets start with loading an XML file and reading its contents. I realize that there are much easier ways to load XML into Flash than this, but the advantage here is that I can use <em>File.applicationResourceDirectory</em> which allows me to target the installation directory for the XML file that was included with the AIR package. In this snippet I am using the synchronous open method.  This essentially pauses everything else in the Flash movie until it has completed its task (opening the file).</p>
<p><span id="more-47"></span></p>
<pre>
<code>
import flash.filesystem.*;

private var _data:String; // Data string pulled from the xml file.

/**
 * Load the xml file and read its data.
 */
private function loadData():void
{
  var dataFile:File = File.applicationResourceDirectory.resolve("data.xml");
  var stream:FileStream = new FileStream();
  stream.open(dataFile, FileMode.READ);
  _data = stream.readUTFBytes(stream.bytesAvailable);
  stream.close();
}
</code>
</pre>
<p>This next snippet shows how to save data to a file using the asynchronous openAsync method. The asynchronous methods allow Flash to continue running normally and use events to trigger user specified actions.</p>
<pre>
<code>
private var _dataXML:XML;	// The XML data.

/**
 * Save the modified data to the xml file.
 */
private function saveData():void
{
  var dataFile:File = File.applicationResourceDirectory.resolve("data.xml");
  var stream:FileStream = new FileStream();
  stream.openAsync(dataFile, FileMode.WRITE);
  stream.writeUTFBytes(_dataXML);
  stream.addEventListener(Event.CLOSE, onDataSaved);
  stream.close();
}

/**
 * Called when the data has been successfully saved.
 * Load the saved data back into the application.
 */
private function onDataSaved(event:Event):void
{
  loadData();
}
</code>
</pre>
<p>If you are planning on using AIR (Apollo) for your own projects I would highly recommend reading <a href="http://download.macromedia.com/pub/labs/apollo/documentation/apollo_for_flex_pocketguide_031907.pdf">Apollo for Adobe Flex Developers Pocket Guide</a> by Mike Chambers, Robert L. Dixon &#038; Jeff Swartz.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/loading-and-saving-xml-data-in-air-apollo/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Firefox with wmode ignores Key.isDown()</title>
		<link>http://www.flashdev.ca/article/firefox-with-wmode-ignores-keyisdown/</link>
		<comments>http://www.flashdev.ca/article/firefox-with-wmode-ignores-keyisdown/#comments</comments>
		<pubDate>Thu, 08 Mar 2007 21:27:10 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[FireFox]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/article/firefox-with-wmode-ignores-keyisdown/</guid>
		<description><![CDATA[I am sure this is old news to many of you, but today was the first time I have run into this issue. I am working on a site for a client that has very high accessibility requirements. I originally built my project to be controlled using the mouse and was asked this morning to [...]]]></description>
			<content:encoded><![CDATA[<p>I am sure this is old news to many of you, but today was the first time I have run into this issue. I am working on a site for a client that has very high accessibility requirements. I originally built my project to be controlled using the mouse and was asked this morning to add the ability to navigate it using the arrow keys of the keyboard. It only took me a couple minutes to get this functionality working in Flash, but when I tested it using Firefox I was not getting any response from the keyboard. I tried it out in IE7 and everything worked like a charm. After a couple minutes of searching I came across <a href="http://www.johanvanmol.org/content/view/47/41/">this site</a> and found my solution. Apparently Firefox always returns the <em>Key.isDown()</em> function as false if you have <em>wmode=&#8221;transparent&#8221;</em> or <em>wmode=&#8221;opaque&#8221;</em> in your html object and embed tags, but if you use <em>Key.getCode()</em> everything works perfect.</p>
<p>Here is a snippet of code showing the workaround to this issue:</p>
<p><span id="more-42"></span></p>
<pre>
function reset():Void {
  var next:Boolean = false;
  var prev:Boolean = false;
  var keyboardListener:Object = new Object();
  keyboardListener.onKeyDown = function () {
    if (Key.getCode() == 39) next = true;
    if (Key.getCode() == 37) prev = true;
  }
  this.onEnterFrame = function() {
    if (next) {
      delete this.onEnterFrame;
      trace("next page");
      flash.external.ExternalInterface.call("alert",
                                            "next page");
      reset();
    }
    if (prev) {
      delete this.onEnterFrame;
      trace("previous page");
      flash.external.ExternalInterface.call("alert",
                                            "previous page");
      reset();
    }
  }
  Key.addListener(keyboardListener);
}
reset();
</pre>
<p>I added some JavaScript Alerts to prove it works in the browser.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/firefox-with-wmode-ignores-keyisdown/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>O&#8217;Reilly Code Search</title>
		<link>http://www.flashdev.ca/article/oreilly-code-search/</link>
		<comments>http://www.flashdev.ca/article/oreilly-code-search/#comments</comments>
		<pubDate>Sun, 10 Sep 2006 17:45:52 +0000</pubDate>
		<dc:creator>Fraser Crosbie</dc:creator>
				<category><![CDATA[Flash Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.flashdev.ca/?p=24</guid>
		<description><![CDATA[O&#8217;Reilly&#8217;s has recently launched a search engine that will scour through nearly 700 of their books, including over 123,000 individual examples, composed of 2.6 million lines of code. I think O&#8217;Reilly has published around 21 ActionScript related books at this time. http://labs.oreilly.com/code/]]></description>
			<content:encoded><![CDATA[<p>O&#8217;Reilly&#8217;s has recently launched a search engine that will scour through nearly 700 of their books, including over 123,000 individual examples, composed of 2.6 million lines of code. I think O&#8217;Reilly has published around 21 ActionScript related books at this time.</p>
<p><a href="http://labs.oreilly.com/code/">http://labs.oreilly.com/code/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flashdev.ca/article/oreilly-code-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

