<?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>Learning jQuery &#187; Adobe AIR Application</title>
	<atom:link href="http://www.learningjquery.org/index.php/tag/adobe-air-application/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learningjquery.org</link>
	<description>Learning jQuery: Tips, techniques, and tutorials for the jQuery JavaScript library</description>
	<lastBuildDate>Tue, 24 Aug 2010 10:10:35 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To Store Adobe AIR Application Preferences Using JavaScript</title>
		<link>http://www.learningjquery.org/index.php/how-to-store-adobe-air-application-preferences-using-javascript/</link>
		<comments>http://www.learningjquery.org/index.php/how-to-store-adobe-air-application-preferences-using-javascript/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 01:03:48 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[How To]]></category>
		<category><![CDATA[Adobe AIR Application]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.learningjquery.org/?p=49</guid>
		<description><![CDATA[by Andrew Tetlaw
When I last wrote the Tech Times I was quite excited about starting my first AIR application, called Harpoon, using only HTML, CSS, and JavaScript. One of the features I ran out of time to discuss was the way you can use an XML file to store and retrieve application preferences.
If you downloaded [...]]]></description>
			<content:encoded><![CDATA[<p>by Andrew Tetlaw</p>
<p><strong>When I last wrote the Tech Times I was quite excited about <a href="http://sitepointcom.cmail1.com/t/y/l/krdtij/ddkyutiil/b" target="_blank">starting my first AIR application</a>, called Harpoon, using only HTML, CSS, and JavaScript. One of the features I ran out of time to discuss was the way you can use an XML file to store and retrieve application preferences.</strong></p>
<p>If you downloaded and installed Harpoon you may have noticed the Preferences panel with the select list.</p>
<p><img border="0" alt="Preferences Panel" width="371" height="99" align="bottom" /></p>
<p>Here&#8217;s the HTML for that field and its label:</p>
<pre><code>&lt;label&gt;Refresh every (minutes)&lt;/label&gt;
&lt;select id="pref_refresh" name="pref_refresh"&gt;
  &lt;option value="1"&gt;1&lt;/option&gt;
  &lt;option value="2"&gt;2&lt;/option&gt;
  &lt;option value="3"&gt;3&lt;/option&gt;
  &lt;option value="4"&gt;4&lt;/option&gt;
  ...
  &lt;option value="10"&gt;10&lt;/option&gt;
&lt;/select&gt;</code></pre>
<p>If you recall, Harpoon is destined to be an auction watching application for the <a href="http://sitepointcom.cmail1.com/t/y/l/krdtij/ddkyutiil/n" target="_blank">Flippa</a> site. Eventually this will control how often Flippa is checked for new auctions matching your query. Of course you&#8217;d want Harpoon to remember this setting, so we&#8217;ll store the selected value in an XML file.</p>
<p>Our task is this:</p>
<ul>
<li> When Harpoon is opened we check to see if the preferences file is available.</li>
<li> If unavailable Harpoon should create the file and write the default value.</li>
<li> If available Harpoon should read it and set the field value.</li>
<li> Whenever the field value is changed Harpoon should write the new value to the preferences file.</li>
</ul>
<p>This sounds way more complicated than it really is. Let&#8217;s dive in so I can show you.</p>
<p>First some adjustments to our <code>Harpoon</code> object. (If you need to prod your memory, take a detour and <a href="http://sitepointcom.cmail1.com/t/y/l/krdtij/ddkyutiil/p" target="_blank">refer back to my previous article</a>.) We want to store the refresh value, and a couple of other important values within the <code>Harpoon</code> object:</p>
<pre><code>var Harpoon = {
  ...
  prefsFile : null,
  storePath : null,
  prefs : {
    refresh : 10
  }
}</code></pre>
<p>I&#8217;ll address <code>prefsFile</code> and <code>storePath</code> in a moment, but you can also see the <code>prefs</code> object that has one property called <code>refresh</code>. This is where we&#8217;ll store the refresh value, and it&#8217;ll be accessible within our application from <code>Harpoon.prefs.refresh</code>.</p>
<p>Now we come back to the <code>prefsFile</code> and <code>storePath</code> properties. For security reasons each AIR application is given its own storage directory from which it can read and write files. This is where our preferences file will reside. These two properties will store the path to the application storage directory and the path to the preferences file. If you remember from the previous article Harpoon has an <code>init</code> function for initialisation, where we placed that call to the <code>setupWindow</code> function. We&#8217;ll add a few lines of code to that:</p>
<pre><code>init : function() {
  Harpoon.setupWindow();
  Harpoon.storePath =
      air.File.applicationStorageDirectory;
  Harpoon.prefsFile =
      Harpoon.storePath.resolvePath("prefs.xml");
  Harpoon.getPrefs();
  ...
},</code></pre>
<p>We use the <code>air.File.applicationStorageDirectory</code> to obtain Harpoon&#8217;s storage directory. Then we use the <code>resolvePath</code> method to retrieve the path to the preferences file <code>prefs.xml</code> and store it as a <code>File</code> object. The next line, <code>Harpoon.getPrefs()</code>, is a call to a new function we shall write, after the break!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learningjquery.org/index.php/how-to-store-adobe-air-application-preferences-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
