<?xml version="1.0" encoding="UTF-16"?>
<rss version="2.0"><channel><title>SoftXML | ADOBEAIR Tutorials</title><link>http://www.softxml.com/rss/tutorials/adobeair.xml</link><description>Tutorials</description><pubDate>Sun, 11 Jan 2009 14:27:49 EST</pubDate><language>en-us</language><image><title>SoftXML | ADOBEAIR Tutorials</title><url>http://www.softxml.com/images/rsscategory.gif</url><link>http://www.softxml.com/rss/tutorials/adobeair.xml</link><width>80</width><height>73</height></image><item><title>Introduction to Adobe AIR</title><link>http://www.softxml.com/LearnTutorial.asp?id=2862224685&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;P class=docText&gt;&lt;A name="Adobe AIR"&gt;&lt;/A&gt;Adobe AIR is a cross-platform desktop 
runtime created by Adobe that allows web developers to use web technologies to 
build and deploy Rich Internet Applications (RIAs) &lt;A 
name=I_indexterm1_d1e641&gt;&lt;/A&gt;&lt;A name="applications to"&gt;&lt;/A&gt;and web applications 
to the desktop.&lt;/P&gt;&lt;A name=introduction_to_adobe_aird1e653&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="its development"&gt;&lt;/A&gt;During its development cycle, 
Adobe AIR was referred to in public by its &lt;A name=I_indexterm1_d1e648&gt;&lt;/A&gt;code 
name of "Apollo".&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="it&amp;#13;&amp;#10;  tries"&gt;&lt;/A&gt;To better understand what 
Adobe AIR enables, and which problems it tries to address, it is useful to first 
take a look at the (relatively short) history of web applications.&lt;/P&gt;&lt;A 
name=a_short_history_of_web_applications&gt;&lt;/A&gt;
&lt;H3 class=docSection1Title id=-100000&gt;1.1. A Short History of Web 
Applications&lt;/H3&gt;
&lt;P class=docText&gt;Over the&lt;A name=ch01-webapp&gt;&lt;/A&gt; past &lt;A 
name=ch01-applicationsweb&gt;&lt;/A&gt;&lt;A name=ch01-internetapp&gt;&lt;/A&gt;&lt;A 
name="an accelerating"&gt;&lt;/A&gt;couple of years, there has been an accelerating trend 
of applications moving from the desktop&lt;A name=I_indexterm1_d1e672&gt;&lt;/A&gt; to the 
web browser. &lt;A name=I_indexterm1_d1e676&gt;&lt;/A&gt;This has been driven by a number of 
factors, which include:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P class=docList&gt;Growth of the Internet as a communication medium&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;Relative ease of deployment of web applications&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;Ability to target multiple operating systems via the 
browser&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;&lt;A name="Flash Player"&gt;&lt;/A&gt;Maturity of higher-level client 
technologies, such as the browser and the Flash Player runtime&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=docText&gt;&lt;A name="HTML and"&gt;&lt;/A&gt;Early web applications were built 
primarily with HTML and JavaScript, which, for the most part, relied heavily on 
client/server interactions and page refreshes. This page refresh model was 
consistent with the document-based metaphor for which the browser was originally 
designed, but provided a relatively poor user experience when displaying 
applications.&lt;/P&gt;
&lt;P class=docText&gt;With the maturation of the Flash Player runtime,&lt;A 
name=I_indexterm1_d1e699&gt;&lt;/A&gt; however, and more recently with Ajax-type 
functionality&lt;A name=I_indexterm1_d1e705&gt;&lt;/A&gt;&lt;A name="break away"&gt;&lt;/A&gt; in the 
browser, it became possible for developers to begin to break away from 
page-based application flows. Developers began to offer richer application 
experiences via the browser. In a whitepaper from March 2002, Macromedia coined 
the term &lt;SPAN class=docEmphasis&gt;rich Internet application&lt;/SPAN&gt;&lt;A 
name="new types"&gt;&lt;/A&gt; to describe these new types of applications in browsers, 
which "blend content, application logic and communications ... to make the 
Internet more usable and enjoyable." These applications provided richer, more 
desktop-like experiences, while still retaining the core cross-platform nature 
of the Web:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P class=docText&gt;&lt;A name="are all"&gt;&lt;/A&gt;Internet applications are all about 
reach. The promise of the web is one of content and applications anywhere, 
regardless of the platform or device. Rich clients must embrace and support all 
popular desktop operating systems, as well as the broadest range of emerging 
device platforms such as smart phones, PDAs, set-top boxes, game consoles, and 
Internet appliances.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;A 
name=a_short_history_of_web_applicationsd1e723&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="You can"&gt;&lt;/A&gt;You can find the complete whitepaper and 
more information on RIAs at &lt;A class=docLink 
href="http://download.macromedia.com/pub/flash/whitepapers/richclient.pdf" 
target=_blank&gt;http://download.macromedia.com/pub/flash/whitepapers/richclient.pdf&lt;/A&gt;.&lt;BR&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="goes on"&gt;&lt;/A&gt;The paper goes on to list some features 
that define RIAs:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;P class=docList&gt;&lt;A name="an efficient"&gt;&lt;/A&gt;Provide an efficient, 
high-performance runtime for executing code, content, and communications&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;Integrate content, communications, and application interfaces 
into a common environment&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;Provide powerful and extensible object models for 
interactivity&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;Enable rapid application development through components and 
reuse&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;&lt;A name="by application"&gt;&lt;/A&gt;Enable the use of web and data 
services provided by application servers&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;Embrace connected and disconnected clients&lt;/P&gt;
&lt;LI&gt;
&lt;P class=docList&gt;&lt;A name="platforms and"&gt;&lt;/A&gt;Enable easy deployment on multiple 
platforms and devices&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P class=docText&gt;&lt;A name="browser "&gt;&lt;/A&gt;This movement toward providing richer, 
more desktop-like application experiences in the browser (enabled by the Flash 
Player runtime, and more recently by Ajax) has led to an explosion of web 
applications.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="an application"&gt;&lt;/A&gt;Today, the web has firmly 
established itself as an application deployment platform that offers benefits to 
both developers and end-users.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=2862224685&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Getting Started with Adobe AIR Development
</title><link>http://www.softxml.com/LearnTutorial.asp?id=1597174412&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;P class="docText"&gt;&lt;A name="This chapter"&gt;&lt;/A&gt;This chapter discusses how &lt;A name="ch02-aagetting"&gt;
	&lt;/A&gt;&lt;A name="developing applications"&gt;&lt;/A&gt;to start developing applications for 
	Adobe AIR using HTML and JavaScript. It covers:&lt;/P&gt;
&lt;UL&gt;
	&lt;LI&gt;
		&lt;P class="docList"&gt;&lt;A name="Adobe AIR"&gt;&lt;/A&gt;Installing Adobe AIR&lt;/P&gt;
	&lt;LI&gt;
		&lt;P class="docList"&gt;Configuring the Adobe AIR SDK and command-line tools&lt;/P&gt;
	&lt;LI&gt;
		&lt;P class="docList"&gt;Creating your first AIR application&lt;/P&gt;
	&lt;LI&gt;
		&lt;P class="docList"&gt;Testing AIR applications&lt;/P&gt;
	&lt;LI&gt;
		&lt;P class="docList"&gt;Signing, packaging, and deploying AIR applications&lt;/P&gt;
	&lt;/LI&gt;
&lt;/UL&gt;
&lt;P class="docText"&gt;&lt;A name="AIR applications"&gt;&lt;/A&gt;Once you have completed this 
	chapter, your environment for developing AIR applications should be configured 
	correctly, and you should have a solid understanding of how to begin to build, 
	test, and deploy Adobe AIR applications.&lt;/P&gt;
&lt;A name="what_do_you_need_to_develop_adobe_air_a"&gt;&lt;/A&gt;
&lt;H3 class="docSection1Title" id="-100000"&gt;2.1. What Do You Need to Develop Adobe 
	AIR Applications?&lt;/H3&gt;
&lt;P class="docText"&gt;&lt;A name="items to"&gt;&lt;/A&gt;You need a number of items to begin 
	developing AIR applications.&lt;/P&gt;
&lt;A name="adobe_air_runtime"&gt;&lt;/A&gt;
&lt;H4 class="docSection2Title" id="title-ID0ELAOM"&gt;2.1.1. Adobe AIR Runtime&lt;/H4&gt;
&lt;P class="docText"&gt;The Adobe AIR runtime is&lt;A name="I_indexterm2_d1e1368"&gt;&lt;/A&gt;&lt;A name="can download"&gt;&lt;/A&gt;
	required to test application icons and deploy AIR applications. You can 
	download the runtime for free from &lt;A class="docLink" href="http://www.adobe.com/go/getair" target="_blank"&gt;
		http://www.adobe.com/go/getair&lt;/A&gt;.&lt;/P&gt;
&lt;A name="adobe_air_sdk"&gt;&lt;/A&gt;
&lt;H4 class="docSection2Title" id="title-ID0EZAOM"&gt;2.1.2. Adobe AIR SDK&lt;/H4&gt;
&lt;P class="docText"&gt;The Adobe AIR SDK&lt;A name="I_indexterm2_d1e1379"&gt;&lt;/A&gt; contains&lt;A name="I_indexterm2_d1e1383"&gt;&lt;/A&gt;&lt;A name="I_indexterm2_d1e1386"&gt;&lt;/A&gt;&lt;A name="I_indexterm2_d1e1389"&gt;&lt;/A&gt;&lt;A name="easier to"&gt;&lt;/A&gt;
	command-line tools, sample files, and other resources to make it easier to 
	develop AIR applications. In particular, we will be using the command-line 
	tools included in the SDK (ADL and ADT), which will allow us to test, sign, and 
	package our AIR applications from virtually any development environment.&lt;/P&gt;
&lt;P class="docText"&gt;You can download the AIR SDK for free from &lt;A class="docLink" href="http://www.adobe.com/go/getairsdk" target="_blank"&gt;
		http://www.adobe.com/go/getairsdk&lt;/A&gt;.&lt;/P&gt;
&lt;A name="html_solidus_javascript_ide_or_editor"&gt;&lt;/A&gt;
&lt;H4 class="docSection2Title" id="title-ID0EWBOM"&gt;2.1.3. HTML/JavaScript IDE or 
	Editor&lt;/H4&gt;
&lt;P class="docText"&gt;Building AIR&lt;A name="I_indexterm2_d1e1402"&gt;&lt;/A&gt;&lt;A name="I_indexterm2_d1e1405"&gt;&lt;/A&gt;&lt;A name="way to"&gt;&lt;/A&gt;
	applications with HTML and JavaScript requires that you have a way to create 
	the HTML and JavaScript files. You can use any tool that supports creating and 
	editing text files (such as VIM or Notepad), although it's recommended that you 
	use a tool that has richer support for working with HTML and JavaScript files, 
	such as&lt;A name="I_indexterm2_d1e1409"&gt;&lt;/A&gt;&lt;A name="I_indexterm2_d1e1412"&gt;&lt;/A&gt;&lt;A name="I_indexterm2_d1e1415"&gt;&lt;/A&gt;
	Adobe Dreamweaver, Panic's Coda, or Aptana Studio.&lt;/P&gt;
&lt;A name="html_solidus_javascript_ide_or_editord1e1427"&gt;&lt;/A&gt;
&lt;DIV class="docNote"&gt;
	&lt;P class="docNormalTitle"&gt;NOTE&lt;/P&gt;
	&lt;P&gt;
	&lt;P class="docText"&gt;&lt;A name="more information"&gt;&lt;/A&gt;You can find more information on 
		Adobe Dreamweaver at &lt;A class="docLink" href="http://www.adobe.com/go/dreamweaver" target="_blank"&gt;
			http://www.adobe.com/go/dreamweaver&lt;/A&gt;, Panic's Coda at &lt;A class="docLink" href="http://www.panic.com/coda/" target="_blank"&gt;
			http://www.panic.com/coda/&lt;/A&gt;&lt;A name="Studio at"&gt;&lt;/A&gt;, and Aptana Studio 
		at &lt;A class="docLink" href="http://www.aptana.com" target="_blank"&gt;http://www.aptana.com&lt;/A&gt;.&lt;/P&gt;
	&lt;P&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;A name="supported_operating_system"&gt;&lt;/A&gt;
&lt;H4 class="docSection2Title" id="title-ID0E6COM"&gt;2.1.4. Supported Operating System&lt;/H4&gt;
&lt;P class="docText"&gt;&lt;A name="Although it"&gt;&lt;/A&gt;Although it is possible to develop&lt;A name="I_indexterm2_d1e1433"&gt;&lt;/A&gt;&lt;A name="AIR applications"&gt;&lt;/A&gt;
	and package AIR applications on virtually any operating system (including 
	Linux), you can test and deploy AIR applications only on operating systems 
	supported by Adobe AIR.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=1597174412&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Working with JavaScript and HTML Within Adobe AIR
</title><link>http://www.softxml.com/LearnTutorial.asp?id=13479781032&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;p&gt;In the previous query, our data was in a relational database. Now let's query an XML file.&lt;/p&gt;

&lt;p&gt;Suppose we want to query the users from a file named 'holdings.xml', which looks like this.&lt;/p&gt;



&lt;table bgcolor="#e6e6e6" ID="Table1"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;
&lt;pre&gt;&lt;span class="xml-tag"&gt;&amp;lt;HOLDINGS&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="xml-tag"&gt;&amp;lt;row&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="xml-tag"&gt;&amp;lt;USERID&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;Jonathan&lt;span class="xml-tag"&gt;&amp;lt;/USERID&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="xml-tag"&gt;&amp;lt;STOCKTICKER&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;AMZN&lt;span class="xml-tag"&gt;&amp;lt;/STOCKTICKER&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="xml-tag"&gt;&amp;lt;SHARES&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;3000.0000&lt;span class="xml-tag"&gt;&amp;lt;/SHARES&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="xml-tag"&gt;&amp;lt;/row&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="xml-tag"&gt;&amp;lt;row&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="xml-tag"&gt;&amp;lt;USERID&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;Minollo&lt;span class="xml-tag"&gt;&amp;lt;/USERID&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="xml-tag"&gt;&amp;lt;STOCKTICKER&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;EBAY&lt;span class="xml-tag"&gt;&amp;lt;/STOCKTICKER&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="xml-tag"&gt;&amp;lt;SHARES&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;4000.0000&lt;span class="xml-tag"&gt;&amp;lt;/SHARES&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
   &lt;span class="xml-tag"&gt;&amp;lt;/row&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;   
&lt;span class="xml-tag"&gt;&amp;lt;/HOLDINGS&lt;/span&gt;&lt;span class="xml-tag"&gt;&amp;gt;&lt;/span&gt;
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Here's an XQuery expression that returns the holdings for Jonathan.&lt;/p&gt;

&lt;table bgcolor="#e6e6e6" ID="Table2"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;
&lt;pre&gt;doc("holdings.xml")//holding[USERID="Jonathan"]
&lt;/pre&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Obviously, Jonathan is not the only person whose holdings might
interest us. If we write our XQuery with an external variable, the Java
program can specify the name of the user before it executes the query.
If we also use an external variable to represent the document, the Java
program can pass any document to the query at runtime:&lt;/p&gt;


&lt;table bgcolor="#e6e6e6" ID="Table3"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;
&lt;pre&gt;declare variable $u as xs:string external; 
declare variable $d as document-node(element(*,xdt:untyped)) external; 
$d//holding[USERID=$u] &lt;/pre&gt; &lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;


&lt;p&gt;Now let's write the Java code to create a DOM tree and bind it to the variable $d. We start by creating a DOM tree.&lt;/p&gt;


&lt;table bgcolor="#e4e4e4" ID="Table4"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;
&lt;pre&gt;DocumentBuilderFactory factory =  
        DocumentBuilderFactory.&lt;span class="java-layer-method"&gt;newInstance&lt;/span&gt;();            
factory.&lt;span class="java-layer-method"&gt;setNamespaceAware&lt;/span&gt;(&lt;span class="java-keywords"&gt;true&lt;/span&gt;);            

FileReader fileReader = &lt;span class="java-keywords"&gt;new&lt;/span&gt; &lt;span class="java-layer-method"&gt;FileReader&lt;/span&gt;(&lt;span class="java-string-literal"&gt;"holdings.xml"&lt;/span&gt;);

Document document = parser.&lt;span class="java-layer-method"&gt;parse&lt;/span&gt;(fileReader);
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;


	
&lt;p&gt;Once we create a DOM tree, we can use XQJ to bind it to a variable
and query it. First, let's create an expression object, and then bind
the document to the variable $d for this expression.&lt;/p&gt;

&lt;table bgcolor="#e4e4e4" ID="Table5"&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td&gt;
&lt;pre&gt;    XQConnection connection = dataSource.&lt;span class="java-layer-method"&gt;getConnection&lt;/span&gt;();
    XQExpression xqExpression = connection.&lt;span class="java-layer-method"&gt;createExpression&lt;/span&gt;();

    xqExpression.&lt;span class="java-layer-method"&gt;bindNode&lt;/span&gt;(&lt;span class="java-keywords"&gt;new&lt;/span&gt; &lt;span class="java-layer-method"&gt;QName&lt;/span&gt;(&lt;span class="java-string-literal"&gt;"d"&lt;/span&gt;), document);
    xqExpression.&lt;span class="java-layer-method"&gt;b&lt;/span&gt;&lt;span class="java-layer-method"&gt;indVariable&lt;/span&gt;(&lt;span class="java-keywords"&gt;new&lt;/span&gt; &lt;span class="java-layer-method"&gt;QName&lt;/span&gt;(&lt;span class="java-string-literal"&gt;"u"&lt;/span&gt;), &lt;span class="java-string-literal"&gt;"Jonathan"&lt;/span&gt;));
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Now we can execute the expression and output the result.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=13479781032&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Adobe AIR Mini-Cookbook</title><link>http://www.softxml.com/LearnTutorial.asp?id=16785995828&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;P class="docText"&gt;&lt;A name="This chapter"&gt;&lt;/A&gt;This chapter provides solutions to 
	common tasks when developing Adobe AIR applications. The solutions in this 
	chapter illustrate many concepts used in AIR application development, and 
	provide working HTML and JavaScript code that you can leverage within your 
	application.&lt;/P&gt;
&lt;A name="adobe_air_mini-cookbookd1e4956"&gt;&lt;/A&gt;
&lt;DIV class="docNote"&gt;
	&lt;P class="docNormalTitle"&gt;NOTE&lt;/P&gt;
	&lt;P&gt;
	&lt;P class="docText"&gt;&lt;A name="in this"&gt;&lt;/A&gt;All examples in this chapter assume that 
		you are using &lt;A name="I_indexterm4_d1e4951"&gt;&lt;/A&gt;the &lt;I&gt;AIRAliases.js&lt;/I&gt; file.&lt;/P&gt;
	&lt;P&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;A name="application_deployment"&gt;&lt;/A&gt;
&lt;H3 class="docSection1Title" id="-100000"&gt;4.1. Application Deployment&lt;/H3&gt;
&lt;A name="deploy_from_a_web_page"&gt;&lt;/A&gt;
&lt;H4 class="docSection2Title" id="title-ID0E2UNM"&gt;4.1.1. Deploy from a Web Page&lt;/H4&gt;
&lt;A name="problem"&gt;&lt;/A&gt;
&lt;H5 class="docSection3Title" id="title-ID0E6UNM"&gt;4.1.1.1. Problem&lt;/H5&gt;
&lt;P class="docText"&gt;You have finished&lt;A name="ch04-appdeploy"&gt;&lt;/A&gt;&lt;A name="ch04-deployment"&gt;&lt;/A&gt;&lt;A name="packaged it"&gt;&lt;/A&gt;
	your application, have signed and packaged it, and want to distribute it via a 
	web page.&lt;/P&gt;
&lt;A name="solution"&gt;&lt;/A&gt;
&lt;H5 class="docSection3Title" id="title-ID0ERVNM"&gt;4.1.1.2. Solution&lt;/H5&gt;
&lt;P class="docText"&gt;&lt;A name="can be"&gt;&lt;/A&gt;Adobe AIR applications can be easily 
	distributed from a web page using the badge installer included with the SDK.&lt;/P&gt;
&lt;A name="discussion"&gt;&lt;/A&gt;
&lt;H5 class="docSection3Title" id="title-ID0EWVNM"&gt;4.1.1.3. Discussion&lt;/H5&gt;
&lt;P class="docText"&gt;&lt;A name="distribution once"&gt;&lt;/A&gt;Adobe AIR application files are 
	largely self-contained entities, and are ready for distribution once they are 
	signed and packaged. The resultant file will have an &lt;I&gt;.air&lt;/I&gt; extension. &lt;A name="I_indexterm4_d1e4991"&gt;
	&lt;/A&gt;&lt;A name="be distributed"&gt;&lt;/A&gt;That application file can be distributed via 
	email, CD-ROM, or other traditional forms; however, installing an &lt;I&gt;.air&lt;/I&gt;&lt;A name="present on"&gt;&lt;/A&gt;
	file requires that Adobe AIR is already present on the target machine. 
	Alternatively, a web-page-based "badge installer" can streamline installation 
	by detecting the runtime and installing it if necessary before installing your 
	application.&lt;/P&gt;
&lt;P class="docText"&gt;&lt;A name="in a"&gt;&lt;/A&gt;Though you can customize it in a number of 
	different ways, a sample badge installer&lt;A name="I_indexterm4_d1e5000"&gt;&lt;/A&gt;&lt;A name="takes the"&gt;&lt;/A&gt;
	is included with the Adobe AIR SDK. The badge takes the form of a small 217x180 
	area, which is ideal for a blog sidebar or other constrained spaces. The 
	default badge installer runs as a Flash 9.0.115 (Flash Update 3) component in 
	the browser. The Flash source file (FLA) is also included with the SDK for 
	additional customization.&lt;/P&gt;
&lt;A name="discussiond1e5012"&gt;&lt;/A&gt;
&lt;DIV class="docNote"&gt;
	&lt;P class="docNormalTitle"&gt;NOTE&lt;/P&gt;
	&lt;P&gt;
	&lt;P class="docText"&gt;&lt;A name="sample badge"&gt;&lt;/A&gt;You can find the files for the sample 
		badge installer in the &lt;I&gt;samples/badge&lt;/I&gt;&lt;A name="directory of"&gt;&lt;/A&gt; directory 
		of the SDK.&lt;/P&gt;
	&lt;P&gt;&lt;/P&gt;
&lt;/DIV&gt;
&lt;P class="docText"&gt;&lt;A name="the badge"&gt;&lt;/A&gt;Deploying with the badge installer 
	requires four files:&lt;A name="I_indexterm4_d1e5012"&gt;&lt;/A&gt;&lt;A name="I_indexterm4_d1e5015"&gt;&lt;/A&gt;&lt;A name="I_indexterm4_d1e5018"&gt;&lt;/A&gt;
	&lt;I&gt;badge.swf&lt;/I&gt;, &lt;I&gt;default_badge.html&lt;/I&gt;, &lt;I&gt;AC_RunActiveContent.js&lt;/I&gt;, and 
	your AIR application.&lt;/P&gt;
&lt;P class="docText"&gt;&lt;A name="installer does"&gt;&lt;/A&gt;Even though the badge installer 
	does appear as Flash content on a web page, you do not need to have any Flash 
	knowledge or software such as Adobe Flash CS3. The badge installer was prebuilt 
	with a number of configurable options that you can set from within the 
	containing HTML page. On line 59 of the &lt;I&gt;default_badge.html&lt;/I&gt;&lt;A name="the"&gt;&lt;/A&gt;
	file, you will see the &lt;TT&gt;flashvars&lt;/TT&gt;&lt;A name="to&amp;#13;&amp;#10;        your"&gt;&lt;/A&gt;
	parameter, which is assigned the various initialization properties that are 
	specific to your application. This parameter &lt;A name="I_indexterm4_d1e5039"&gt;&lt;/A&gt;
	&lt;A name="I_indexterm4_d1e5042"&gt;&lt;/A&gt;&lt;A name="I_indexterm4_d1e5045"&gt;&lt;/A&gt;&lt;A name="I_indexterm4_d1e5048"&gt;
	&lt;/A&gt;&lt;A name="I_indexterm4_d1e5051"&gt;&lt;/A&gt;&lt;A name="I_indexterm4_d1e5054"&gt;&lt;/A&gt;&lt;A name="a query"&gt;
	&lt;/A&gt;takes the form of a query string, and has the options outlined in &lt;A class="docLink" href="#badge_installer_flashvars_options"&gt;
		Table 4-1&lt;/A&gt;.&lt;/P&gt;
&lt;A name="badge_installer_flashvars_options"&gt;&lt;/A&gt;
&lt;P&gt;
	&lt;TABLE cellSpacing="0" width="100%" border="1" ID="Table1"&gt;
		&lt;CAPTION&gt;
			&lt;H5 class="docTableTitle"&gt;Table 4-1. Badge Installer flashvars options&lt;/H5&gt;
		&lt;/CAPTION&gt;
		&lt;COLGROUP span="2"&gt;
			&lt;COL&gt;
			&lt;COL&gt;
		&lt;/COLGROUP&gt;
		&lt;THEAD&gt;
			&lt;TR&gt;
				&lt;TH class="docTableCell thead" style="TEXT-ALIGN: left" vAlign="bottom" scope="col"
					align="left"&gt;
					Parameter&lt;/TH&gt;
				&lt;TH class="docTableCell thead" style="TEXT-ALIGN: left" vAlign="bottom" scope="col"
					align="left"&gt;
					Description&lt;/TH&gt;&lt;/TR&gt;
		&lt;/THEAD&gt;
		&lt;TBODY&gt;
			&lt;TR&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;TT&gt;appname&lt;/TT&gt;&lt;/TD&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;A name="badge installer"&gt;&lt;/A&gt;The 
					name of the application, displayed by the badge installer.&lt;/TD&gt;
			&lt;/TR&gt;
			&lt;TR&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;TT&gt;appurl&lt;/TT&gt;&lt;/TD&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;A name="AIR file"&gt;&lt;/A&gt;Required. 
					The URL of the Adobe AIR file to be downloaded. You must use an absolute, not a 
					relative, URL.&lt;/TD&gt;
			&lt;/TR&gt;
			&lt;TR&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;TT&gt;airversion&lt;/TT&gt;&lt;/TD&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;Required. For the 1.0 version of 
					the runtime, set this to &lt;TT&gt;1.0&lt;/TT&gt;.&lt;/TD&gt;
			&lt;/TR&gt;
			&lt;TR&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;TT&gt;imageurl&lt;/TT&gt;&lt;/TD&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;A name="the badge"&gt;&lt;/A&gt;Optional. 
					The URL of the image to display in the badge.&lt;/TD&gt;
			&lt;/TR&gt;
			&lt;TR&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;TT&gt;buttoncolor&lt;/TT&gt;&lt;/TD&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;A name="a hex"&gt;&lt;/A&gt;Optional. 
					The color of the download button (specified as a hex value, such as FFCC00).&lt;/TD&gt;
			&lt;/TR&gt;
			&lt;TR&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;TT&gt;messagecolor&lt;/TT&gt;&lt;/TD&gt;
				&lt;TD class="docTableCell" vAlign="top" align="left"&gt;&lt;A name="The color"&gt;&lt;/A&gt;Optional. 
					The color of the text message displayed below the button (specified as a hex 
					value, such as FFCC00).&lt;/TD&gt;
			&lt;/TR&gt;
		&lt;/TBODY&gt;
	&lt;/TABLE&gt;
&lt;/P&gt;
&lt;BR&gt;
&lt;P class="docText"&gt;&lt;A name="an HTML"&gt;&lt;/A&gt;Here is an HTML page that displays the 
	badge installer to install an AIR application, as well as the AIR runtime if 
	necessary:&lt;/P&gt;
&lt;DIV class="codeSegmentsExpansionLinks"&gt;Code View:&lt;/DIV&gt;
&lt;PRE class=""&gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&amp;gt; 
&amp;lt;head&amp;gt; &amp;lt;title&amp;gt;Adobe AIR Application Installer Page&amp;lt;/title&amp;gt; 
&amp;lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" 
/&amp;gt; &amp;lt;style type="text/css"&amp;gt; &amp;lt;!-- #AIRDownloadMessageTable { width: 
217px; height: 180px; border: 1px solid #999; font-family: Verdana, Arial, 
Helvetica, sans-serif; font-size: 14px; } #AIRDownloadMessageRuntime { 
font-size: 12px; color: #333; } --&amp;gt; &amp;lt;/style&amp;gt; &amp;lt;script 
language="JavaScript" type="text/javascript"&amp;gt; &amp;lt;!-- var 
requiredMajorVersion = 9; var requiredMinorVersion = 0; var requiredRevision = 
115; &amp;lt;/sc &amp;lt;/head&amp;gt; &amp;lt;body bgcolor="#ffffff"&amp;gt; &amp;lt;script 
src="AC_RunActiveContent.js" type="text/javascript"&amp;gt; &amp;lt;/script&amp;gt; 
&amp;lt;script language="JavaScript" type="text/javascript"&amp;gt; &amp;lt;!-- // Version 
check based upon the values entered above in "Globals" var hasRequestedVersion 
= DetectFlashVer( requiredMajorVersion, requiredMinorVersion, requiredRevision 
); // Check to see if the version meets the requirements // for playback if( 
hasReqestedVersion ) { AC_FL_RunContent( 
'codebase','http://fpdownload.macromedia.com/pub/ 
shockwave/cabs/flash/swflash.cab', 'width','217', 'height','180', 'id','badge', 
'align','middle', 'src','badge', 'quality','high', 'bgcolor','#FFFFFF', 
'name','badge', 'allowscriptaccess','all', 
'pluginspage','http://www.macromedia.com/ go/getflashplayer', 
'flashvars','appname=My%20Application&amp;amp;appurl= myapp.air&amp;amp;airversion= 
1.0&amp;amp;imageurl=test.jpg', 'movie','badge' ); //end AC code } else { 
document.write('&amp;lt;table id="AIRDownloadMessageTable"&amp;gt;&amp;lt;tr&amp;gt; 
&amp;lt;td&amp;gt;Download &amp;lt;a href="myapp.air"&amp;gt;My Application&amp;lt;/a&amp;gt; 
now.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;span id="AIRDownloadMessageRuntime"&amp;gt; This 
application requires the &amp;lt;a href="'); var platform = 'unknown'; if( typeof( 
window.navigator.platform ) != undefined ) { platform = 
window.navigator.platform.toLowerCase(); if( platform.indexOf( 'win' ) != -1 ) 
{ platform = 'win'; } else if( platform.indexOf( 'mac' ) != -1 ) { platform = 
'mac'; } } if( platform == 'win' ) { document.write( 
'http://airdownload.adobe.com/air/win/ download/1.0/ AdobeAIRInstaller.exe' ); 
} else if( platform == 'mac' ) { document.write( 
'http://airdownload.adobe.com/air/ mac/download/1.0/ AdobeAIR.dmg' ); } else { 
document.write( 'http://www.adobe.com/go/getair/' ); } document.write( 
'"&amp;gt;Adobe&amp;amp;#174;&amp;amp;nbsp;AIR&amp;amp;#8482; runtime&amp;lt;/a&amp;gt;. 
&amp;lt;/span&amp;gt;&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table&amp;gt;' ); } // --&amp;gt; 
&amp;lt;/script&amp;gt; &amp;lt;noscript&amp;gt; &amp;lt;table id="AIRDownloadMessageTable"&amp;gt; 
&amp;lt;tr&amp;gt; &amp;lt;td&amp;gt; Download &amp;lt;a href="myapp.air"&amp;gt;My 
Application&amp;lt;/a&amp;gt; now.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=16785995828&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Application Chrome</title><link>http://www.softxml.com/LearnTutorial.asp?id=878627672&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class="docSection2Title" id="title-ID0EKUNM"&gt;4.2.1. Add Custom Controls&lt;/H4&gt;
&lt;A name="problem-id1"&gt;&lt;/A&gt;
&lt;H5 class="docSection3Title" id="title-ID0EOUNM"&gt;4.2.1.1. Problem&lt;/H5&gt;
&lt;P class="docText"&gt;You&lt;A name="I_indexterm4_d1e5142"&gt;&lt;/A&gt;&lt;A name="I_indexterm4_d1e5143"&gt;&lt;/A&gt;&lt;A name="ch04-chromeapp"&gt;&lt;/A&gt;&lt;A name="ch04-appchrome"&gt;&lt;/A&gt;&lt;A name="want to"&gt;&lt;/A&gt;
	want to create custom window chrome for your application and you need the user 
	to be able to close and minimize the application.&lt;/P&gt;
&lt;A name="solution-id1"&gt;&lt;/A&gt;
&lt;H5 class="docSection3Title" id="title-ID0EKVNM"&gt;4.2.1.2. Solution&lt;/H5&gt;
&lt;P class="docText"&gt;Use the &lt;TT&gt;NativeWindow&lt;/TT&gt; class &lt;A name="I_indexterm4_d1e5161"&gt;&lt;/A&gt;
	&lt;A name="AIR to"&gt;&lt;/A&gt;within Adobe AIR to integrate, minimize, and close button 
	functionality.&lt;/P&gt;
&lt;A name="discussion-id1"&gt;&lt;/A&gt;
&lt;H5 class="docSection3Title" id="title-ID0EYVNM"&gt;4.2.1.3. Discussion&lt;/H5&gt;
&lt;P class="docText"&gt;&lt;A name="developers to"&gt;&lt;/A&gt;Although Adobe AIR allows developers 
	to completely define and customize the application's window chrome, it is 
	important to remember that when doing so, the application is responsible for 
	every type of windowing event that might normally occur. This means the 
	application must connect the various visual elements with their respective 
	operating system events.&lt;/P&gt;
&lt;P class="docText"&gt;&lt;A name="application on"&gt;&lt;/A&gt;When deploying an application on 
	Adobe AIR, the &lt;TT&gt;window&lt;/TT&gt; object &lt;A name="I_indexterm4_d1e5175"&gt;&lt;/A&gt;gets 
	additional properties. Among those properties is &lt;TT&gt;nativeWindow&lt;/TT&gt;, &lt;A name="I_indexterm4_d1e5182"&gt;
	&lt;/A&gt;&lt;A name="the current"&gt;&lt;/A&gt;which is a reference to the native window that 
	houses the current HTML document. Using the native window reference, the 
	appropriate methods can be called to trigger the operating-system-specific 
	event (or vice versa). In the case of being able to minimize the window, the 
	application can use &lt;TT&gt;NativeWindow.minimize()&lt;/TT&gt;; &lt;A name="I_indexterm4_d1e5190"&gt;
	&lt;/A&gt;it can use&lt;A name="I_indexterm4_d1e5194"&gt;&lt;/A&gt; &lt;TT&gt;NativeWindow.close()&lt;/TT&gt;&lt;A name="closing it"&gt;&lt;/A&gt;
	in the case of closing it:&lt;/P&gt;
&lt;PRE&gt;window.nativeWindow.minimize();
window.nativeWindow.close();
&lt;/PRE&gt;
&lt;BR&gt;
&lt;P class="docText"&gt;The &lt;TT&gt;NativeWindow.close()&lt;/TT&gt;&lt;A name="only one"&gt;&lt;/A&gt; method 
	does not necessarily terminate the application. If only one application window 
	is available, the application will terminate. If multiple windows are 
	available, they will close until only one window remains. Closing the last 
	window terminates the application.&lt;/P&gt;
&lt;A name="application.xml"&gt;&lt;/A&gt;
&lt;H5 class="docSection3Title" id="title-ID0EHXNM"&gt;4.2.1.4. application.xml&lt;/H5&gt;
&lt;PRE&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;
&amp;lt;application xmlns="http://ns.adobe.com/air/application/1.0"&amp;gt;

    &amp;lt;id&amp;gt;com.adobe.demo.CustomControls&amp;lt;/id&amp;gt;
    &amp;lt;name&amp;gt;Custom Controls&amp;lt;/name&amp;gt;
    &amp;lt;version&amp;gt;1.0&amp;lt;/version&amp;gt;
    &amp;lt;filename&amp;gt;Custom Controls&amp;lt;/filename&amp;gt;
    &amp;lt;description&amp;gt;Adding Custom Window Controls&amp;lt;/description&amp;gt;

    &amp;lt;initialWindow&amp;gt;

         &amp;lt;title&amp;gt;Custom Controls&amp;lt;/title&amp;gt;
         &amp;lt;content&amp;gt;index.html&amp;lt;/content&amp;gt;
         &amp;lt;systemChrome&amp;gt;none&amp;lt;/systemChrome&amp;gt;
         &amp;lt;transparent&amp;gt;true&amp;lt;/transparent&amp;gt;
         &amp;lt;visible&amp;gt;true&amp;lt;/visible&amp;gt;
         &amp;lt;width&amp;gt;206&amp;lt;/width&amp;gt;
         &amp;lt;height&amp;gt;206&amp;lt;/height&amp;gt;

  &amp;lt;/initialWindow&amp;gt;

&amp;lt;/application&amp;gt;
&lt;/PRE&gt;
&lt;BR&gt;
&lt;A name="index.html"&gt;&lt;/A&gt;
&lt;H5 class="docSection3Title" id="title-ID0EOXNM"&gt;4.2.1.5. index.html&lt;/H5&gt;
&lt;DIV class="codeSegmentsExpansionLinks"&gt;Code View:&lt;/DIV&gt;
&lt;PRE class=""&gt;
&amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;title&amp;gt;Custom Window Controls&amp;lt;/title&amp;gt; 
&amp;lt;style&amp;gt; body { background-image: url( 'custom-chrome.gif' ); font-family: 
Verdana, Geneva, Arial, Helvetica, sans-serif; font-size: 12px; } #closer { 
position: absolute; width: 70px; left: 68px; top: 105px; } #minimize { 
position: absolute; width: 70px; left: 68px; top: 75px; } textarea { position: 
absolute; left: 8px; right: 8px; bottom: 8px; top: 36px; border-color: #B3B3B3; 
} #title { position: absolute; font-weight: bold; color: #FFFFFF; } 
&amp;lt;/style&amp;gt; &amp;lt;script type="text/javascript" 
src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt; &amp;lt;script&amp;gt; function doClose() { 
window.nativeWindow.close(); } function doLoad() { document.getElementById( 
"minimize" ).</description><guid>http://www.softxml.com/LearnTutorial.asp?id=878627672&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Windowing</title><link>http://www.softxml.com/LearnTutorial.asp?id=3529601986&amp;f=adobeair&amp;fo=tutorials</link><description>4.3.1. Create a New Window
4.3.1.1. Problem
You need to display an additional widow into which additional content can be loaded.

4.3.1.2. Solution
Basic windows can be generated and maintained in a similar fashion as traditional HTML content using the window.open() method.

4.3.1.3. Discussion
The JavaScript window.open() method invokes a new window similar to the way it would when used in the browser. Content that gets loaded into the new window can come from a local file, or URL endpoint. Similar to windows created using JavaScript in the browser, there is finite control over the window itself. The window properties that can be controlled are width, height, scrollbars, and resizable.

var login = window.open( 'login.html', 'login', 'width = 300, 
height = 200' );



A native window is a better choice when additional control over the new window is required. Native windows expose virtually the entire functionality of the operating system, such as control over minimize and maximize functionality, always in front, full screen, and even removal of system chrome altogether. The choice between using window.open() and NativeWindow depends largely on the requirements for the window and the overall portability of the JavaScript source code.

NOTE


You also can use the window.opener property, which is commonly used in JavaScript to refer from a new window to the parent (creating) window.


Code View:
&lt;html&gt;
&lt;head&gt;

&lt;title&gt;Creating a New Window&lt;/title&gt;

&lt;style type="text/css"&gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&lt;/style&gt;

&lt;script type="text/javascript"&gt;
function doLoad()
{
    document.getElementById( 'window' ).addEventListener( 
    'click', doWindow );
}

function doWindow()
{
    var login = window.open( 'login.html', null, 'width = 325, 
    height = 145' );
}

function doLogin( email, pass )
{
    alert( 'Welcome: ' + email );
}
&lt;/script&gt;

&lt;/head&gt;
&lt;body onLoad="doLoad();"&gt;

&lt;input id="window" type="button" value="Login" /&gt;

&lt;/body&gt;
&lt;/html&gt;


					  


4.3.1.4. Login.html
Code View:
&lt;html&gt;
&lt;head&gt;

&lt;title&gt;Login&lt;/title&gt;

&lt;style type="text/css"&gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&lt;/style&gt;

&lt;script&gt;
function doLoad()
{
    document.getElementById( 'signIn' ).addEventListener( 
    'click', doSignIn );
}

function doSignIn()
{
    var email = document.getElementById( 'email' ).value;
    var password = document.getElementById( 'password' )
    .value;

    window.opener.doLogin( email, password );
}
&lt;/script&gt;

&lt;/head&gt;
&lt;body onLoad="doLoad();"&gt;

&lt;table&gt;
    &lt;tr&gt;
         &lt;td&gt;Email:&lt;/td&gt;
         &lt;td&gt;&lt;input id="email" name="email" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
         &lt;td&gt;Password:&lt;/td&gt;
         &lt;td&gt;&lt;input id="password" name="password" 
         type="password" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
         &lt;td colspan="2" align="right"&gt;
              &lt;input id="signIn" type="button" 
               value="Sign In" /&gt;
         &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;/body&gt;
&lt;/html&gt;


					  


4.3.2. Create a New Native Window
4.3.2.1. Problem
You need to display an additional window into which content can be loaded, and you need to be able to fine-tune how the new window appears.

4.3.2.2. Solution
The HTMLLoader class represents the root content of an HTML-based Adobe AIR application, and has various methods for creating and loading new native windows that require a high degree of customization and control.

4.3.2.3. Discussion
Creating and managing native windows with Adobe AIR is highly customizable. As an example, depending on the application requirements, you may want to hide the minimize and maximize buttons. You may also want to control window z-ordering, or force a particular window to always stay on top. The NativeWindow and NativeWindowInitOptions classes offer control over virtually all of these aspects of a native window. Although you can access the native window directly through the window.nativeWindow property, the HTMLLoader class provides much of the functionality for creating new native windows.

Calling HTMLLoader.createRootWindow() returns a reference to the HTMLLoader instance of the newly created window (not the native window itself). The HTMLLoader.createRootWindow() method can take up to four arguments controlling initial visibility, initialization options, scroll bars, and window bounds (i.e., the size and position on the screen). The initialization options are passed through an instance of NativeWindowInitOptions, which must be created and configured prior to creating the new native window. The NativeWindowInitOptions object controls aspects of the window such as whether it is resizable, or even whether it has any system chrome at all. The NativeWindowInitOptions constructor takes no arguments:

var options = new air.NativeWindowInitOptions();
var login = null;
var bounds = new air.Rectangle(
    ( air.Capabilities.screenResolutionX - 270 ) / 2,
    ( air.Capabilities.screenResolutionY - 150 ) / 2,
    270,
    150 );

options.minimizable = false;
options.maximizable = false;
options.resizable = false;

login = new air.HTMLLoader.createRootWindow( false, 
options, true, bounds );



All of the arguments for HTMLLoader.createRootWindow() have default values which can be further explored in the Adobe AIR documentation. Not all of the options an application may use appear as initialization options. Additional options that may be controlled on an instance of NativeWindow itself include the window title, and whether it is always in front.

NOTE


In many cases, it is beneficial to start with an invisible window. This will allow the window to size and position itself, load the desired content, and then lay out and render the application without impacting what is displayed. This technique falls into a broader classification that is often referred to as perceived performance and is a very important aspect to consider during development.


Once a reference to the HTMLLoader instance of a new native window is obtained, you can load content into it via the HTMLLoader.load() method. The HTMLLoader.load() method takes a single argument which is a URLRequest instance that points to the HTML content to be loaded into the new window:

Code View:
&lt;html&gt;
&lt;head&gt;

&lt;title&gt;Creating a New Native Window&lt;/title&gt;

&lt;script src="AIRAliases.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;style type="text/css"&gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&lt;/style&gt;

&lt;script type="text/javascript"&gt;
function doLoad()
{
    document.getElementById( 'window' ).addEventListener
( 'click', doWindow );
}

function doWindow()
{
    var init = new air.NativeWindowInitOptions();
    var bounds = null;
    var win = null;
    var login = air.File.applicationDirectory.resolvePath
    ( 'login.html' );

   bounds = new air.Rectangle( ( air.Capabilities.
   screenResolutionX - 325 ) / 2,
 ( air.Capabilities.screenResolutionY - 145 ) / 2, 325, 145 );

    init.minimizable = false;
    init.maximizable = false;
    init.resizable = false;

    win = air.HTMLLoader.createRootWindow( true, init, false, 
    bounds );
    win.load( new air.URLRequest( login.url ) );
}
&lt;/script&gt;

&lt;/head&gt;
&lt;body onLoad="doLoad();"&gt;

&lt;input id="window" type="button" value="Login" /&gt;

&lt;/body&gt;
&lt;/html&gt;


					  


4.3.2.4. Login.html
Code View:
&lt;html&gt;
&lt;head&gt;

&lt;title&gt;Login&lt;/title&gt;

&lt;style type="text/css"&gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&lt;/style&gt;

&lt;script&gt;
function doLoad()
{
    document.getElementById( 'signIn' ).addEventListener
    ( 'click', doSignIn );
}

function doSignIn()
{
    window.nativeWindow.close();
}
&lt;/script&gt;

&lt;/head&gt;
&lt;body onLoad="doLoad();"&gt;

&lt;table&gt;
    &lt;tr&gt;
         &lt;td&gt;Email:&lt;/td&gt;
         &lt;td&gt;&lt;input id="email" name="email" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
         &lt;td&gt;Password:&lt;/td&gt;
         &lt;td&gt;&lt;input id="password" name="password" type=
         "password" /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
         &lt;td colspan="2" align="right"&gt;
              &lt;input id="signIn" type="button" 
               value="Sign In" /&gt;
         &lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;/body&gt;
&lt;/html&gt;


					  


4.3.3. Create Full-Screen Windows
4.3.3.1. Problem
For the purpose of enabling more viewing space or enabling additional interactions, your application needs to be able to run using the full screen.

4.3.3.2. Solution
The HTMLLoader class provides the functionality to create new native windows, which, when used in conjunction with the NativeWindowInitOptions class, can create transparent and full-screen native windows.

4.3.3.3. Discussion
The difference between using NativeWindowInitOptions for full-screen display and using NativeWindowInitOptions for custom windows is an additional initialization option and setting the window to fill the screen. To remove any OS-specific windowing chrome, use the NativeWindowInitOptions.systemChrome property. The NativeWindowInitOptions.systemChrome property should be set to one of the two string constants found in the NativeWindowSystemChrome class (see Table 4-2).

Table 4-2. String constants in NativeWindowSystemChrome String constant Description 
NativeWindowSystemChrome.STANDARD This is the default for NativeWindow and reflects the window chrome used on the specific operating system. 
NativeWindowSystemChrome.NONE This indicates that no chrome should be present, and requires that the application handle all traditional windowing tasks. 




To create a full-screen window without any chrome, set the NativeWindowInitOptions.systemChrome property to NativeWindowSystemChrome.NONE. Window boundaries that match the full-screen resolution can be passed when calling HTMLLoader.createRootWindow(). The boundaries for the window are passed to the HTMLLoader.createRootWindow() method as a Rectangle object which specifies horizontal and vertical origination, as well as width and height. Depending on the requirements for the application, an alternative approach would be to call NativeWindow.maximize() or to set NativeWindow.bounds directly when system chrome is set to NativeWindowSystemChrome.NONE.

NOTE


If you find yourself confronted with an application that doesn't shut down, but whose visible windows are all closed, you're probably dealing with one of a few different challenges. The first is that you never set a size on a NativeWindow. The second is that you never set a NativeWindow to visible. The most common is that you used NativeWindowSystemChrome.NONE, but never added any content.


Code View:
&lt;html&gt;
&lt;head&gt;

&lt;title&gt;Creating a Full Screen Window&lt;/title&gt;

&lt;script src="AIRAliases.js" type="text/javascript"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
function doLoad()
{
    var init = new air.NativeWindowInitOptions();
    var win = null;
    var bounds = new air.Rectangle( 0,
                                    0,
                                    air.Capabilities.
                                    screenResolutionX,
                                    air.Capabilities.
                                    screenResolutionY );

    init.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=3529601986&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>File API</title><link>http://www.softxml.com/LearnTutorial.asp?id=24004234340&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class=docSection2Title id=title-ID0E3UNM&gt;4.4.1. Write Text to a File from a 
String&lt;/H4&gt;&lt;A name=problem-id5&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EAVNM&gt;4.4.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name=A&gt;&lt;/A&gt;A &lt;A name=I_indexterm4_d1e5580&gt;&lt;/A&gt;user&lt;A 
name=I_indexterm4_d1e5582&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e5583&gt;&lt;/A&gt; &lt;A 
name=ch04-fileapi&gt;&lt;/A&gt;&lt;A name="changes to"&gt;&lt;/A&gt;has made changes to textual 
content in the application, which need to be saved to the local disk for offline 
access.&lt;/P&gt;&lt;A name=solution-id5&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E4VNM&gt;4.4.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="through the"&gt;&lt;/A&gt;You can write text through the 
&lt;TT&gt;File&lt;/TT&gt; and &lt;TT&gt;FileStream&lt;/TT&gt; classes&lt;A name=I_indexterm4_d1e5600&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e5603&gt;&lt;/A&gt;&lt;A name="of Adobe"&gt;&lt;/A&gt; that are part of Adobe 
AIR.&lt;/P&gt;&lt;A name=discussion-id5&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0ESWNM&gt;4.4.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="to a"&gt;&lt;/A&gt;Before any reading or writing to disk takes 
place, a reference to a file or directory must exist in the application. You can 
establish a file reference in a number of ways, including via programmatic 
manipulation and user selection. You accomplish both of these by using the 
&lt;TT&gt;File&lt;/TT&gt; class. The &lt;TT&gt;File&lt;/TT&gt;&lt;A name="properties that"&gt;&lt;/A&gt; class also 
contains static properties that point to common locations on the operating 
system. These locations include the desktop directory, user directory, and 
documents directory:&lt;/P&gt;&lt;PRE&gt;var file =
air.File.applicationStorageDirectory.
resolvePath( 'myFile.txt' );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The call to &lt;TT&gt;File.resolvePath()&lt;/TT&gt; creates&lt;A 
name=I_indexterm4_d1e5625&gt;&lt;/A&gt; a reference to a file named &lt;I&gt;myFile.txt&lt;/I&gt;&lt;A 
name="reference has"&gt;&lt;/A&gt; located in the application storage directory. Once a 
reference has been established, it can be used in file I/O operations. Note that 
this doesn't actually create the file at this point.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="disk is"&gt;&lt;/A&gt;Physically reading and writing to disk is 
accomplished using the &lt;TT&gt;FileStream&lt;/TT&gt; class. The &lt;TT&gt;FileStream&lt;/TT&gt; class 
does not take any arguments in its constructor:&lt;/P&gt;&lt;PRE&gt;var stream = new air.FileStream();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;With the file reference available and a &lt;TT&gt;FileStream&lt;/TT&gt;&lt;A 
name="can take"&gt;&lt;/A&gt; object instantiated, the process of writing data to disk 
can take place. The type of data that can be written may be anything from 
binary, to text, to value objects. You can access all of these by using the 
respective &lt;TT&gt;FileStream&lt;/TT&gt; method for that operation.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="is to"&gt;&lt;/A&gt;The first step in writing a file is to open 
it using the &lt;TT&gt;FileStream.open()&lt;/TT&gt; method. &lt;A 
name=I_indexterm4_d1e5655&gt;&lt;/A&gt;&lt;A name=The&gt;&lt;/A&gt;The &lt;TT&gt;FileStream.open()&lt;/TT&gt;&lt;A 
name="two arguments"&gt;&lt;/A&gt; method takes two arguments. The first argument is the 
file reference created earlier that will be the destination of the output. The 
second argument is the type of file access the application will need. In the 
case of writing data to a file, the &lt;TT&gt;FileMode.WRITE&lt;/TT&gt; static &lt;A 
name=I_indexterm4_d1e5665&gt;&lt;/A&gt;&lt;A name="A second"&gt;&lt;/A&gt;property will be most 
common. A second possibility is &lt;TT&gt;FileMode.APPEND&lt;/TT&gt;, &lt;A 
name=I_indexterm4_d1e5673&gt;&lt;/A&gt;&lt;A name="application requirements"&gt;&lt;/A&gt;depending 
on the application requirements:&lt;/P&gt;&lt;PRE&gt;stream.open( file, air.FileMode.WRITE );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;When writing text, an application should use 
&lt;TT&gt;FileStream.writeMultiByte()&lt;/TT&gt; to ensure that data is written with the 
correct encoding. The &lt;TT&gt;FileStream.writeMultiByte()&lt;/TT&gt; method &lt;A 
name=I_indexterm4_d1e5687&gt;&lt;/A&gt;takes two arguments. The first argument is the 
&lt;TT&gt;String&lt;/TT&gt;&lt;A name="the character"&gt;&lt;/A&gt; object (text) that will be written 
to disk. The second argument is the character set to be used. The most common 
character set is that which the operating system is using, which is available on 
the &lt;TT&gt;File&lt;/TT&gt; class as&lt;A name=I_indexterm4_d1e5698&gt;&lt;/A&gt; 
&lt;TT&gt;File.systemCharset&lt;/TT&gt;:&lt;/P&gt;&lt;PRE&gt;stream.writeMultiByte( document.getElementById
('txtNote' ).value, air.File.systemCharset );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="been written"&gt;&lt;/A&gt;Once the text has been written to 
the file, it is important to close the file to avoid any corruption or blocking 
of access from other applications. You close a file using the 
&lt;TT&gt;FileStream.close()&lt;/TT&gt; method.&lt;/P&gt;&lt;A name=discussion-id5d1e5721&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="as such"&gt;&lt;/A&gt;XML data is already in textual format 
and, as such, can be written to disk using this same series of steps. If the 
application uses the &lt;TT&gt;XMLHttpRequest&lt;/TT&gt; object, using the 
&lt;TT&gt;myXml.responseText&lt;/TT&gt;&lt;A name="for most"&gt;&lt;/A&gt; property alone may be 
adequate for most situations.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Writing a Text File&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}

#save {
    position: absolute;
    right: 5px;
    bottom: 5px;
}

textarea {
    position: absolute;
    left: 5px;
    right: 5px;
    top: 5px;
    bottom: 32px;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
function doLoad()
{
    document.getElementById( 'save' ).
    addEventListener( 'click', doSave );
}

function doSave()
{
    var file = air.File.desktopDirectory.
    resolvePath( 'note.txt' );
    var note = document.getElementById( 'note' ).value;
    var stream = new air.FileStream();

    stream.open( file, air.FileMode.WRITE );
    stream.writeMultiByte( note, air.File.systemCharset );
    stream.close();
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;

&amp;lt;textarea id="note"&amp;gt;&amp;lt;/textarea&amp;gt;
&amp;lt;input id="save" type="button" value="Save" /&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=synchronously_read_text_from_a_file&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0ER1NM&gt;4.4.2. Synchronously Read Text from 
a File&lt;/H4&gt;&lt;A name=problem-id6&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EV1NM&gt;4.4.2.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="small text"&gt;&lt;/A&gt;You want to read the contents of a 
small text file into your application.&lt;/P&gt;&lt;A name=solution-id6&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E11NM&gt;4.4.2.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Use the &lt;TT&gt;File&lt;/TT&gt; and &lt;TT&gt;FileStream&lt;/TT&gt; &lt;A 
name=I_indexterm4_d1e5743&gt;&lt;/A&gt;classes&lt;A name=I_indexterm4_d1e5747&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e5752&gt;&lt;/A&gt;&lt;A name="on&amp;#13;&amp;#10;        text"&gt;&lt;/A&gt; provided 
by Adobe AIR to locate, open, and operate on text files.&lt;/P&gt;&lt;A 
name=discussion-id6&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EW2NM&gt;4.4.2.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="You can"&gt;&lt;/A&gt;You can read small files that contain 
text content using the &lt;TT&gt;FileStream.open()&lt;/TT&gt; method. &lt;A 
name=I_indexterm4_d1e5766&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e5769&gt;&lt;/A&gt;&lt;A 
name="opens a"&gt;&lt;/A&gt;This method opens a file synchronously for reading. 
Synchronous access requires less code, but also blocks any additional user input 
until the data has been read. When using asynchronous access, additional user 
input is not blocked, but event handlers must be registered, which results in 
more development time.&lt;/P&gt;&lt;A name=discussion-id6d1e5781&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="to access"&gt;&lt;/A&gt;Although it is possible to access XML 
files as text, the result of this approach is a string of text that can't be 
readily manipulated. Accessing an XML file for use as a data source is often 
more easily handled using &lt;TT&gt;XMLHttpRequest&lt;/TT&gt;&lt;A name="offered by"&gt;&lt;/A&gt; or 
wrapper functionality offered by most JavaScript libraries.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="the&amp;#13;&amp;#10;        same"&gt;&lt;/A&gt;The steps for 
synchronously reading a file are almost always the same:&lt;/P&gt;
&lt;DIV style="FONT-WEIGHT: bold"&gt;
&lt;OL class=docList type=1&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Get a &lt;TT&gt;File&lt;/TT&gt; reference.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Create a &lt;TT&gt;FileStream&lt;/TT&gt; object.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;&lt;A name="synchronous access"&gt;&lt;/A&gt;Open the stream for 
synchronous access.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Call the appropriate &lt;TT&gt;FileStream&lt;/TT&gt; read 
methods.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Close the file.&lt;/P&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="file is"&gt;&lt;/A&gt;The first step to reading a text file is 
to get a reference to the resource on disk. You can establish a reference by 
programmatically designating a path using the appropriate property on the 
&lt;TT&gt;File&lt;/TT&gt; object, such as &lt;TT&gt;File.applicationStorageDirectory&lt;/TT&gt;&lt;A 
name=call&gt;&lt;/A&gt;. You will also have to call &lt;TT&gt;File.resolvePath()&lt;/TT&gt; &lt;A 
name=I_indexterm4_d1e5817&gt;&lt;/A&gt;when using this approach, as the static 
&lt;TT&gt;File&lt;/TT&gt; class properties always return a directory:&lt;/P&gt;&lt;PRE&gt;var file =
air.File.applicationStorageDirectory.
resolvePath('myFile.txt' );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;FileStream&lt;/TT&gt;&lt;A name="instantiated anywhere"&gt;&lt;/A&gt; 
class has an empty constructor and can be instantiated anywhere in your 
application. The file reference just established is used during the physical 
process of opening the file. The mode for which the file is going to be opened 
must also be specified.&lt;/P&gt;
&lt;P class=docText&gt;The &lt;TT&gt;FileMode&lt;/TT&gt;&lt;A name="provide constants"&gt;&lt;/A&gt; object 
serves no purpose other than to provide constants for the types of file access 
that can be performed. These operations are &lt;TT&gt;FileMode.READ&lt;/TT&gt;, 
&lt;TT&gt;FileMode.WRITE&lt;/TT&gt;, &lt;TT&gt;FileMode.UPDATE&lt;/TT&gt;&lt;A name=and&gt;&lt;/A&gt;, and 
&lt;TT&gt;FileMode.APPEND&lt;/TT&gt;:&lt;/P&gt;&lt;PRE&gt;var stream = new air.FileStream();
stream.open( file, air.FileMode.READ );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="use three"&gt;&lt;/A&gt;You can use three &lt;TT&gt;FileStream&lt;/TT&gt;&lt;A 
name="data from"&gt;&lt;/A&gt; methods to read character data from a file. The 
&lt;TT&gt;FileStream.readUTF()&lt;/TT&gt; &lt;A name=I_indexterm4_d1e5858&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e5861&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e5864&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e5867&gt;&lt;/A&gt;and &lt;TT&gt;FileStream.readUTFBytes()&lt;/TT&gt;&lt;A 
name="tuned for"&gt;&lt;/A&gt; methods are specifically tuned for UTF data.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="the application"&gt;&lt;/A&gt;If this is the target format of 
the data for the application, you should use these methods directly. In the case 
of other character sets, you can use the &lt;TT&gt;FileStream.readMultiByte()&lt;/TT&gt;&lt;A 
name="target format"&gt;&lt;/A&gt; method to specify the target format. Additional 
character sets are specified in the form of a string, such as 
&lt;TT&gt;us-ascii&lt;/TT&gt;&lt;A name=the&gt;&lt;/A&gt;. There is also a convenience property on the 
&lt;TT&gt;File&lt;/TT&gt;&lt;A name="system&amp;#13;&amp;#10;        character"&gt;&lt;/A&gt; object to use the 
default system character set, &lt;TT&gt;File.systemCharset&lt;/TT&gt;.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="bytes to"&gt;&lt;/A&gt;You also need to specify the number of 
bytes to be read in the case of &lt;TT&gt;FileStream.readUTFBytes()&lt;/TT&gt; and 
&lt;TT&gt;FileStream.readMultiByte()&lt;/TT&gt;&lt;A name="requirements of"&gt;&lt;/A&gt;. This sizing 
will depend largely on the requirements of the application. When reading the 
entire file is required, you can find the number of bytes available to be read 
on the &lt;TT&gt;FileStream.bytesAvailable&lt;/TT&gt; property:&lt;/P&gt;&lt;PRE&gt;var data = stream.readMultiByte( stream.bytesAvailable, 
air.File.systemCharset );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="Once the"&gt;&lt;/A&gt;Once the contents of a file have been 
read, it is important to close the file. This operation will allow other 
applications to access the file:&lt;/P&gt;&lt;PRE&gt;stream.close();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="demonstrable amount"&gt;&lt;/A&gt;Although a demonstrable 
amount of flexibility has been provided by Adobe AIR, the actual process in its 
entirety is considerably concise. This brevity is provided when performing 
synchronous data access operations. Synchronous file access should be reserved 
for smaller files regardless of reading or writing character or binary data:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Synchronous File Access&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}

textarea {
    position: absolute;
    left: 5px;
    right: 5px;
    top: 5px;
    bottom: 5px;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script&amp;gt;
function doLoad()
{
    var data = null;
    var file = new air.File();
    var stream = null;

    file = air.File.applicationDirectory.resolvePath(
     'the-raven.txt' );

    stream = new air.FileStream();
    stream.open( file, air.FileMode.READ );
    data = stream.readMultiByte( stream.bytesAvailable, 
    air.File.systemCharset );
    stream.close();

    document.getElementById( 'editor' ).value = data;
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;

&amp;lt;textarea id="editor"&amp;gt;&amp;lt;/textarea&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=asynchronously_read_text_from_a_file&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0EZAOM&gt;4.4.3. Asynchronously Read Text 
from a File&lt;/H4&gt;&lt;A name=problem-id7&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E4AOM&gt;4.4.3.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;You want to &lt;A name=I_indexterm4_d1e5918&gt;&lt;/A&gt;&lt;A 
name="of text"&gt;&lt;/A&gt;read a large amount of text into your application without 
impacting the user interface.&lt;/P&gt;&lt;A name=solution-id7&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EIBOM&gt;4.4.3.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Use the &lt;TT&gt;File&lt;/TT&gt; and &lt;TT&gt;FileStream&lt;/TT&gt; classes&lt;A 
name=I_indexterm4_d1e5933&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e5938&gt;&lt;/A&gt;&lt;A 
name="on the"&gt;&lt;/A&gt; to asynchronously operate on the data; ensuring that the 
application execution is not blocked while the file is being processed.&lt;/P&gt;&lt;A 
name=discussion-id7&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E6BOM&gt;4.4.3.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="using the"&gt;&lt;/A&gt;Files containing a large amount of data 
should be read using the &lt;TT&gt;FileStream.openAsync()&lt;/TT&gt; method.&lt;A 
name=I_indexterm4_d1e5952&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e5955&gt;&lt;/A&gt;&lt;A 
name="file asynchronously"&gt;&lt;/A&gt; This method opens a file asynchronously for 
reading or writing and will not block additional user input. Asynchronous file 
operations achieve this goal by raising events during processing. The result is 
that event listeners must be created and registered on the &lt;TT&gt;FileStream&lt;/TT&gt; 
object.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="are almost"&gt;&lt;/A&gt;The steps for asynchronously reading a 
file are almost always the same:&lt;/P&gt;
&lt;DIV style="FONT-WEIGHT: bold"&gt;
&lt;OL class=docList type=1&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Get a &lt;TT&gt;File&lt;/TT&gt; reference.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Create a &lt;TT&gt;FileStream&lt;/TT&gt; object.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Create event handlers for processing data.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Add event listeners for asynchronous operations.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Open the stream for asynchronous access.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Close the file.&lt;/P&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="a text"&gt;&lt;/A&gt;The first step to reading a text file is 
to get a reference to the resource on disk. You can establish a reference by 
programmatically designating a path using the appropriate property on the 
&lt;TT&gt;File&lt;/TT&gt; object, such as &lt;TT&gt;File.applicationStorageDirectory&lt;/TT&gt;:&lt;/P&gt;&lt;PRE&gt;var file =
air.File.applicationStorageDirectory.
resolvePath('myFile.txt' );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;A &lt;TT&gt;FileStream&lt;/TT&gt;&lt;A name="the file"&gt;&lt;/A&gt; instance is 
necessary to read or write to the file:&lt;/P&gt;&lt;PRE&gt;stream = new air.FileStream();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;Before registering event handlers on a &lt;TT&gt;FileStream&lt;/TT&gt;&lt;A 
name="are triggered"&gt;&lt;/A&gt; object, you must create those handlers. The events 
that are triggered by file I/O operations using the &lt;TT&gt;FileStream&lt;/TT&gt;&lt;A 
name="class will"&gt;&lt;/A&gt; class will always pass an event object as an argument. 
The properties on the event object will depend on the type of event being 
raised. This object can be helpful in determining the target 
&lt;TT&gt;FileStream&lt;/TT&gt;&lt;A name="data is"&gt;&lt;/A&gt; object, how much data is available for 
reading, how much data is waiting to be written, and more:&lt;/P&gt;&lt;PRE&gt;function doProgress( event )
{
    // Read all the data that is currently available
    var data = stream.readMultiByte( stream.bytesAvailable, 
    air.File.systemCharset );

    // Append the most recent content
    document.getElementById( "editor" ).value += data;

    // Close the file after the entire contents
    // have been read
    if( event.bytesLoaded == event.bytesTotal )
    {
        stream.close();
    }
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="place using"&gt;&lt;/A&gt;Registering for events takes place 
using &lt;A name=I_indexterm4_d1e6021&gt;&lt;/A&gt;the &lt;TT&gt;addEventListener()&lt;/TT&gt; 
method:&lt;/P&gt;&lt;PRE&gt;stream.addEventListener( air.ProgressEvent.PROGRESS, 
doProgress );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="a stream"&gt;&lt;/A&gt;You can open a stream for asynchronous 
access using the &lt;TT&gt;FileStream.openAsync()&lt;/TT&gt; method. The 
&lt;TT&gt;FileStream.openAsync()&lt;/TT&gt;&lt;A name="and the"&gt;&lt;/A&gt; method takes two arguments 
that specify the file being accessed and the type of access being performed.&lt;/P&gt;
&lt;P class=docText&gt;The &lt;TT&gt;FileMode&lt;/TT&gt;&lt;A name="other than"&gt;&lt;/A&gt; object serves no 
purpose other than to provide constants for the types of file access that can be 
performed. These operations are&lt;A name=I_indexterm4_d1e6044&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e6047&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e6050&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e6053&gt;&lt;/A&gt; &lt;TT&gt;FileMode.READ&lt;/TT&gt;, &lt;TT&gt;FileMode.WRITE&lt;/TT&gt;, 
&lt;TT&gt;FileMode.UPDATE&lt;/TT&gt;, and &lt;TT&gt;FileMode.APPEND&lt;/TT&gt;:&lt;/P&gt;&lt;PRE&gt;stream.openAsync( file, air.FileMode.READ );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="and new"&gt;&lt;/A&gt;As soon as the file is opened and new 
data is available in the stream, the &lt;TT&gt;ProgressEvent.PROGRESS&lt;/TT&gt;&lt;A 
name="size of"&gt;&lt;/A&gt; event is triggered. Depending on the size of the file, as 
well as machine and network characteristics, not all of the bytes may be read in 
a single pass. In many cases, additional read operations take place, raising&lt;A 
name=I_indexterm4_d1e6077&gt;&lt;/A&gt; a &lt;TT&gt;ProgressEvent.PROGRESS&lt;/TT&gt; event for each 
iteration.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="from the"&gt;&lt;/A&gt;Once all of the data has been read from 
the file, an &lt;TT&gt;Event.COMPLETE&lt;/TT&gt; &lt;A name=I_indexterm4_d1e6089&gt;&lt;/A&gt;event is 
broadcast.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="important to"&gt;&lt;/A&gt;After the file has been read, it is 
important to close the file stream to ensure that other applications can access 
it:&lt;/P&gt;&lt;PRE&gt;stream.close();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="This example"&gt;&lt;/A&gt;This example provides a baseline for 
the various types of asynchronous access an application might choose to perform. 
In this case, the contents of the file are read and placed into an HTML text 
area each time more data is available. Asynchronous processing also provides the 
means for random file access (seek) without interrupting the user interface. An 
application should always use asynchronous access whenever the size of a file is 
in question.&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Asynchronous File Access&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}

textarea {
    position: absolute;
    left: 5px;
    right: 5px;
    top: 5px;
    bottom: 5px;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var stream = null;

function doLoad()
{
    var file = air.File.applicationDirectory.resolvePath(
     'the-raven.txt' );

    stream = new air.FileStream();
    stream.addEventListener( air.ProgressEvent.PROGRESS, 
    doProgress );
    stream.openAsync( file, air.FileMode.READ );
}

function doProgress( event )
{
    var data = stream.readMultiByte( stream.bytesAvailable, 
    air.File.systemCharset );

    document.getElementById( 'editor' ).value += data;

    if( event.bytesLoaded == event.bytesTotal )
    {
         stream.close();
    }
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;

&amp;lt;textarea id="editor"&amp;gt;&amp;lt;/textarea&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=load_data_from_an_xml_file&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0EHHOM&gt;4.4.4. Load Data from an XML 
File&lt;/H4&gt;&lt;A name=problem-id8&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0ELHOM&gt;4.4.4.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name=to&gt;&lt;/A&gt;You want to &lt;A name=ch04-xmlloading&gt;&lt;/A&gt;&lt;A 
name="a local"&gt;&lt;/A&gt;read XML data from a local file using common JavaScript 
techniques, and you want to manipulate the Document Object Model (DOM), not just 
the character data.&lt;/P&gt;&lt;A name=solution-id8&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EYHOM&gt;4.4.4.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="a local"&gt;&lt;/A&gt;You can read a local XML document for its 
data using the&lt;A name=I_indexterm4_d1e6120&gt;&lt;/A&gt; &lt;TT&gt;XMLHttpRequest&lt;/TT&gt; object, 
and by using &lt;A name=I_indexterm4_d1e6129&gt;&lt;/A&gt;a &lt;TT&gt;File&lt;/TT&gt;&lt;A 
name="web address"&gt;&lt;/A&gt; object reference as the URI endpoint as opposed to a web 
address.&lt;/P&gt;&lt;A name=discussion-id8&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EQIOM&gt;4.4.4.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="every data"&gt;&lt;/A&gt;Most JavaScript libraries, and 
virtually every data-oriented Ajax application, &lt;A 
name=I_indexterm4_d1e6143&gt;&lt;/A&gt;makes use of the &lt;TT&gt;XMLHttpRequest&lt;/TT&gt;&lt;A 
name="means to"&gt;&lt;/A&gt; object to load data. This is a common means to accessing 
data from the client without refreshing the page, and it is core to Ajax 
development techniques. Adobe AIR includes support for the 
&lt;TT&gt;XMLHttpRequest&lt;/TT&gt;&lt;A name="data access"&gt;&lt;/A&gt; object, which can be used for 
data access.&lt;/P&gt;
&lt;P class=docText&gt;The &lt;TT&gt;XMLHttpRequest.open()&lt;/TT&gt; method &lt;A 
name=I_indexterm4_d1e6158&gt;&lt;/A&gt;&lt;A name="method to"&gt;&lt;/A&gt;expects three arguments. 
The first argument is the HTTP method to be used for the call, which is commonly 
&lt;TT&gt;GET&lt;/TT&gt; or &lt;TT&gt;POST&lt;/TT&gt;&lt;A name="it should"&gt;&lt;/A&gt;. The third argument tells 
the object whether it should make the request asynchronously. The challenge in 
an Adobe AIR application is the second argument, which tells the object where to 
get its data:&lt;/P&gt;&lt;PRE&gt;var xml = new XMLHTTPRequest();

xml.open( 'GET', 'myData.xml', true );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="This URI"&gt;&lt;/A&gt;This URI endpoint generally points to a 
remote server. This can still happen in an application that is online, but as 
Adobe AIR applications can also work offline, the endpoint needs to be pointed 
to a local resource. Rather than pass an endpoint to a remote server, a 
&lt;TT&gt;File&lt;/TT&gt;&lt;A name="be&amp;#13;&amp;#10;        provided"&gt;&lt;/A&gt; reference can be 
provided:&lt;/P&gt;&lt;PRE&gt;var file = air.File.applicationStorageDirectory.resolve
('myData.xml' );
var xml = new XMLHttpRequest();

xml.onreadystatechange = function()
{
    if( xml.readystate == 4 )
    {
        // Work with data
    }
}

xml.open('GET', file.url, true );
xml.send( null );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="make for"&gt;&lt;/A&gt;The key distinction to make for this 
example is the use of the &lt;TT&gt;File.url&lt;/TT&gt; property, which the 
&lt;TT&gt;XMLHttpRequest&lt;/TT&gt;&lt;A name="uses to"&gt;&lt;/A&gt; object understands and uses to 
access the appropriate data. Using this approach results in a traditional DOM 
that can be used to traverse and manipulate the XML data in the file. 
Additionally, you can use this approach with common JavaScript libraries.&lt;/P&gt;&lt;A 
name=given&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EEKOM&gt;4.4.4.4. Given&lt;/H5&gt;&lt;PRE&gt;&amp;lt;rolodex&amp;gt;
    &amp;lt;contact&amp;gt;
        &amp;lt;first&amp;gt;Kevin&amp;lt;/first&amp;gt;
        &amp;lt;last&amp;gt;Hoyt&amp;lt;/last&amp;gt;
    &amp;lt;/contact&amp;gt;
    ...
&amp;lt;/rolodex&amp;gt;
&lt;/PRE&gt;&lt;BR&gt;&lt;A name=example&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0ELKOM&gt;4.4.4.5. Example&lt;/H5&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Reading XML Data (using XMLHttpRequest)&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var contacts = air.File.applicationDirectory.resolvePath
( 'rolodex.xml' );

function doLoad()
{
    var xml = new XMLHttpRequest();

    xml.onreadystatechange = function()
    {
         var elem = null;
         var first = null;
         var last = null;
         var rolodex = null;

         if( xml.readyState == 4 )
         {
              rolodex = xml.responseXML.documentElement.
              getElementsByTagName
( 'contact' );

              for( var c = 0; c &amp;lt; rolodex.length; c++ )
              {
                   first = rolodex[c].getElementsByTagName
                   ( 'first' )[0].textContent;
                   last = rolodex[c].getElementsByTagName
                   ( 'last' )[0].textContent;

                   elem = document.createElement( 'div' );
                   elem.innerText = first + " " + last;
                   document.body.appendChild( elem );
              }
         }
    }

    xml.open( 'GET', contacts.url, true );
    xml.send( null );
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;



&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=create_a_temporary_file&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0ESKOM&gt;4.4.5. Create a Temporary 
File&lt;/H4&gt;&lt;A name=problem-id9&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EWKOM&gt;4.4.5.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;An application&lt;A name=I_indexterm4_d1e6203&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e6206&gt;&lt;/A&gt; &lt;A name=I_indexterm4_d1e6212&gt;&lt;/A&gt;&lt;A 
name="that adequate"&gt;&lt;/A&gt;needs to store transient information during file 
processing, and cannot assume that adequate memory exists to store the data in 
memory.&lt;/P&gt;&lt;A name=solution-id9&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EMLOM&gt;4.4.5.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Creating temporary files with &lt;TT&gt;File.createTempFile()&lt;/TT&gt; is 
&lt;A name=I_indexterm4_d1e6222&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e6225&gt;&lt;/A&gt;&lt;A 
name="store transient"&gt;&lt;/A&gt;an ideal means to store transient information while 
relieving the overhead of additional memory.&lt;/P&gt;&lt;A name=discussion-id9&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E5LOM&gt;4.4.5.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File&lt;/TT&gt; class contains a static 
&lt;TT&gt;File.createTempFile()&lt;/TT&gt;&lt;A name="a temporary"&gt;&lt;/A&gt; method that you can use 
to establish a temporary file. The temporary file is created at a destination 
determined by the operating system. Temporary files are also automatically given 
a unique name to avoid collision with other files that may be present:&lt;/P&gt;&lt;PRE&gt;var temp = air.File.createTempFile();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="been created"&gt;&lt;/A&gt;Once a temporary file has been 
created, you can use the &lt;TT&gt;File&lt;/TT&gt; and &lt;TT&gt;FileStream&lt;/TT&gt;&lt;A 
name="would any"&gt;&lt;/A&gt; APIs to interact with the file as you would any other 
file.:&lt;/P&gt;&lt;PRE&gt;var stream = new air.FileStream();

stream.open( temp, air.FileMode.WRITE );
stream.writeMultiByte('Hello', air.File.systemCharset );
stream.close();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;You can use &lt;A name=I_indexterm4_d1e6254&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e6257&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e6260&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e6263&gt;&lt;/A&gt;the &lt;TT&gt;File.moveTo()&lt;/TT&gt; and 
&lt;TT&gt;File.moveToAsync()&lt;/TT&gt;&lt;A name="it is"&gt;&lt;/A&gt; methods after the fact, should 
you decide that it is necessary to keep the temporary file for later reference. 
Both &lt;TT&gt;move&lt;/TT&gt;&lt;A name="methods take"&gt;&lt;/A&gt; methods take two arguments. The 
first argument is a &lt;TT&gt;File&lt;/TT&gt;&lt;A name="the destination"&gt;&lt;/A&gt; reference to the 
destination location. The second argument is a &lt;TT&gt;Boolean&lt;/TT&gt;&lt;A 
name="any existing"&gt;&lt;/A&gt; value that controls overwriting any existing file. If 
the second argument is set to &lt;TT&gt;false&lt;/TT&gt;&lt;A name="the application"&gt;&lt;/A&gt;, and 
a collision occurs, the application throws an error:&lt;/P&gt;&lt;PRE&gt;var move = air.File.desktopDirectory.resolve('temp.txt' );

try
{
    temp.moveTo( move, false );
} catch( ioe ) {
    alert('Can\'t move file:\n' + ioe.message );
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The JavaScript &lt;TT&gt;try&lt;/TT&gt;/&lt;TT&gt;catch&lt;/TT&gt; block will receive 
an error object of type &lt;TT&gt;IOError&lt;/TT&gt;. The &lt;TT&gt;IOError&lt;/TT&gt; class has&lt;A 
name=I_indexterm4_d1e6302&gt;&lt;/A&gt;&lt;A name="exception in"&gt;&lt;/A&gt; available numerous 
properties that you can use for further evaluation. The exception in the 
previous code snippet raises the error message that is generated by Adobe 
AIR:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Creating a Temporary File&amp;lt;/title&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
function doLoad()
{
    var stream = new air.FileStream();
    var temp = air.File.createTempFile();
    var move = air.File.desktopDirectory.resolvePath
    ( 'temp.txt' );

    stream.open( temp, air.FileMode.WRITE );
    stream.writeMultiByte( 'Hello World!', air.File.
    systemCharset );
    stream.close();

    try
    {
         temp.moveTo( move, false );
    } catch( ioe ) {
         alert( 'Could not move temporary file:\n' + 
         ioe.message );
    }

}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;



&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=iterate_the_contents_of_a_directory&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0EWOOM&gt;4.4.6. Iterate the Contents of a 
Directory&lt;/H4&gt;&lt;A name=problem-id10&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E1OOM&gt;4.4.6.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;The application&lt;A name=ch04-directories&gt;&lt;/A&gt;&lt;A 
name="information about"&gt;&lt;/A&gt; is required to display information about a 
directory as part of the user interface.&lt;/P&gt;&lt;A name=solution-id10&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EHPOM&gt;4.4.6.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Use the &lt;TT&gt;File.browseForDirectory()&lt;/TT&gt; method&lt;A 
name=I_indexterm4_d1e6330&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e6333&gt;&lt;/A&gt;&lt;A 
name="and then"&gt;&lt;/A&gt; to prompt the user to select a directory, and then use&lt;A 
name=I_indexterm4_d1e6337&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e6340&gt;&lt;/A&gt; the 
&lt;TT&gt;File.getDirectoryListing()&lt;/TT&gt;&lt;A name="contents of"&gt;&lt;/A&gt; method to iterate 
through the contents of the directory.&lt;/P&gt;&lt;A name=discussion-id10&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EFQOM&gt;4.4.6.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File&lt;/TT&gt; class provides&lt;A 
name=I_indexterm4_d1e6355&gt;&lt;/A&gt;&lt;A 
name="specific&amp;#13;&amp;#10;        information"&gt;&lt;/A&gt; numerous properties that you 
can use to get specific information about files on disk. Also, various methods 
on the &lt;TT&gt;File&lt;/TT&gt;&lt;A name="an application"&gt;&lt;/A&gt; class pertain to getting a 
directory listing. Although an application can specify a directory 
programmatically, you can use &lt;TT&gt;File.browseForDirectory()&lt;/TT&gt;&lt;A 
name="to prompt"&gt;&lt;/A&gt; to prompt the user to select a directory using the native 
dialog. Once a location on the local disk has been specified, the 
&lt;TT&gt;File.getDirectoryListing()&lt;/TT&gt;&lt;A name=an&gt;&lt;/A&gt; method returns an 
&lt;TT&gt;Array&lt;/TT&gt; of &lt;TT&gt;File&lt;/TT&gt;&lt;A 
name="referenced&amp;#13;&amp;#10;        directory"&gt;&lt;/A&gt; objects for the currently 
referenced directory.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="user to"&gt;&lt;/A&gt;Before prompting the user to select a 
directory using the native dialog, the application needs to establish and 
register an event handler for &lt;TT&gt;Event.SELECT&lt;/TT&gt;. The &lt;TT&gt;Event.target&lt;/TT&gt;&lt;A 
name="to the"&gt;&lt;/A&gt; property on the raised event object will contain a reference 
to the &lt;TT&gt;File&lt;/TT&gt;&lt;A name="browse&amp;#13;&amp;#10;        operation"&gt;&lt;/A&gt; object that 
invoked the browse operation.&lt;/P&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File.browseForDirectory()&lt;/TT&gt; method takes one 
argument, a &lt;TT&gt;String&lt;/TT&gt;&lt;A name="in the"&gt;&lt;/A&gt; representing additional 
information that will be placed in the dialog box. This &lt;TT&gt;String&lt;/TT&gt;&lt;A 
name="the dialog"&gt;&lt;/A&gt; is not the title of the dialog, as is the case with 
&lt;TT&gt;File.browseForOpen()&lt;/TT&gt;. There is also no need to specify 
&lt;TT&gt;FileFilter&lt;/TT&gt;&lt;A name="and no"&gt;&lt;/A&gt; objects, as the dialog box presented is 
specific to directories, and no files will be displayed.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="registered event"&gt;&lt;/A&gt;After the user has selected a 
directory, the registered event handler will be called. The file reference, 
whether using a class or global reference, or &lt;TT&gt;Event.target&lt;/TT&gt;&lt;A 
name="will now"&gt;&lt;/A&gt;, will now contain the path to the selected directory. At 
this point, &lt;TT&gt;File.getDirectoryListing()&lt;/TT&gt;&lt;A name="which returns"&gt;&lt;/A&gt; can 
be called, which returns an &lt;TT&gt;Array&lt;/TT&gt; of &lt;TT&gt;File&lt;/TT&gt;&lt;A 
name="directory "&gt;&lt;/A&gt; objects for the selected directory (as represented by the 
file reference). The &lt;TT&gt;File.getDirectoryListing()&lt;/TT&gt; method takes no 
arguments:&lt;/P&gt;&lt;PRE&gt;var listing = directory.getDirectoryListing();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File&lt;/TT&gt;&lt;A name="both files"&gt;&lt;/A&gt; class can represent 
both files and directories on the local filesystem. You can &lt;A 
name=I_indexterm4_d1e6429&gt;&lt;/A&gt;use the &lt;TT&gt;File.isDirectory&lt;/TT&gt; property to 
determine whether a specific &lt;TT&gt;File&lt;/TT&gt; instance references a file or a 
directory.&lt;/P&gt;&lt;A name=discussion-id10d1e6447&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="exposed&amp;#13;&amp;#10;          by"&gt;&lt;/A&gt;See the API 
documentation for a complete list of data exposed by the File API.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Selecting a Directory&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var directory = null;

function doBrowse()
{
    directory.browseForDirectory( 'Select a directory of 
    files:' );
}

function doLoad()
{
    directory = air.File.documentsDirectory;
    directory.addEventListener( air.Event.SELECT, doSelect );

    document.getElementById( 'browse' ).addEventListener
    ( 'click', doBrowse );
}

function doSelect( e )
{
    var files = directory.getDirectoryListing();
    var elem = null;
    var name = null;
    var mod = null;
    var size = null;

    for( var f = 0; f &amp;lt; files.length; f++ )
    {
         name = files[f].name;

         mod = files[f].modificationDate;
         mod = ( mod.month + 1 ) + '/' + mod.date + '/' + 
         mod.fullYear;

         size = Math.ceil( files[f].</description><guid>http://www.softxml.com/LearnTutorial.asp?id=24004234340&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>File Pickers</title><link>http://www.softxml.com/LearnTutorial.asp?id=32612322179&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class=docSection2Title id=title-ID0EFVNM&gt;4.5.1. Browse for a File&lt;/H4&gt;&lt;A 
name=problem-id11&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EJVNM&gt;4.5.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="An application"&gt;&lt;/A&gt;An application&lt;A 
name=I_indexterm4_d1e6455&gt;&lt;/A&gt; &lt;A name=I_indexterm4_d1e6457&gt;&lt;/A&gt;&lt;A 
name="prompt the"&gt;&lt;/A&gt;needs to prompt the user to select a file to open from the 
local system using a native dialog.&lt;/P&gt;&lt;A name=solution-id11&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E2VNM&gt;4.5.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File&lt;/TT&gt; class allows&lt;A 
name=I_indexterm4_d1e6467&gt;&lt;/A&gt;&lt;A name="the user"&gt;&lt;/A&gt; an application to prompt 
the user to select one or more files of a specific type from the local 
system.&lt;/P&gt;&lt;A name=discussion-id11&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EKWNM&gt;4.5.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File&lt;/TT&gt;&lt;A name="browse methods"&gt;&lt;/A&gt; class provides 
numerous browse methods that present the native dialog for the specified 
operation. In the case of browsing for a single file to open, the appropriate 
method is &lt;TT&gt;File.browseForOpen()&lt;/TT&gt;. &lt;A name=I_indexterm4_d1e6484&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e6487&gt;&lt;/A&gt;&lt;A name="of the"&gt;&lt;/A&gt;This method takes a required 
string argument for the title of the dialog box, and an &lt;A 
name=I_indexterm4_d1e6491&gt;&lt;/A&gt;optional &lt;TT&gt;Array&lt;/TT&gt; of &lt;TT&gt;FileFilter&lt;/TT&gt; 
objects.&lt;/P&gt;
&lt;P class=docText&gt;&lt;TT&gt;FileFilter&lt;/TT&gt;&lt;A name="to filter"&gt;&lt;/A&gt; objects allow an 
application to filter the viewable files in the native dialog box. This argument 
is &lt;TT&gt;null&lt;/TT&gt;&lt;A name="any file"&gt;&lt;/A&gt; by default, which allows the user to 
select any file to which he would normally have access (i.e., not hidden files). 
An application can provide as many filters as necessary, by placing multiple 
&lt;TT&gt;FileFilter&lt;/TT&gt; objects in an &lt;TT&gt;Array&lt;/TT&gt; and passing that &lt;TT&gt;Array&lt;/TT&gt; 
as the second argument to &lt;TT&gt;File.browseForOpen()&lt;/TT&gt;.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="on the"&gt;&lt;/A&gt;None of the browse methods on the 
&lt;TT&gt;File&lt;/TT&gt;&lt;A name="a valid"&gt;&lt;/A&gt; class is static, and as such, an existing 
reference to a valid &lt;TT&gt;File&lt;/TT&gt;&lt;A name="by that"&gt;&lt;/A&gt; object must first be 
available. The directory represented by that &lt;TT&gt;File&lt;/TT&gt;&lt;A 
name="object reference"&gt;&lt;/A&gt; object reference will be selected by default when 
the dialog is displayed:&lt;/P&gt;&lt;PRE&gt;var file = air.File.documentsDirectory;
var filters = new Array();

filters.push( new FileFilter( "Image Files", "*.jpg" ) );
file.browseForOpen( file, filters );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="file selection"&gt;&lt;/A&gt;When a file selection has been 
made, Adobe AIR will raise an event in the issuing application. To catch that 
event, the application must have first registered an event listener. The event 
that gets raised is &lt;TT&gt;Event.SELECT&lt;/TT&gt;&lt;A name="will be"&gt;&lt;/A&gt;, and an event 
object will be passed to the handler:&lt;/P&gt;&lt;PRE&gt;var file = air.File.documentsDirectory;
var filters = new Array();

filters.push( new air.FileFilter( "Image Files", "*.jpg" ) );

file.addEventListener( air.Event.SELECT, doSelect );
file.browseForOpen( file, filters );

function doSelect( event )
{
    alert( file.nativePath );
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="of the"&gt;&lt;/A&gt;A useful property of the &lt;TT&gt;Event&lt;/TT&gt;&lt;A 
name="contains a"&gt;&lt;/A&gt; object that is sent to the handler is the "target" which 
contains a reference to the originating &lt;TT&gt;File&lt;/TT&gt;&lt;A 
name="the&amp;#13;&amp;#10;        dialog"&gt;&lt;/A&gt; object. Nothing is returned from the 
dialog operation to be assigned to a &lt;TT&gt;File&lt;/TT&gt;&lt;A name="a reference"&gt;&lt;/A&gt; 
object, as the originating object will now hold a reference to the directory 
selected by the user. For this purpose, it may be beneficial to have a class or 
global reference to the &lt;TT&gt;File&lt;/TT&gt; object, and even to reuse it:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Selecting a File&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var file = null;

function doBrowse()
{
    var filters = new Array();

    filters.push( new air.FileFilter( 'Image Files',
    '*.jpg' ) );
    file.browseForOpen( 'Select Photo', filters );
}

function doLoad()
{
    file = air.File.documentsDirectory;
    file.addEventListener( air.Event.SELECT, doSelect );

    document.getElementById( 'browse' ).
    addEventListener( 'click', doBrowse );
}

function doSelect( e )
{
    var elem = document.createElement( 'div' );

    elem.innerText = file.nativePath;
    document.body.appendChild( elem );
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;

&amp;lt;input id="browse" type="button" value="Browse" /&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=browse_for_multiple_files&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0EEZNM&gt;4.5.2. Browse for Multiple 
Files&lt;/H4&gt;&lt;A name=problem-id12&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EIZNM&gt;4.5.2.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="the user"&gt;&lt;/A&gt;An application needs to prompt the user 
to select multiple files from the local system using the native dialog.&lt;/P&gt;&lt;A 
name=solution-id12&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0ENZNM&gt;4.5.2.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Use the &lt;TT&gt;File.browseForOpenMultiple()&lt;/TT&gt; method&lt;A 
name=I_indexterm4_d1e6573&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e6576&gt;&lt;/A&gt;&lt;A 
name="that will"&gt;&lt;/A&gt; to prompt the user with a dialog box that will allow for 
multiple file selection.&lt;/P&gt;&lt;A name=discussion-id12&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E6ZNM&gt;4.5.2.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;Using the &lt;TT&gt;File&lt;/TT&gt;&lt;A name="predominantly the"&gt;&lt;/A&gt; class 
to open a single file is predominantly the same as using the &lt;TT&gt;File&lt;/TT&gt;&lt;A 
name="class to"&gt;&lt;/A&gt; class to open multiple files. In the case of allowing the 
user to select multiple files, the appropriate method to use is 
&lt;TT&gt;File.browseForOpenMultiple()&lt;/TT&gt;. The 
&lt;TT&gt;File.browseForOpenMultiple()&lt;/TT&gt;&lt;A name="the same"&gt;&lt;/A&gt; method takes the 
same two arguments that the &lt;TT&gt;File.browseForOpen()&lt;/TT&gt; method takes: a 
&lt;TT&gt;String&lt;/TT&gt;&lt;A name="the title"&gt;&lt;/A&gt; to be used in the title of the dialog, 
and an &lt;TT&gt;Array&lt;/TT&gt; of &lt;TT&gt;FileFilter&lt;/TT&gt; objects.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="has selected"&gt;&lt;/A&gt;Once the user has selected the files 
from the dialog, &lt;TT&gt;FileListEvent.SELECT_MULTIPLE&lt;/TT&gt;&lt;A 
name="handler will"&gt;&lt;/A&gt; will be broadcast. The event object that is sent to the 
handler will be of type &lt;TT&gt;FileListEvent&lt;/TT&gt;. The &lt;TT&gt;FileListEvent&lt;/TT&gt; class 
contains a &lt;TT&gt;files&lt;/TT&gt; property, which will be an &lt;TT&gt;Array&lt;/TT&gt; of 
&lt;TT&gt;File&lt;/TT&gt;&lt;A name="that the"&gt;&lt;/A&gt; objects representing the files that the 
user selected:&lt;/P&gt;&lt;PRE&gt;var file = air.File.documentsDirectory;

file.addEventListener( air.FileListEvent.SELECT_MULTIPLE, 
doSelect );

function doSelect( event )
{
    for( var f = 0; f &amp;lt; event.files.length; f++ )
    {
        ...
    }
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;Here is the complete code:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Selecting Multiple Files&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var file = null;

function doBrowse()
{
    var filters = new Array();

    filters.push( new air.FileFilter( 'Image Files', 
    '*.jpg' ) );
    file.browseForOpenMultiple( 'Select Photos', filters );
}

function doLoad()
{
    file = air.File.documentsDirectory;
    file.addEventListener( air.FileListEvent.SELECT_MULTIPLE, 
    doSelect );

    document.getElementById( 'browse' ).addEventListener
    ( 'click', doBrowse );
}

function doSelect( e )
{
    var elem = null;
    var name = null;
    var size = null;

    for( var f = 0; f &amp;lt; e.files.length; f++ )
    {
         name = e.files[f].name;
         size = Math.ceil( e.files[f].size / 1000 );

         elem = document.createElement( 'div' );
         elem.innerText = name + ' (' + size + ' KB)';

         document.body.appendChild( elem );
    }
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;

&amp;lt;input id="browse" type="button" value="Browse" /&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=browse_for_a_directory&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0EY2NM&gt;4.5.3. Browse for a 
Directory&lt;/H4&gt;&lt;A name=problem-id13&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E32NM&gt;4.5.3.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;Application requirements dictate that&lt;A 
name=ch04-dirbrowsing&gt;&lt;/A&gt;&lt;A name="in which"&gt;&lt;/A&gt; you allow users to select a 
directory in which they will store data.&lt;/P&gt;&lt;A name=solution-id13&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EJ3NM&gt;4.5.3.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Use the &lt;TT&gt;File.browseForDirectory()&lt;/TT&gt; method &lt;A 
name=I_indexterm4_d1e6659&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e6662&gt;&lt;/A&gt;&lt;A 
name="select a"&gt;&lt;/A&gt;to prompt the user to select a directory.&lt;/P&gt;&lt;A 
name=discussion-id13&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E23NM&gt;4.5.3.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File.browseForDirectory()&lt;/TT&gt;&lt;A name="users to"&gt;&lt;/A&gt; 
method creates a native dialog box that allows users to select a directory. The 
method takes a required &lt;TT&gt;String&lt;/TT&gt;&lt;A name="information to"&gt;&lt;/A&gt; argument, 
which will be used to provide additional information to the user about the 
purpose of the selected directory.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="When a"&gt;&lt;/A&gt;When a directory selection has been made, 
Adobe AIR will raise an event in the issuing application. To catch that event, 
the application must have first registered an event listener. The event that 
gets raised&lt;A name=I_indexterm4_d1e6679&gt;&lt;/A&gt; is &lt;TT&gt;Event.SELECT&lt;/TT&gt;&lt;A 
name="event object"&gt;&lt;/A&gt;, and an event object will be passed to the handler:&lt;/P&gt;&lt;PRE&gt;var file = air.File.applicationStorageDirectory;

file.addEventListener( air.Event.SELECT, doSelect );
file.browseForDirectory( "Where do you want to store your 
photos?" );

function doSelect( event )
{
    alert( file.nativePath );
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="the dialog"&gt;&lt;/A&gt;Nothing is returned from the dialog 
operation to be assigned to a &lt;TT&gt;File&lt;/TT&gt;&lt;A name="object will"&gt;&lt;/A&gt; object, as 
the originating object will now hold a reference to the directory selected by 
the user. For this purpose, it may be beneficial to have a class or global 
reference to the &lt;TT&gt;File&lt;/TT&gt; object, and even to reuse it:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Selecting a Directory&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var directory = null;

function doBrowse()
{
    directory.browseForDirectory( 'Select a directory of 
    files:' );
}

function doLoad()
{
    directory = air.File.documentsDirectory;
    directory.addEventListener( air.Event.SELECT, doSelect );

    document.getElementById( 'browse' ).addEventListener
    ( 'click', doBrowse );
}

function doSelect( e )
{
    var files = directory.getDirectoryListing();
    var elem = null;
    var name = null;
    var mod = null;
    var size = null;

    for( var f = 0; f &amp;lt; files.length; f++ )
    {
         name = files[f].name;

         mod = files[f].modificationDate;
         mod = ( mod.month + 1 ) + '/' + mod.date + '/' + 
         mod.fullYear;

         size = Math.ceil( files[f].</description><guid>http://www.softxml.com/LearnTutorial.asp?id=32612322179&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Service and Server Monitoring</title><link>http://www.softxml.com/LearnTutorial.asp?id=25146119571&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class=docSection2Title id=title-ID0EOVNM&gt;4.6.1. Monitor Connectivity to an 
HTTP Server&lt;/H4&gt;&lt;A name=problem-id14&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0ESVNM&gt;4.6.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name=Your&gt;&lt;/A&gt;Your &lt;A name=I_indexterm4_d1e6709&gt;&lt;/A&gt;&lt;A 
name="to monitor"&gt;&lt;/A&gt;application needs to monitor and determine whether a 
specific HTTP server can be reached.&lt;/P&gt;&lt;A name=solution-id14&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E5VNM&gt;4.6.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Use the &lt;TT&gt;URLMonitor&lt;/TT&gt; class to &lt;A 
name=I_indexterm4_d1e6719&gt;&lt;/A&gt;&lt;A name="in HTTP"&gt;&lt;/A&gt;detect network state changes 
in HTTP/S endpoints.&lt;/P&gt;&lt;A name=discussion-id14&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EMWNM&gt;4.6.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="work through"&gt;&lt;/A&gt;Service monitor classes work through 
event notification and subsequent polling of the designated endpoint. Service 
monitoring is not an integrated function of Adobe AIR directly, and needs to be 
added before it can be used.&lt;/P&gt;
&lt;P class=docText&gt;The classes for service monitoring are contained in the 
&lt;I&gt;servicemonitor.swf&lt;/I&gt; file, which you can find in the &lt;I&gt;frameworks&lt;/I&gt;&lt;A 
name="into the"&gt;&lt;/A&gt; directory of the Adobe AIR SDK. You should copy this file 
into the application project folder; you can include it through the use of the 
HTML &lt;TT&gt;SCRIPT&lt;/TT&gt;&lt;A name="include the"&gt;&lt;/A&gt; tag. You also need to include the 
&lt;I&gt;servicemonitor.swf&lt;/I&gt; file in the packaged Adobe AIR application. The 
&lt;TT&gt;SCRIPT&lt;/TT&gt;&lt;A name="must come"&gt;&lt;/A&gt; tag used to include service monitoring 
functionality must come before the &lt;I&gt;AIRAliases.js&lt;/I&gt;&lt;A 
name="specify the"&gt;&lt;/A&gt; file is declared. You also must specify the content type 
on the &lt;TT&gt;SCRIPT&lt;/TT&gt; tag as &lt;TT&gt;application/x-shockwave-flash&lt;/TT&gt;:&lt;/P&gt;&lt;PRE&gt;&amp;lt;script src="servicemonitor.swf" 
type="application/x-shockwave-flash"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="AIRAliases.js" 
type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;URLMonitor&lt;/TT&gt;&lt;A name="instance of"&gt;&lt;/A&gt; class takes a 
single argument in the constructor, an instance of the &lt;TT&gt;URLRequest&lt;/TT&gt; 
class. The &lt;TT&gt;URLRequest&lt;/TT&gt; constructor takes a &lt;TT&gt;String&lt;/TT&gt;&lt;A 
name=The&gt;&lt;/A&gt; that represents the URL service endpoint to query. The 
&lt;TT&gt;URLRequest&lt;/TT&gt;&lt;A name="class also"&gt;&lt;/A&gt; class also contains information 
about how to query the endpoint (i.e., &lt;TT&gt;GET&lt;/TT&gt;, &lt;TT&gt;POST&lt;/TT&gt;&lt;A 
name="additional data"&gt;&lt;/A&gt;), and any additional data that should be passed to 
the server:&lt;/P&gt;&lt;PRE&gt;var request = air.URLRequest( 'http://www.adobe.com' ) ;
var monitor = new air.URLMonitor( request );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;URLMonitor&lt;/TT&gt; class will raise a 
&lt;TT&gt;StatusEvent.STATUS&lt;/TT&gt;&lt;A name="status changes"&gt;&lt;/A&gt; event when the network 
status changes. Once the event handler has been registered, the 
&lt;TT&gt;URLMonitor&lt;/TT&gt;&lt;A name="told to"&gt;&lt;/A&gt; instance can be told to start watching 
for network start changes:&lt;/P&gt;&lt;PRE&gt;monitor.addEventListener( air.StatusEvent.STATUS, doStatus );
monitor.start();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="can&amp;#13;&amp;#10;        use"&gt;&lt;/A&gt;After a network change 
has been propagated as an event, you can use the &lt;TT&gt;URLMonitor.available&lt;/TT&gt; 
property on the originating &lt;TT&gt;URLMonitor&lt;/TT&gt;&lt;A 
name="the&amp;#13;&amp;#10;        presence"&gt;&lt;/A&gt; instance to check for the presence of 
a connection. The &lt;TT&gt;URLMonitor.available&lt;/TT&gt; property returns a 
&lt;TT&gt;Boolean&lt;/TT&gt;&lt;A name="As it"&gt;&lt;/A&gt; value that reflects the state of the 
network. As it is necessary to query the originating &lt;TT&gt;URLMonitor&lt;/TT&gt;&lt;A 
name="declare the"&gt;&lt;/A&gt; instance for network availability, you should declare 
the object in a scope that is accessible across the application:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Connectivity to an HTTP Server&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script src="servicemonitor.swf" 
type="application/x-shockwave-flash"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type="text/javascript" 
src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var monitor = null;

function doLoad()
{
    var request = new air.URLRequest
    ( 'http://www.adobe.com' );

    monitor = new air.URLMonitor( request );
    monitor.addEventListener( air.StatusEvent.STATUS,
    doStatus );
    monitor.start();
}

function doStatus( e )
{
    var elem = document.createElement( 'div' );

    elem.innerText = monitor.available;

    document.body.appendChild( elem );
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;



&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=monitor_connectivity_to_a_jabber_server&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0EKZNM&gt;4.6.2. Monitor Connectivity to a 
Jabber Server&lt;/H4&gt;&lt;A name=problem-id15&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EOZNM&gt;4.6.2.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;A Jabber chat client is required&lt;A 
name=I_indexterm4_d1e6823&gt;&lt;/A&gt;&lt;A name="the endpoint"&gt;&lt;/A&gt; to reflect network 
presence in the user interface, but the endpoint is a Jabber server on a 
specific port, and not HTTP/S.&lt;/P&gt;&lt;A name=solution-id15&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EZZNM&gt;4.6.2.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Use the &lt;TT&gt;SocketMonitor&lt;/TT&gt; class to &lt;A 
name=I_indexterm4_d1e6835&gt;&lt;/A&gt;detect network state changes against TCP/IP socket 
endpoints.&lt;/P&gt;&lt;A name=discussion-id15&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EH1NM&gt;4.6.2.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="into Adobe"&gt;&lt;/A&gt;The service monitoring features are 
not built into Adobe AIR directly, and need to be added before they can be used. 
The &lt;I&gt;servicemonitor.swf&lt;/I&gt;&lt;A name="which is"&gt;&lt;/A&gt; file, which is included in 
the Adobe AIR SDK, must be imported as an application resource and included via 
an HTML &lt;TT&gt;SCRIPT&lt;/TT&gt;&lt;A name="type on"&gt;&lt;/A&gt; tag. The content type on the 
&lt;TT&gt;SCRIPT&lt;/TT&gt; tag must be specified, &lt;A name=I_indexterm4_d1e6853&gt;&lt;/A&gt;and the 
&lt;TT&gt;SCRIPT&lt;/TT&gt;&lt;A name="monitor classes"&gt;&lt;/A&gt; tag for the service monitor 
classes must come before the &lt;I&gt;AIRAliases.js&lt;/I&gt; &lt;TT&gt;SCRIPT&lt;/TT&gt; tag.&lt;/P&gt;&lt;PRE&gt;&amp;lt;script src="servicemonitor.swf" 
type="application/x-shockwave-flash"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="AIRAliases.js" 
type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;SocketMonitor&lt;/TT&gt;&lt;A name="arguments in"&gt;&lt;/A&gt; class 
takes two arguments in the constructor: a &lt;TT&gt;String&lt;/TT&gt;&lt;A 
name="server is"&gt;&lt;/A&gt; that represents the host endpoint, and a port on which the 
server is listening:&lt;/P&gt;&lt;PRE&gt;var host = 'im.mydomain.com';
var port = 5220;
var monitor = new air.SocketMonitor( host, port );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;SocketMonitor&lt;/TT&gt; class will raise a 
&lt;TT&gt;StatusEvent.STATUS&lt;/TT&gt;&lt;A name="status changes"&gt;&lt;/A&gt; event when the network 
status changes. Once the event handler has been registered, calling the 
&lt;TT&gt;SocketMonitor.start()&lt;/TT&gt; method &lt;A name=I_indexterm4_d1e6890&gt;&lt;/A&gt;will 
start watching the network for changes:&lt;/P&gt;&lt;PRE&gt;monitor.addEventListener( air.StatusEvent.STATUS, doStatus );
monitor.start();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="as an"&gt;&lt;/A&gt;After a network change has been propagated 
as an event, you can use the &lt;TT&gt;SocketMonitor.available&lt;/TT&gt; property on the 
originating &lt;TT&gt;SocketMonitor&lt;/TT&gt;&lt;A name="presence of"&gt;&lt;/A&gt; instance to check 
for the presence of a connection. The &lt;TT&gt;SocketMonitor.available&lt;/TT&gt; property 
returns a &lt;TT&gt;Boolean&lt;/TT&gt;&lt;A name="a best"&gt;&lt;/A&gt; value that reflects the state of 
the network. As a best practice, you should declare the &lt;TT&gt;SocketMonitor&lt;/TT&gt;&lt;A 
name="across the"&gt;&lt;/A&gt; object in a scope that is accessible across the 
application and is referenced directly during event handling:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Connectivity to a Jabber Server&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script src="servicemonitor.swf" 
type="application/x-shockwave-flash"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var monitor = null;

function doLoad()
{
    monitor = new air.SocketMonitor
    ( 'im.mydomain.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=25146119571&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Online/Offline</title><link>http://www.softxml.com/LearnTutorial.asp?id=23982087786&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class=docSection2Title id=title-ID0EXVNM&gt;4.7.1. Cache Assets for Offline 
Use&lt;/H4&gt;&lt;A name=problem-id16&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E2VNM&gt;4.7.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="You want"&gt;&lt;/A&gt;You want to load an asset from a URL and 
store it for use when the application is offline.&lt;/P&gt;&lt;A name=solution-id16&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EAWNM&gt;4.7.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="File I"&gt;&lt;/A&gt;Use the File I/O API to save the requested 
asset to the application's store and read that file on subsequent 
requests.&lt;/P&gt;&lt;A name=discussion-id16&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EFWNM&gt;4.7.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="load an"&gt;&lt;/A&gt;In this example, we will load an XML file 
that is at a known URL. Once the data has been loaded, it will be saved to the 
local disk, and on subsequent requests for the document it will be loaded from 
the local disk instead of from the remote location.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name=the&gt;&lt;/A&gt;First, we will use the &lt;TT&gt;XMLHttpRequest&lt;/TT&gt; 
object to load the XML data from the remote location. The 
&lt;TT&gt;XMLHttpRequest.open()&lt;/TT&gt;&lt;A name="the HTTP"&gt;&lt;/A&gt; method takes three 
arguments. The first argument is the method of the HTTP request that is being 
made. The second argument is the URI of the location of the data being loaded. 
The third argument is a &lt;TT&gt;Boolean&lt;/TT&gt;&lt;A 
name="operation&amp;#13;&amp;#10;        will"&gt;&lt;/A&gt; that specifies whether the operation 
will be asynchronous.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name=the&gt;&lt;/A&gt;Once we have specified these arguments in the 
&lt;TT&gt;open&lt;/TT&gt; method, we will call the &lt;TT&gt;send&lt;/TT&gt; method. The &lt;TT&gt;send&lt;/TT&gt;&lt;A 
name="that&amp;#13;&amp;#10;        contains"&gt;&lt;/A&gt; method takes a single argument that 
contains the content that is to be sent with the request. In our case, we won't 
send any data with the request:&lt;/P&gt;&lt;PRE&gt;var xml = new XMLHttpRequest();
xml.open( "GET", "http://www.foo.com/data.xml", true );
xml.send( null );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="to&amp;#13;&amp;#10;        create"&gt;&lt;/A&gt;Because we are loading 
the data asynchronously, we need to create a handler for the response which is 
called once the data has loaded from the server. This handler will be added 
before the &lt;TT&gt;send&lt;/TT&gt;&lt;A name="the data"&gt;&lt;/A&gt; method is called. Within this 
handler, we will save the data that is located in the &lt;TT&gt;responseText&lt;/TT&gt;&lt;A 
name="property of"&gt;&lt;/A&gt; property of the &lt;TT&gt;XMLHttpRequest&lt;/TT&gt;&lt;A 
name="a known"&gt;&lt;/A&gt; instance to a known location on the local filesystem for 
retrieval in subsequent requests. We cover reading and writing text to the local 
system elsewhere in the book, and therefore we won't cover it in detail 
here:&lt;/P&gt;&lt;PRE&gt;xml.onreadystatechange = function()
{
    if( xml.readyState == 4 ) // the request is complete
    {
        // write the data to the local system
       var file =
       air.File.applicationStorageDirectory.resolvePath
       ("data.xml");
        var fileStream = new air.FileStream();
        fileStream.open( file, air.FileMode.WRITE );
        fileStream.writeMultiByte( xml.responseText ,
                                   air.File.systemCharset );
        fileStream.close();
    }
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="the data"&gt;&lt;/A&gt;Before each request of the data, we will 
need to check whether the &lt;I&gt;data.xml&lt;/I&gt;&lt;A name="we do"&gt;&lt;/A&gt; file exists. If it 
exists, we do not need to load the file using the &lt;TT&gt;XMLHttpRequest&lt;/TT&gt;&lt;A 
name="from the"&gt;&lt;/A&gt; object and can use the File API to load it from the disk. 
This allows us to load the data even if the user is not currently online:&lt;/P&gt;&lt;PRE&gt;var data = null;
var file = air.File.applicationStorageDirectory.resolvePath
("data.xml");

if( file.exists )
{
    var fileStream = new air.FileStream();
    fileStream.open( file, air.FileMode.READ );
    data =
    fileStream.readMultiByte( fileStream.bytesAvailable,
                              air.File.systemCharset );
    fileStream.close();
}
else
{
    // read the data via XMLHttpRequest and write that
    // data to the file system
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;Here is the complete example:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Caching Assets for Offline Use&amp;lt;/title&amp;gt;
    &amp;lt;script src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script&amp;gt;

        var file =
        air.File.applicationStorageDirectory.resolvePath
        ("data.xml");

        function onLoad()
        {
            if( file.exists )
            {
                var fileStream = new air.FileStream();
                fileStream.open( file, air.FileMode.READ );
                document.getElementById( "dataText" ).value =
                    fileStream.readMultiByte(
                        fileStream.bytesAvailable,
                        air.File.systemCharset );
                fileStream.close();
            }
            else
            {
                var xml = new XMLHttpRequest();
                xml.open( "GET",
                          "http://www.foo.com/data.xml", 
                         true );

                xml.onreadystatechange = function()
                {
                    if( xml.readyState == 4 ) // the request 
is complete
                    {
                        var file = air.File.
applicationStorageDirectory. resolvePath("data.xml");
                        var fileStream = new air.FileStream();
                        fileStream.open( file, air.
FileMode.WRITE );
                        fileStream.writeMultiByte( xml.
responseText , air.File.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=23982087786&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Drag-and-Drop</title><link>http://www.softxml.com/LearnTutorial.asp?id=3254898943&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class=docSection2Title id=title-ID0EAWNM&gt;4.8.1. Use Drag and-Drop from 
HTML&lt;/H4&gt;&lt;A name=problem-id17&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EEWNM&gt;4.8.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="You want"&gt;&lt;/A&gt;You want to allow &lt;A 
name=ch04-htmldand&gt;&lt;/A&gt;&lt;A name=ch04-dandd&gt;&lt;/A&gt;&lt;A name="drag files"&gt;&lt;/A&gt;users to 
drag files, images, text, and other data types into and out of HTML-based AIR 
applications.&lt;/P&gt;&lt;A name=solution-id17&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EXWNM&gt;4.8.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="and Drop"&gt;&lt;/A&gt;By using Adobe AIR's Drag and Drop 
implementation in JavaScript, &lt;A name=I_indexterm4_d1e7014&gt;&lt;/A&gt;&lt;A 
name="to drag"&gt;&lt;/A&gt;developers can react to drag-and-drop operations that occur 
on HTML DOM objects.&lt;/P&gt;&lt;A name=solution-id17d1e7028&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="WebKit implementation"&gt;&lt;/A&gt;Adobe AIR's support for 
drag-and-drop within HTML content is based on the WebKit implementation. You can 
find more information on this at &lt;A class=docLink 
href="http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/DragAndDrop.html" 
target=_blank&gt;http://developer.apple.com/documentation/AppleApplications/Conceptual/SafariJSProgTopics/Tasks/DragAndDrop.html&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;A name=discussion-id17&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EKXNM&gt;4.8.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="of developing"&gt;&lt;/A&gt;One of the benefits of developing 
for the desktop is providing users with a more integrated experience when 
interacting with multiple applications. One of the most frequently used user 
gestures is to drag-and-drop files, data, and other elements between 
applications and the desktop and between the applications themselves.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="accept text"&gt;&lt;/A&gt;This example will demonstrate how you 
can accept text being dragged items into your application as well as support 
dragging elements out. It will also show you how to modify the drag effect to 
demonstrate for the user what type of drag operations he can perform with the 
element he is dragging as well as the ability to modify the drag image.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="consider when"&gt;&lt;/A&gt;Two flows are important to consider 
when using drag-and-drop operations in HTML. First, we will examine the flow for 
HTML elements that are drag-enabled:&lt;/P&gt;
&lt;DIV style="FONT-WEIGHT: bold"&gt;
&lt;OL class=docList type=1&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;&lt;A name="drag&amp;#13;&amp;#10;            operations"&gt;&lt;/A&gt;The element 
specifies that it is available for drag operations.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;&lt;A name="to drag"&gt;&lt;/A&gt;The user selects the element and starts 
to drag it.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;&lt;A name="The element"&gt;&lt;/A&gt;The element receives an 
&lt;TT&gt;ondragstart&lt;/TT&gt;&lt;A name="sets the"&gt;&lt;/A&gt; event and sets the data which will 
be transferred, as well as specifies which drag operations are supported. It can 
also specify a custom drag image at this time.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;The element receives &lt;TT&gt;ondrag&lt;/TT&gt;&lt;A 
name="being&amp;#13;&amp;#10;            dragged"&gt;&lt;/A&gt; events while it is being 
dragged.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;&lt;A name="the element"&gt;&lt;/A&gt;The user drops the element being 
dragged and receives an &lt;TT&gt;ondragend&lt;/TT&gt; event.&lt;/P&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="drop&amp;#13;&amp;#10;        operations"&gt;&lt;/A&gt;The typical flow 
for HTML elements that want to receive drop operations is as follows:&lt;/P&gt;
&lt;DIV style="FONT-WEIGHT: bold"&gt;
&lt;OL class=docList type=1&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;&lt;A name="item over"&gt;&lt;/A&gt;The user drags an item over the element 
listening for drop events.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;The element receives an &lt;TT&gt;ondragenter&lt;/TT&gt; event and 
specifies which drop operations are allowed.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;The element receives &lt;TT&gt;ondragover&lt;/TT&gt;&lt;A 
name="dragged over"&gt;&lt;/A&gt; operations continuously as the item is being dragged 
over.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;&lt;A name="and the"&gt;&lt;/A&gt;The user drops the item and the receiving 
element receives an &lt;TT&gt;ondrop&lt;/TT&gt; event.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;&lt;A name="the boundaries"&gt;&lt;/A&gt;Alternatively, if the user moves 
the dragged item outside the boundaries of the listening element, it will 
receive an &lt;TT&gt;ondragleave&lt;/TT&gt; event.&lt;/P&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="by&amp;#13;&amp;#10;        default"&gt;&lt;/A&gt;Linked text and 
highlighted text elements are drag-enabled by default. To disable this 
functionality, use the &lt;TT&gt;-khtml-user-drag:none&lt;/TT&gt; style. &lt;A 
name=I_indexterm4_d1e7094&gt;&lt;/A&gt;&lt;A name="to enable"&gt;&lt;/A&gt;Conversely, to enable 
other HTML elements to be drag-enabled, use &lt;A name=I_indexterm4_d1e7098&gt;&lt;/A&gt;the 
&lt;TT&gt;-khtml-user-drag:element&lt;/TT&gt; style.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="the data"&gt;&lt;/A&gt;To manipulate the data that is being 
transferred as part of the drag operation, listen for the &lt;TT&gt;ondragstar&lt;/TT&gt; 
operation and use the &lt;TT&gt;dataTransfer&lt;/TT&gt;&lt;A name="to the"&gt;&lt;/A&gt; object that is 
attached to the event object. The &lt;TT&gt;dataTransfer&lt;/TT&gt;&lt;A 
name="data modification"&gt;&lt;/A&gt; object has two data modification methods: 
&lt;TT&gt;getData&lt;/TT&gt; and &lt;TT&gt;setData&lt;/TT&gt;. The &lt;TT&gt;setData&lt;/TT&gt;&lt;A 
name="data that"&gt;&lt;/A&gt; method takes two parameters: the MIME type and the string 
of data that conforms to that type. You can call the &lt;TT&gt;setData&lt;/TT&gt;&lt;A 
name="allows you"&gt;&lt;/A&gt; method multiple times, and it allows you to store 
multiple data types. For example, if you wanted to specify a &lt;TT&gt;text/plain&lt;/TT&gt; 
type and a &lt;TT&gt;text/uri- list&lt;/TT&gt; type, you would do the following:&lt;/P&gt;&lt;PRE&gt;function dropStartListener( event )
{
    event.dataTransfer.setData( "text/plain", "Adobe" );
    event.dataTransfer.setData( "text/uri-list",
                                 "http://www.adobe.com" );
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;If &lt;TT&gt;setData&lt;/TT&gt;&lt;A name="already exists"&gt;&lt;/A&gt; is called for 
a MIME type that already exists on the element being dragged, that data will be 
overwritten. Retrieving data from an element that is being dragged can occur 
only within an &lt;TT&gt;ondrop&lt;/TT&gt; event handler. The &lt;TT&gt;getData&lt;/TT&gt;&lt;A 
name="as its"&gt;&lt;/A&gt; method takes a MIME type as its only parameter and returns 
the value of the MIME type if it exists on the element being dragged. For 
example:&lt;/P&gt;&lt;PRE&gt;function dropListener( event )
{
    alert( event.dataTransfer.getData( "text/plain" ) );
// Adobe
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;AIR supports the&lt;A name=I_indexterm4_d1e7153&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7156&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e7159&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7162&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e7165&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7168&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e7171&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7176&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e7179&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7182&gt;&lt;/A&gt; following MIME types:&lt;/P&gt;
&lt;P class=docText&gt;Text "text/plain"&lt;/P&gt;
&lt;P class=docText&gt;HTML "text/html"&lt;/P&gt;
&lt;P class=docText&gt;URL "text/uri-list"&lt;/P&gt;
&lt;P class=docText&gt;Bitmap "image/x-vnd.adobe.air.bitmap"&lt;/P&gt;
&lt;P class=docText&gt;File list "application/x-vnd.adobe.air.file-list"&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="application to"&gt;&lt;/A&gt;When a user is dragging data from 
one application to another, or from one location in your application to another, 
you may want to indicate to the user which operations (copy, link, or move) are 
available. By using &lt;A name=I_indexterm4_d1e7198&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7201&gt;&lt;/A&gt;the &lt;TT&gt;effectAllowed&lt;/TT&gt; and &lt;TT&gt;dropEffect&lt;/TT&gt; 
properties of the &lt;TT&gt;dataTransfer&lt;/TT&gt;&lt;A name="can see"&gt;&lt;/A&gt; object, you can 
specify which operations are allowed. You can see the list of available values 
for these properties by reading the WebKit documentation referenced earlier.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name=The&gt;&lt;/A&gt;The &lt;TT&gt;effectAllowed&lt;/TT&gt;&lt;A 
name="the system"&gt;&lt;/A&gt; property tells the system what operations the source 
element supports. The &lt;TT&gt;dropEffect&lt;/TT&gt;&lt;A name="operation that"&gt;&lt;/A&gt; property 
specifies the single operation that the current target receiving the drag event 
supports. The operating system then uses this information regarding which 
effects the source and destination targets support, and allows the user to make 
that choice. Generally, the user chooses by using the system's standard keyboard 
modifiers.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="drag image"&gt;&lt;/A&gt;To modify the drag image that is 
displayed to the user as she is dragging the item, use the &lt;TT&gt;setDragImage&lt;/TT&gt; 
method of the &lt;TT&gt;dataTransfer&lt;/TT&gt; object. This method takes three arguments. 
The first argument is a JavaScript &lt;TT&gt;Image&lt;/TT&gt;&lt;A name="The second"&gt;&lt;/A&gt; 
object which references the image that will appear to the user. The second and 
third arguments are the respective X and Y offsets that will modify the position 
of that image relative to the cursor's X and Y positions on-screen.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="the following"&gt;&lt;/A&gt;Assume that we had the following 
HTML element in our document. Notice that we explicitly specify that this 
element is draggable using the &lt;TT&gt;-khtml-user-drag:element&lt;/TT&gt; style:&lt;/P&gt;&lt;PRE&gt;&amp;lt;div id="box" style="-khtml-user-drag:element"
      ondragstart="onBoxDragStart
(event)"&amp;gt;&amp;lt;/div&amp;gt;
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="listening for"&gt;&lt;/A&gt;We can then change the image by 
listening for the &lt;TT&gt;ondragstart&lt;/TT&gt;&lt;A name=using&gt;&lt;/A&gt; event and modify the 
image using &lt;A name=I_indexterm4_d1e7246&gt;&lt;/A&gt;the &lt;TT&gt;setDragImage&lt;/TT&gt; 
method:&lt;/P&gt;&lt;PRE&gt;    // First create a reference to our drag image in the 
    // main document scope.
    var dragImage = new Image();
    dragImage.src = "app:/images/dragImage.png";

    // This method gets called when a drag starts
    // on our 'box' element.
    function onBoxDragStart( event )
    {
        // Set the data we would like to be transferred.
        event.dataTransfer.setData("text/plain", 
        "This is a red box!");

        // Modify the drag image to use the reference
        // we created above.
        event.dataTransfer.setDragImage( dragImage, 0, 0 );
    }
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;Here is the full example:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;HTML Drag Test&amp;lt;/title&amp;gt;
    &amp;lt;script src="AIRAliases.js" /&amp;gt;
    &amp;lt;script&amp;gt;

    // DROP EVENTS

    function onDragEnter(event)
    {
        air.trace("onDragEnter");
        event.dataTransfer.dropEffect = "copy";
        event.preventDefault();
    }

    function onDrop(event)
    {
      air.trace("onDrop");
      air.trace( event.dataTransfer.getData("text/plain") );
      air.trace( event.dataTransfer.getData("text/uri-list") );
    }

    function onDragOver(event)
    {
        event.preventDefault();
    }

    // DRAG EVENTS

    function onDragStart(event)
    {
        air.trace("onDragStart");
        event.dataTransfer.setData("text/plain",
           "This is the URL I am dragging" );
        // We overwrite the default URL specified in the
        // anchor tag with a different URL. When the data
        // is dropped, this is the URL that will be
        //  transferred.
        event.dataTransfer.setData("text/uri-list",
                                   "http://www.foo.com" );
        event.dataTransfer.effectAllowed = "all";
    }

    function onDragEnd( event )
    {
        air.trace("onDragEnd");
    }


    var dragImage = new Image();
    dragImage.src = "app:/images/dragImage.png";

    function onBoxDragStart( event )
    {
         event.dataTransfer.setData("text/plain", "This is a 
red box!");
         event.dataTransfer.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=3254898943&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Embedded Database</title><link>http://www.softxml.com/LearnTutorial.asp?id=40933512144&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;P class=docText&gt;Adobe&lt;A name=I_indexterm4_d1e7265&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7266&gt;&lt;/A&gt;&lt;A name=AIR&gt;&lt;/A&gt; AIR &lt;A 
name=ch04-database&gt;&lt;/A&gt;includes an embedded&lt;A name=I_indexterm4_d1e7272&gt;&lt;/A&gt;&lt;A 
name="that AIR"&gt;&lt;/A&gt; SQLite database that AIR applications can leverage. SQLite 
is a compact open source database that supports&lt;A 
name=I_indexterm4_d1e7276&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e7279&gt;&lt;/A&gt;&lt;A 
name="most of"&gt;&lt;/A&gt; ACID transactions, requires zero configuration, implements 
most of SQL92, and supports strings and BLOBs up to 2 GB in size. All database 
information is stored in a single file on disk, which you can freely share 
between machines, even if they have different byte orders.&lt;/P&gt;&lt;A 
name=embedded_databased1e7291&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="more information"&gt;&lt;/A&gt;You can find more information 
about SQLite on the project web site, at &lt;A class=docLink 
href="http://www.sqlite.org" target=_blank&gt;http://www.sqlite.org&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="transaction will"&gt;&lt;/A&gt;Adobe AIR supports both 
synchronous and asynchronous database transactions. A synchronous transaction 
will block additional user interface interaction until the transaction has been 
completed, but can be substantially less effort to code. An asynchronous 
approach will allow additional interaction with the user interface while the 
transaction is processing, though it may require a substantial amount of code 
for event handlers. All of the following examples showcase an asynchronous 
approach.&lt;/P&gt;&lt;A name=connect_to_a_database&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0ESXNM&gt;4.9.1. Connect to a Database&lt;/H4&gt;&lt;A 
name=problem-id18&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EWXNM&gt;4.9.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;You need to connect &lt;A name=I_indexterm4_d1e7298&gt;&lt;/A&gt;&lt;A 
name="prior to"&gt;&lt;/A&gt;to a local database prior to working with the schema or 
altering data.&lt;/P&gt;&lt;A name=solution-id18&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0ECYNM&gt;4.9.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="database using"&gt;&lt;/A&gt;You can create and connect to a 
database using the &lt;A name=I_indexterm4_d1e7309&gt;&lt;/A&gt;single 
&lt;TT&gt;SQLConnection.open()&lt;/TT&gt; method.&lt;/P&gt;&lt;A name=discussion-id18&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EQYNM&gt;4.9.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="in a"&gt;&lt;/A&gt;SQLite stores all database information in a 
single file on disk. This means that before an application can access a 
database, it must first have a reference to the file. A single application might 
choose to access any number of database files. Databases are managed through &lt;A 
name=I_indexterm4_d1e7321&gt;&lt;/A&gt;the &lt;TT&gt;SQLConnection&lt;/TT&gt; data type.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="file through"&gt;&lt;/A&gt;You can obtain a reference to the 
database file through the &lt;TT&gt;File.resolvePath()&lt;/TT&gt; method, &lt;A 
name=I_indexterm4_d1e7333&gt;&lt;/A&gt;&lt;A name="the file"&gt;&lt;/A&gt;which takes a single 
argument: the name of the file that will be referenced. Files that do not yet 
exist can have a reference, and the &lt;TT&gt;File.exists&lt;/TT&gt;&lt;A 
name="property&amp;#13;&amp;#10;        returns"&gt;&lt;/A&gt; property returns a 
&lt;TT&gt;Boolean&lt;/TT&gt;&lt;A name="that&amp;#13;&amp;#10;        file"&gt;&lt;/A&gt; to determine that 
file&amp;#8216;s presence on disk:&lt;/P&gt;&lt;PRE&gt;var db = new air.SQLConnection();
var file =
air.File.applicationStorageDirectory.
resolvePath( &amp;#8216;mycrm.db&amp;#8216; );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="database file"&gt;&lt;/A&gt;The extension to the database file 
is not specific and can be named as necessary for the application.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="asynchronous database"&gt;&lt;/A&gt;To operate using 
asynchronous database transactions, an application must first create and 
register a handler for the events in which it is interested. In the case of 
establishing a connection to a database, &lt;A name=I_indexterm4_d1e7349&gt;&lt;/A&gt;the 
&lt;TT&gt;SQLEvent.OPEN&lt;/TT&gt; event will be monitored. Among various other properties, 
you can use the &lt;TT&gt;SQLEvent.type&lt;/TT&gt; property to determine the status of the 
database.&lt;/P&gt;&lt;PRE&gt;db.addEventListener( air.SQLEvent.OPEN, doDbOpen );

function doDbOpen( event )
{
    alert(&amp;#8216;Connected&amp;#8216; );
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;SQLConnection.open()&lt;/TT&gt;&lt;A name="arguments are"&gt;&lt;/A&gt; 
method can take a number of different arguments. The most common arguments are 
the file reference to the database, and a &lt;TT&gt;String&lt;/TT&gt;&lt;A name="in which"&gt;&lt;/A&gt; 
value indicating the mode in which the database should be opened. The default 
value of &lt;TT&gt;SQLMode.CREATE&lt;/TT&gt; &lt;A name=I_indexterm4_d1e7372&gt;&lt;/A&gt;&lt;A 
name="not exist"&gt;&lt;/A&gt;will create the database if it does not exist, and then 
will establish a connection to the database.&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Connecting to a Database&amp;lt;/title&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script&amp;gt;
var db = new air.SQLConnection();

function doDbOpen( event )
{
    alert( &amp;#8216;You are now connected to the database.&amp;#8216; );
}

function doLoad()
{
    var file = air.File.applicationDirectory.resolvePath(
 &amp;#8216;crm.db&amp;#8216; );

    db.addEventListener( air.SQLEvent.OPEN, doDbOpen );
    db.open( file, air.SQLMode.READ );
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;


&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=create_database_tables&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0EV1NM&gt;4.9.2. Create Database 
Tables&lt;/H4&gt;&lt;A name=problem-id19&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EZ1NM&gt;4.9.2.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;An application has a specific &lt;A name=ch04-dbtables&gt;&lt;/A&gt;&lt;A 
name=ch04-tbl&gt;&lt;/A&gt;&lt;A name="for data"&gt;&lt;/A&gt;schema it needs to provide for data 
storage.&lt;/P&gt;&lt;A name=solution-id19&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EL2NM&gt;4.9.2.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;You can create a database schema using the 
&lt;TT&gt;SQLStatement&lt;/TT&gt; class, using SQL92 grammar.&lt;/P&gt;&lt;A 
name=discussion-id19&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EU2NM&gt;4.9.2.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="a connection"&gt;&lt;/A&gt;Once a database file has been 
created and a connection to the database has been established, the next likely 
step will be to create any required schema. You can do this using&lt;A 
name=I_indexterm4_d1e7408&gt;&lt;/A&gt; SQL92 in conjunction with the 
&lt;TT&gt;SQLStatement&lt;/TT&gt; class. The &lt;TT&gt;SQLStatement&lt;/TT&gt; class executes commands 
against a specified database.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="check for"&gt;&lt;/A&gt;Using an asynchronous approach, the 
best place to check for any required schemaâ€”or to create itâ€”is in the handler 
for the &lt;TT&gt;SQLEvent.OPEN&lt;/TT&gt;&lt;A name="At this"&gt;&lt;/A&gt; event. At this point, the 
application can be assured a connection against which statements can be 
executed. Along the same lines, event handlers must also be registered on the 
&lt;TT&gt;SQLStatement&lt;/TT&gt; instance:&lt;/P&gt;&lt;PRE&gt;var stmt = new air.SQLStatement();

stmt.addEventListener( air.SQLErrorEvent.ERROR, doStmtError );
stmt.addEventListener( air.SQLEvent.RESULT, doStmtResult );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="to a"&gt;&lt;/A&gt;When applied to a &lt;TT&gt;SQLStatement&lt;/TT&gt; 
object, the &lt;TT&gt;SQLErrorEvent.ERROR&lt;/TT&gt; event &lt;A 
name=I_indexterm4_d1e7438&gt;&lt;/A&gt;&lt;A name="error has"&gt;&lt;/A&gt;is called when an error 
has occurred while executing a &lt;TT&gt;SQLStatement.next()&lt;/TT&gt; or 
&lt;TT&gt;SQLStatement.execute()&lt;/TT&gt; method. Conversely, the &lt;TT&gt;SQLEvent.RESULT&lt;/TT&gt; 
event&lt;A name=I_indexterm4_d1e7452&gt;&lt;/A&gt;&lt;A name="results are"&gt;&lt;/A&gt; is called when 
results are returned from the database. This usually indicates a successful 
execution:&lt;/P&gt;&lt;PRE&gt;function doStmtError( event )
{
    alert( &amp;#8216;There has been a problem executing 
    the statement.&amp;#8216; );
}

function doStmtResult( event )
{
    alert( &amp;#8216;The database table has 
    been created.&amp;#8216; );
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;To execute a SQL statement, a &lt;TT&gt;SQLConnection&lt;/TT&gt;&lt;A 
name=a&gt;&lt;/A&gt; instance against which to execute must be established. You can 
assign a &lt;TT&gt;SQLConnection&lt;/TT&gt; instance to the 
&lt;TT&gt;SQLStatement.sqlConnection&lt;/TT&gt; property. The &lt;TT&gt;SQLStatement.text&lt;/TT&gt;&lt;A 
name="any SQL"&gt;&lt;/A&gt; property is then assigned any SQL that needs to be executed. 
Finally, the &lt;TT&gt;SQLStatement.execute()&lt;/TT&gt; method is called:&lt;/P&gt;&lt;PRE&gt;stmt.sqlConnection = db;
stmt.text = &amp;#8216;CREATE TABLE IF NOT EXISTS contact ( &amp;#8216; +
    &amp;#8216;id INTEGER PRIMARY KEY AUTOINCREMENT, &amp;#8216; +
    &amp;#8216;first TEXT, &amp;#8216; +
    &amp;#8216;last TEXT )&amp;#8216;;
stmt.execute();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;In this case, a &lt;TT&gt;CREATE TABLE&lt;/TT&gt; statement&lt;A 
name=I_indexterm4_d1e7482&gt;&lt;/A&gt;&lt;A name="of&amp;#13;&amp;#10;        SQL"&gt;&lt;/A&gt; has been 
applied to the database. Additional types of SQL statements, such as 
&lt;TT&gt;SELECT&lt;/TT&gt;, &lt;TT&gt;INSERT&lt;/TT&gt;, &lt;TT&gt;UPDATE&lt;/TT&gt;, and &lt;TT&gt;DELETE&lt;/TT&gt;, are&lt;A 
name=I_indexterm4_d1e7499&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e7502&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7505&gt;&lt;/A&gt; executed in the same manner. &lt;A 
name=I_indexterm4_d1e7509&gt;&lt;/A&gt;The &lt;TT&gt;SQLStatement.execute()&lt;/TT&gt;&lt;A 
name="the number"&gt;&lt;/A&gt; method can take two optional arguments: the number of 
rows to prefetch, and a responder object to handle events.&lt;/P&gt;
&lt;P class=docText&gt;The prefetch option defaults to &lt;TT&gt;-1&lt;/TT&gt;&lt;A 
name="responder object"&gt;&lt;/A&gt;, which indicates that all rows should be returned. 
The responder object can be a custom object designed to handle any status or 
result events that take place during execution. The default responder is 
&lt;TT&gt;null&lt;/TT&gt;&lt;A name="registered with"&gt;&lt;/A&gt; in this case, as event handlers have 
been registered with the &lt;TT&gt;SQLStatement&lt;/TT&gt;&lt;A name="object directly"&gt;&lt;/A&gt; 
object directly:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Creating Database Tables&amp;lt;/title&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script&amp;gt;
var db = null;
var stmt = null

function doDbOpen( event )
{
    stmt = new air.SQLStatement();
    stmt.addEventListener( air.SQLErrorEvent.ERROR, 
doStmtError );
    stmt.addEventListener( air.SQLEvent.RESULT, doStmtResult );

    stmt.sqlConnection = db;
    stmt.text = &amp;#8216;CREATE TABLE IF NOT EXISTS contact ( &amp;#8216; +
                        &amp;#8216;id INTEGER PRIMARY KEY 
AUTOINCREMENT, &amp;#8216; +
                        &amp;#8216;first TEXT, &amp;#8216; +
                        &amp;#8216;last TEXT )&amp;#8216;;

    stmt.execute();
}

function doLoad()
{
    var file = air.File.applicationDirectory.resolvePath(
 &amp;#8216;crm.db&amp;#8216; );

    db = new air.SQLConnection();
    db.addEventListener( air.SQLEvent.OPEN, doDbOpen );
    db.open( file, air.SQLMode.CREATE );
}

function doStmtResult( event )
{
    alert( &amp;#8216;The database table has been created.&amp;#8216; );
}

function doStmtError( event )
{
    alert( &amp;#8216;There has been a problem executing 
    a statement:\n&amp;#8216; + event.error.message );
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;



&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=store_data_in_a_database&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0E36NM&gt;4.9.3. Store Data in a 
Database&lt;/H4&gt;&lt;A name=problem-id20&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EAAOM&gt;4.9.3.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;An application&lt;A name=I_indexterm4_d1e7537&gt;&lt;/A&gt; &lt;A 
name=I_indexterm4_d1e7539&gt;&lt;/A&gt;needs&lt;A name=ch04-dbstore&gt;&lt;/A&gt;&lt;A 
name="data in"&gt;&lt;/A&gt; to store user-provided data in a relational database on 
disk.&lt;/P&gt;&lt;A name=solution-id20&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EZAOM&gt;4.9.3.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;SQL92 &lt;TT&gt;INSERT&lt;/TT&gt; statements &lt;A 
name=I_indexterm4_d1e7555&gt;&lt;/A&gt;&lt;A name="executed using"&gt;&lt;/A&gt;can be created and 
executed using the &lt;TT&gt;SQLStatement&lt;/TT&gt; class.&lt;/P&gt;&lt;A name=discussion-id20&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EKBOM&gt;4.9.3.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="database file"&gt;&lt;/A&gt;Given a valid database file with 
the appropriate schema created, SQL92 statements can be executed using the 
&lt;TT&gt;SQLStatement&lt;/TT&gt; object. The same &lt;TT&gt;SQLStatement&lt;/TT&gt;&lt;A name=same&gt;&lt;/A&gt; 
object can be reused to execute multiple statements. When reusing the same 
&lt;TT&gt;SQLStatement&lt;/TT&gt;&lt;A name="differentiate what"&gt;&lt;/A&gt; object, it is important 
to differentiate what type of statement has just been executed. You can listen 
for the different actions in various ways.&lt;/P&gt;&lt;PRE&gt;function doSave()
{
    var first = document.getElementById( &amp;#8216;txtFirst&amp;#8216; ).value;
    var last = document.getElementById( &amp;#8216;txtLast&amp;#8216; ).value;

    stmt.text = &amp;#8216;INSERT INTO contact VALUES ( &amp;#8216; +
        &amp;#8216;NULL, &amp;#8216; +
        &amp;#8216;\&amp;#8216;&amp;#8216; + first + &amp;#8216;\&amp;#8216;, &amp;#8216; +
        &amp;#8216;\&amp;#8216;&amp;#8216; + last + &amp;#8216;\&amp;#8216; ) &amp;#8216;;
    stmt.execute();
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="handlers for"&gt;&lt;/A&gt;One approach is to assign different 
event handlers for the different statements that will be executed. (Do not 
forget to remove the old handlers.) Another approach is to specify different 
responder objects that have been created with the specific statement in mind. 
The approach used in this example is a basic state machine that tracks what type 
of statement has just been executed:&lt;/P&gt;&lt;PRE&gt;var NONE = - 1;
var CREATE_SCHEMA = 0;
var INSERT_DATA = 1;

var state = NONE;

var stmt = new air.SQLStatement();

// Other database creation and configuration

function doSave()
{
    var first = document.getElementById( &amp;#8216;txtFirst&amp;#8216; ).value;
    var last = document.getElementById( &amp;#8216;txtLast&amp;#8216; ).value;

    stmt.text = &amp;#8216;INSERT INTO contact VALUES ( &amp;#8216; +
        &amp;#8216;NULL, &amp;#8216; +
    &amp;#8216;\&amp;#8216; + first + &amp;#8216;\&amp;#8216;, &amp;#8216; +
        &amp;#8216;\&amp;#8216;&amp;#8216; + last + &amp;#8216;\&amp;#8216; )&amp;#8216;;

    // Track state
    state = INSERT_DATA;
    stmt.execute();
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name=the&gt;&lt;/A&gt;After successfully executing a database 
statement, the &lt;TT&gt;SQLResultEvent.RESULT&lt;/TT&gt; event will be triggered. If an 
error occurs, the &lt;TT&gt;SQLStatusEvent.STATUS&lt;/TT&gt;&lt;A name="designed to"&gt;&lt;/A&gt; event 
will be raised. By tracking the state, the method designed to handle the result 
can determine the appropriate action(s) to take. In the case of inserting new 
data, this may be user notification and updating of the user interface:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Storing Data in a Database&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var db = null;
var stmt = null

var NONE = -1;
var CREATE_SCHEMA = 0;
var INSERT_DATA = 1;

var state = NONE;

function doDbOpen( event )
{
    stmt = new air.SQLStatement();
    stmt.addEventListener( air.SQLErrorEvent.ERROR, 
doStmtError );
    stmt.addEventListener( air.SQLEvent.RESULT, 
    doStmtResult );

    stmt.sqlConnection = db;
    stmt.text = &amp;#8216;CREATE TABLE IF NOT EXISTS contact ( &amp;#8216; +
                        &amp;#8216;id INTEGER PRIMARY KEY 
AUTOINCREMENT, &amp;#8216; +
                        &amp;#8216;first TEXT, &amp;#8216; +
                        &amp;#8216;last TEXT )&amp;#8216;;

    state = CREATE_SCHEMA;
    stmt.execute();
}

function doLoad()
{
    var file = air.File.applicationDirectory.resolvePath(
 &amp;#8216;crm.db&amp;#8216; );

    db = new air.SQLConnection();
    db.addEventListener( air.SQLEvent.OPEN, doDbOpen );
    db.open( file, air.SQLMode.CREATE );

    document.getElementById( &amp;#8216;btnSave&amp;#8216; ).addEventListener(
 &amp;#8216;click&amp;#8216;, doSave );
}

function doSave()
{
    var first = document.getElementById( &amp;#8216;txtFirst&amp;#8216; ).value;
    var last = document.getElementById( &amp;#8216;txtLast&amp;#8216; ).value;

    stmt.text = &amp;#8216;INSERT INTO contact VALUES ( &amp;#8216; +
                        &amp;#8216;NULL, &amp;#8216; +
                        &amp;#8216;\&amp;#8216;&amp;#8216; + first + &amp;#8216;\&amp;#8216;, &amp;#8216; +
                        &amp;#8216;\&amp;#8216;&amp;#8216; + last + &amp;#8216;\&amp;#8216; )&amp;#8216;;

    state = INSERT_DATA;
    stmt.execute();
}

function doStmtResult( event )
{
    switch( state )
    {
         case CREATE_SCHEMA:
              alert( &amp;#8216;The database table has been created.&amp;#8216; );
              state = NONE;

              break;

         case INSERT_DATA:
              document.getElementById( &amp;#8216;txtFirst&amp;#8216; ).value = &amp;#8216;&amp;#8216;;
              document.getElementById( &amp;#8216;txtLast&amp;#8216; ).value = &amp;#8216;&amp;#8216;;

              alert( &amp;#8216;A new record has been stored.&amp;#8216; );
    }
}

function doStmtError( event )
{
    alert( &amp;#8216;There has been a problem executing a 
    statement:\n&amp;#8216; + event.error.message );
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onLoad="doLoad();"&amp;gt;

&amp;lt;div&amp;gt;
    First name: &amp;lt;input id="txtFirst" type="text" /&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
    Last name: &amp;lt;input id="txtLast" type="text" /&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;div&amp;gt;
    &amp;lt;input id="btnSave" type="button" value="Save" /&amp;gt;
&amp;lt;/div&amp;gt;

&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=access_database_data&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0ELCOM&gt;4.9.4. Access Database Data&lt;/H4&gt;&lt;A 
name=problem-id21&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EPCOM&gt;4.9.4.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;You need &lt;A name=I_indexterm4_d1e7600&gt;&lt;/A&gt;to generate&lt;A 
name=ch04-dbaccess&gt;&lt;/A&gt;&lt;A name="embedded&amp;#13;&amp;#10;        database"&gt;&lt;/A&gt; a 
tabular display of data from the embedded database.&lt;/P&gt;&lt;A 
name=solution-id21&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0ECDOM&gt;4.9.4.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="Database data"&gt;&lt;/A&gt;Database data can be queried using 
SQL92 and the &lt;TT&gt;SQLStatement&lt;/TT&gt; class.&lt;/P&gt;&lt;A name=discussion-id21&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0ELDOM&gt;4.9.4.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="run traditional"&gt;&lt;/A&gt;You can run traditional&lt;A 
name=I_indexterm4_d1e7621&gt;&lt;/A&gt; &lt;TT&gt;SELECT&lt;/TT&gt; statements using&lt;A 
name=I_indexterm4_d1e7628&gt;&lt;/A&gt; a &lt;TT&gt;SQLStatement&lt;/TT&gt;&lt;A 
name="referenced against"&gt;&lt;/A&gt; object that has been referenced against an 
existing database. A successful execution of the &lt;TT&gt;SELECT&lt;/TT&gt;&lt;A 
name=registered&gt;&lt;/A&gt; statement invokes the registered 
&lt;TT&gt;SQLResultEvent.RESULT&lt;/TT&gt; event handler. That event handler will get a 
&lt;TT&gt;SQLResultEvent&lt;/TT&gt; object &lt;A name=I_indexterm4_d1e7645&gt;&lt;/A&gt;which contains 
the result data:&lt;/P&gt;&lt;PRE&gt;function doStmtResult( event )
{
    var elem = null;
    var results = stmt.getResult();

    if( results.data != null )
    {
         for( var c = 0; c &amp;lt; results.data.length; c++ )
         {
              elem = document.createElement( &amp;#8216;div&amp;#8216; );
              elem.innerText = results.data[c].first + &amp;#8216; &amp;#8216;  
+ results.data[c].last;

              document.body.appendChild( elem );
         }
    }
}
&lt;/PRE&gt;&lt;BR&gt;&lt;A name=discussion-id21d1e7659&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="connectivity covered"&gt;&lt;/A&gt;This snippet forgoes much of 
the state management, event registration, and database connectivity covered in 
other sections. Please review that content, or the example at the end of this 
section, for complete coverage of the topic.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;To get any result data, &lt;TT&gt;SQLStatement.getResult()&lt;/TT&gt; is &lt;A 
name=I_indexterm4_d1e7659&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e7662&gt;&lt;/A&gt;called, which 
returns a &lt;TT&gt;SQLResult&lt;/TT&gt; object. The &lt;TT&gt;SQLResult.data&lt;/TT&gt; property is an 
&lt;TT&gt;Array&lt;/TT&gt; of the results, if any. &lt;TT&gt;SQLResult.data&lt;/TT&gt; Array&lt;A 
name=I_indexterm4_d1e7679&gt;&lt;/A&gt; will contain &lt;TT&gt;Object&lt;/TT&gt;&lt;A 
name="the names"&gt;&lt;/A&gt; instances whose properties match the names of the columns 
used in the query. This &lt;TT&gt;Array&lt;/TT&gt;&lt;A name="results of"&gt;&lt;/A&gt; can be used to 
iterate over the results of a query.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="is being"&gt;&lt;/A&gt;If the database table that is being 
queried has no data, or the statement did not return any data, the 
&lt;TT&gt;SQLResult.data&lt;/TT&gt; property will be &lt;TT&gt;null&lt;/TT&gt;:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Accessing Data in a Database&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var db = null;
var stmt = null

var NONE = -1;
var CREATE_SCHEMA = 0;
var SELECT_DATA = 1;

var state = NONE;

function doDbOpen( event )
{
    stmt = new air.SQLStatement();
    stmt.addEventListener( air.SQLErrorEvent.ERROR, 
doStmtError );
    stmt.addEventListener( air.SQLEvent.RESULT, doStmtResult );

    stmt.sqlConnection = db;
    stmt.text = &amp;#8216;CREATE TABLE IF NOT EXISTS contact ( &amp;#8216; +
                        &amp;#8216;id INTEGER PRIMARY KEY 
AUTOINCREMENT, &amp;#8216; +
                        &amp;#8216;first TEXT, &amp;#8216; +
                        &amp;#8216;last TEXT )&amp;#8216;;

    state = CREATE_SCHEMA;
    stmt.execute();
}

function doLoad()
{
    var file = air.File.applicationDirectory.resolvePath(
 &amp;#8216;crm.db&amp;#8216; );

    db = new air.SQLConnection();
    db.addEventListener( air.SQLEvent.OPEN, doDbOpen );
    db.open( file, air.SQLMode.CREATE );
}

function doStmtResult( event )
{
    var elem = null;
    var result = null;

    switch( state )
    {
         case CREATE_SCHEMA:
              stmt.text = &amp;#8216;SELECT * FROM contact&amp;#8216;;

              state = SELECT_DATA;
              stmt.execute();

              break;

        case SELECT_DATA:
              result = stmt.getResult();

              if( result.data != null )
              {
                   for( var c = 0; c &amp;lt; result.data.length; 
                   c++ )
                   {
                      elem = document.createElement( &amp;#8216;div&amp;#8216; );
                      elem.innerText = result.data[c].first +
                      &amp;#8216; &amp;#8216; + result.data[c].last;

                        document.body.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=40933512144&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Command-Line Arguments</title><link>http://www.softxml.com/LearnTutorial.asp?id=22526873374&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class=docSection2Title id=title-ID0ESWNM&gt;4.10.1. Capture Command-Line 
Arguments&lt;/H4&gt;&lt;A name=problem-id22&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EWWNM&gt;4.10.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;You&lt;A name=I_indexterm4_d1e7710&gt;&lt;/A&gt; &lt;A 
name=I_indexterm4_d1e7712&gt;&lt;/A&gt;need&lt;A name=ch04-command&gt;&lt;/A&gt;&lt;A 
name="to capture"&gt;&lt;/A&gt; to capture command-line arguments sent to your 
applicationâ€”either at application startup or while the application is 
running.&lt;/P&gt;&lt;A name=solution-id22&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EPXNM&gt;4.10.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name=the&gt;&lt;/A&gt;Register for the &lt;TT&gt;InvokeEvent&lt;/TT&gt;, &lt;A 
name=I_indexterm4_d1e7728&gt;&lt;/A&gt;&lt;A name="into your"&gt;&lt;/A&gt;and capture command-line 
arguments passed into your application.&lt;/P&gt;&lt;A name=discussion-id22&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E4XNM&gt;4.10.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="is started"&gt;&lt;/A&gt;Whenever an application is started, or 
an application is called from the command line while it is running, an 
&lt;TT&gt;InvokeEvent&lt;/TT&gt;&lt;A name="about the"&gt;&lt;/A&gt; will be broadcast. The event 
handler for this is passed information about the event, including any arguments 
passed to the application on the command line.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name=the&gt;&lt;/A&gt;You should register for the 
&lt;TT&gt;InvokeEvent&lt;/TT&gt;&lt;A name="event is"&gt;&lt;/A&gt; during your application&amp;#8216;s 
initialization phase, to ensure that the event is captured when the application 
is initially launched.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="event from"&gt;&lt;/A&gt;You can register for the event from 
the &lt;TT&gt;NativeApplication&lt;/TT&gt; singleton, like so:&lt;/P&gt;&lt;PRE&gt;function init()
{
air.NativeApplication.nativeApplication.addEventListener
(air.InvokeEvent.INVOKE,onInvoke);
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;This registers the &lt;TT&gt;onInvoke&lt;/TT&gt; function as a handler for 
&lt;TT&gt;InvokeEvent&lt;/TT&gt;. The handler is passed an instance of the 
&lt;TT&gt;InvokeEvent&lt;/TT&gt; object, which contains a property named &lt;TT&gt;arguments&lt;/TT&gt; 
which is an &lt;TT&gt;Array&lt;/TT&gt; of &lt;TT&gt;Strings&lt;/TT&gt; of any arguments passed to the 
application:&lt;/P&gt;&lt;PRE&gt;function onInvoke(event)
{
    air.trace("onInvoke : " + event.arguments);
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="in&amp;#13;&amp;#10;        command"&gt;&lt;/A&gt;When testing your 
application via ADL, you can pass in command-line arguments by using&lt;A 
name=I_indexterm4_d1e7777&gt;&lt;/A&gt; the &lt;TT&gt;--&lt;/TT&gt; argument. For example:&lt;/P&gt;&lt;PRE&gt;adl InvokeExample.xml -- foo "bim bam"
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="the application"&gt;&lt;/A&gt;This would pass in two arguments 
to the application: &lt;TT&gt;foo&lt;/TT&gt;&lt;A name=and&gt;&lt;/A&gt; and &lt;TT&gt;bim bam&lt;/TT&gt;.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="example follows"&gt;&lt;/A&gt;The complete example follows; it 
listens for the &lt;TT&gt;InvokeEvent&lt;/TT&gt;&lt;A name="the included"&gt;&lt;/A&gt;, and prints out 
to the included &lt;TT&gt;textarea&lt;/TT&gt;&lt;A name="as&amp;#13;&amp;#10;        the"&gt;&lt;/A&gt; HTML 
control, as well as the command line&lt;A name=I_indexterm4_d1e7802&gt;&lt;/A&gt; via 
&lt;TT&gt;air.trace()&lt;/TT&gt;:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

    &amp;lt;script src="AIRAliases.js" /&amp;gt;
    &amp;lt;script type="text/javascript"&amp;gt;

      function onInvoke(event)
      {
        air.trace("onInvoke : " + event.arguments);

         var field = document.getElementById("outputField");
         field.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=22526873374&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Networking</title><link>http://www.softxml.com/LearnTutorial.asp?id=22440560416&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class=docSection2Title id=title-ID0E2WNM&gt;4.11.1. Communicate on a 
Socket&lt;/H4&gt;&lt;A name=problem-id23&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E6WNM&gt;4.11.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;You&lt;A name=I_indexterm4_d1e7823&gt;&lt;/A&gt; &lt;A 
name=ch04-networking&gt;&lt;/A&gt;&lt;A name="would like"&gt;&lt;/A&gt;would like to communicate with 
a server using a protocol that is not directly supported by Adobe AIR (e.g., 
communicate with&lt;A name=I_indexterm4_d1e7829&gt;&lt;/A&gt; an FTP server).&lt;/P&gt;&lt;A 
name=solution-id23&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EWXNM&gt;4.11.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;Use the &lt;TT&gt;Socket&lt;/TT&gt; class in the&lt;A 
name=I_indexterm4_d1e7841&gt;&lt;/A&gt;&lt;A name="to send"&gt;&lt;/A&gt; AIR API to send binary or 
text data to the server and register for events that will alert you to incoming 
data from the server.&lt;/P&gt;&lt;A name=discussion-id23&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EEYNM&gt;4.11.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="other than"&gt;&lt;/A&gt;When communicating using protocols 
other than those directly supported by Adobe AIR, you may need to use the Socket 
API. The Socket API is an asynchronous API that lets you send data to a 
persistent socket endpoint and receive data from it in real time. You do not 
need to create a new &lt;TT&gt;Socket&lt;/TT&gt;&lt;A name="set of"&gt;&lt;/A&gt; instance for each set 
of data sent to the same endpoint. The connection can be kept alive for the 
entire conversation between your client and the service to which you&amp;#8216;re 
connecting. This is the typical flow when using the Socket API:&lt;/P&gt;
&lt;DIV style="FONT-WEIGHT: bold"&gt;
&lt;OL class=docList type=1&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Create a connection to the endpoint.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Listen for notification of connection success or 
failure.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Queue data that will be sent to the endpoint.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Send the data to the endpoint.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Listen for data incoming from the endpoint.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Repeat steps 3 through 5.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Close the connection.&lt;/P&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="socket endpoint"&gt;&lt;/A&gt;The first step is to create a 
connection to the socket endpoint that consists of a host and a port number. For 
example, to connect to an endpoint the host might be &lt;A class=docLink 
href="http://foo.com" target=_blank&gt;foo.com&lt;/A&gt;&lt;A name="might be"&gt;&lt;/A&gt; and the 
port number might be 5555. Create the instance of the &lt;TT&gt;Socket&lt;/TT&gt;&lt;A 
name="that information"&gt;&lt;/A&gt; class and connect to the endpoint using that 
information. At this time, we will also set up our listeners to listen for the 
different events that the Socket can dispatch:&lt;/P&gt;&lt;PRE&gt;var socket = new air.Socket();
socket.addEventListener( air.Event.CONNECT, onSocketOpen );
socket.addEventListener( air.ProgressEvent.SOCKET_DATA, 
onSocketData );
socket.connect( &amp;#8216;foo.com&amp;#8216;, 5555 );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="create the"&gt;&lt;/A&gt;We will also need to create the 
functions to handle the events for which we subscribed. The first event is the 
&lt;TT&gt;air.Event.CONNECT&lt;/TT&gt; event. &lt;A name=I_indexterm4_d1e7890&gt;&lt;/A&gt;&lt;A 
name="has been"&gt;&lt;/A&gt;This event will tell us when the socket has been initiated 
and when communication with the service behind the endpoint is possible. In this 
example, we are sending the bytes of a UTF-8 encoded string to the service:&lt;/P&gt;&lt;PRE&gt;function onSocketOpen( event )
{
    // This queues up the binary representation of the
    // string &amp;#8216;Bob&amp;#8216; in UTF-8 format to be sent to the
    // endpoint.
    socket.writeUTFBytes( "Bob" );

    // Send the actual bytes to the server and clear
    // the stream. We then wait for data to be sent
    // back to us.
    socket.flush();
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;air.ProgressEvent.SOCKET_DATA&lt;/TT&gt; event &lt;A 
name=I_indexterm4_d1e7901&gt;&lt;/A&gt;&lt;A name="we&amp;#13;&amp;#10;        are"&gt;&lt;/A&gt;is 
dispatched whenever data is received. The service we are connecting to uses a 
simple protocol: we send a UTF-8 encoded&lt;A name=I_indexterm4_d1e7905&gt;&lt;/A&gt;&lt;A 
name="string and"&gt;&lt;/A&gt; string and it returns a UTF-8 encoded string. This makes 
accessing the data sent back to us very simple. To access this data, we measure 
the total number of bytes of data available on the Socket and read that many 
bytes as a UTF-8 encoded string using the &lt;TT&gt;readUTFBytes()&lt;/TT&gt;&lt;A 
name=the&gt;&lt;/A&gt; method of the &lt;TT&gt;Socket&lt;/TT&gt; class.&lt;/P&gt;&lt;PRE&gt;function onSocketData( event )
{
    var data =
      socket.readUTFBytes( socket.bytesAvailable );
    air.trace( data ); // Hello Bob
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="of communication"&gt;&lt;/A&gt;In our example, the protocol of 
communication was just a single string. In some cases, depending on the service 
with which you&amp;#8216;re communicating, you may need to send and receive other data 
types. The &lt;TT&gt;Socket&lt;/TT&gt;&lt;A name="for&amp;#13;&amp;#10;        reading"&gt;&lt;/A&gt; class 
provides methods for reading and writing many data types,&lt;A 
name=I_indexterm4_d1e7922&gt;&lt;/A&gt;&lt;A name=I_indexterm4_d1e7925&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e7928&gt;&lt;/A&gt; such as &lt;TT&gt;int&lt;/TT&gt;s, &lt;TT&gt;Boolean&lt;/TT&gt;s, 
&lt;TT&gt;float&lt;/TT&gt;&lt;A name="that required"&gt;&lt;/A&gt;s, and more. For example, if we were 
talking with a fictional service that required us to send a &lt;TT&gt;Boolean&lt;/TT&gt; 
followed by an &lt;TT&gt;int&lt;/TT&gt;, our &lt;TT&gt;onSocketOpen&lt;/TT&gt;&lt;A 
name="example could"&gt;&lt;/A&gt; function in the preceding example could look like 
this:&lt;/P&gt;&lt;PRE&gt;function onSocketOpen( event )
{
    // First send the boolean
    socket.writeBoolean( true );
    // Now send an int
    socket.writeInt( 10 );

    // Now we send the bytes to the service and
    // clear the buffer.
    socket.flush();
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="that can"&gt;&lt;/A&gt;This example provides a baseline of 
functionality that can be expanded upon to speak to many different protocols. 
The only current limitation is that there is not currently an SSL Socket 
implementation in AIR. For secure communication you will be limited to 
HTTPS:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Communicating on a Socket&amp;lt;/title&amp;gt;
&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;
&amp;lt;/script&amp;gt;

&amp;lt;script&amp;gt;
var socket = null;

function init()
{
   socket = new air.Socket();

   // Create our listeners which tell us when the Socket
   // is open and when we receive data from our service.
    socket.addEventListener( air.Event.CONNECT, 
    onSocketOpen );
    socket.addEventListener( air.ProgressEvent.SOCKET_DATA,
                           onSocketData );

    // Connect to our service, which is located at 
    // host foo.com using port 5555.
    socket.connect( &amp;#8216;foo.com&amp;#8216;, 5555 );
}

function onSocketOpen( event )
{
    // This queues up the binary representation of the
    // string &amp;#8216;Bob&amp;#8216; in UTF-8 format to be sent to the
    // endpoint.
    socket.writeUTFBytes( "Bob" );

    // Send the actual bytes to the server and clear
    // the stream. We then wait for data to be sent
    // back to us.
    socket.flush();
}

function onSocketData( event )
{
    var data = socket.readUTFBytes( socket.bytesAvailable );
    air.trace( data ); // Hello Bob
}
&amp;lt;/script&amp;gt;

&amp;lt;/head&amp;gt;
&amp;lt;body onload="init()"&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;


					  &lt;/PRE&gt;&lt;BR&gt;&lt;A name=upload_a_file_in_the_background&gt;&lt;/A&gt;
&lt;H4 class=docSection2Title id=title-ID0E12NM&gt;4.11.2. Upload a File in the 
Background&lt;/H4&gt;&lt;A name=problem-id24&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E52NM&gt;4.11.2.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;The application user has created&lt;A name=ch04-uploading&gt;&lt;/A&gt;&lt;A 
name="want to"&gt;&lt;/A&gt; numerous files offline, and you now want to send those to 
the server without blocking the user from doing any additional work.&lt;/P&gt;&lt;A 
name=solution-id24&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EK3NM&gt;4.11.2.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File&lt;/TT&gt; class in Adobe AIR provides an 
&lt;TT&gt;upload()&lt;/TT&gt; method &lt;A name=ch04-fileupload&gt;&lt;/A&gt;&lt;A 
name="to create"&gt;&lt;/A&gt;that is designed specifically for this purpose, without 
having to create and manage HTML forms.&lt;/P&gt;&lt;A name=discussion-id24&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0E43NM&gt;4.11.2.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;The &lt;TT&gt;File.upload()&lt;/TT&gt;&lt;A name="server for"&gt;&lt;/A&gt; method can 
upload files via HTTP/S to a server for additional processing. The upload takes 
places just like a traditional multipart file upload from an HTML form, but 
without the need to manipulate forms on the client. The upload process also 
takes place asynchronously in the background, allowing the application to 
continue processing without interruption.&lt;/P&gt;&lt;A name=discussion-id24d1e8003&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="The implementation"&gt;&lt;/A&gt;The implementation of the 
receiving server is beyond the scope of this example. Numerous technologies, and 
tutorials for these technologies, elegantly handle file upload. You&amp;#8216;re 
encouraged to investigate your options.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;&lt;A name="events that"&gt;&lt;/A&gt;The primary events that are useful 
are &lt;TT&gt;ProgressEvent.PROGRESS&lt;/TT&gt; and&lt;A name=I_indexterm4_d1e8003&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e8006&gt;&lt;/A&gt; &lt;TT&gt;Event.COMPLETE&lt;/TT&gt;&lt;A 
name="the application"&gt;&lt;/A&gt;. These events handle notifying the application of 
upload progress, and when an individual upload is complete, respectively:&lt;/P&gt;&lt;PRE&gt;var file =
new air.File.documentsDirectory.
resolvePath( &amp;#8216;myImage.jpg&amp;#8216; );

file.addEventListener( air.ProgressEvent.PROGRESS, 
doProgress );
file.addEventListener( air.Event.COMPLETE, 
doComplete );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;TT&gt;ProgressEvent&lt;/TT&gt;&lt;A name="that can"&gt;&lt;/A&gt; contains various 
properties that can help in reflecting upload progress in the user interface. 
The most notable of these properties are &lt;TT&gt;ProgressEvent.bytesLoaded&lt;/TT&gt; and 
&lt;TT&gt;ProgressEvent.bytesTotal&lt;/TT&gt;&lt;A name="and the"&gt;&lt;/A&gt;, which show how much of 
the file has been uploaded and the total size of the file. 
&lt;TT&gt;Event.COMPLETE&lt;/TT&gt;&lt;A name="upload is"&gt;&lt;/A&gt; is broadcast once the upload is 
complete.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name=valid&gt;&lt;/A&gt;To start the upload, you first need a valid 
&lt;TT&gt;File&lt;/TT&gt;&lt;A name="resource on"&gt;&lt;/A&gt; object that points to a resource on 
disk.&lt;/P&gt;
&lt;P class=docText&gt;&lt;A name="want&amp;#13;&amp;#10;        to"&gt;&lt;/A&gt;Once a valid file 
reference is established, developers will want to call the 
&lt;TT&gt;File.upload()&lt;/TT&gt; method. The &lt;TT&gt;File.upload()&lt;/TT&gt;&lt;A name="which is"&gt;&lt;/A&gt; 
method can take three arguments, the first of which is a &lt;TT&gt;URLRequest&lt;/TT&gt;&lt;A 
name="object that"&gt;&lt;/A&gt; object that contains information about where the file 
should be sent. The &lt;TT&gt;URLRequest&lt;/TT&gt;&lt;A name="also contain"&gt;&lt;/A&gt; object can 
also contain additional data to be passed to the receiving server. This 
additional data manifests itself as HTML form fields might during a traditional 
multipart file upload:&lt;/P&gt;&lt;PRE&gt;var request = new air.URLRequest( 
&amp;#8216;http://www.mydomain.com/upload&amp;#8216; );
file.upload( request, &amp;#8216;image&amp;#8216;, false );
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="to the"&gt;&lt;/A&gt;The second argument provided to the 
&lt;TT&gt;File.upload()&lt;/TT&gt; method&lt;A name=I_indexterm4_d1e8054&gt;&lt;/A&gt;&lt;A 
name="name of"&gt;&lt;/A&gt; call is the name of the form field that contains the file 
data.&lt;/P&gt;
&lt;P class=docText&gt;The third argument is a &lt;TT&gt;Boolean&lt;/TT&gt;&lt;A name="a test"&gt;&lt;/A&gt; 
value that tells the upload process whether it should try a test before sending 
the actual file. The test upload will &lt;TT&gt;POST&lt;/TT&gt;&lt;A name="to the"&gt;&lt;/A&gt; 
approximately 10 KB of data to the endpoint to see if the endpoint responds. If 
the service monitoring capabilities of Adobe AIR are not being used, this is a 
good way to check for potential failure of the process.&lt;/P&gt;&lt;A 
name=discussion-id24d1e8075&gt;&lt;/A&gt;
&lt;DIV class=docNote&gt;
&lt;P class=docNormalTitle&gt;NOTE&lt;/P&gt;
&lt;P&gt;
&lt;P class=docText&gt;&lt;A name="been caught"&gt;&lt;/A&gt;More than one great web application 
has been caught by this subtlety. If the server is expecting the file data 
outright, a test upload will almost assuredly cause an error. If you intend to 
use the test facility, be sure that your server code is prepared to handle the 
scenario.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;PRE&gt;function doProgress( event )
{
    var pct = Math.ceil( ( event.bytesLoaded / event.
bytesTotal ) * 100 );
    document.getElementById( &amp;#8216;progress&amp;#8216; ).innerText =
    pct + "%";
}
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;The &lt;TT&gt;Event.COMPLETE&lt;/TT&gt;&lt;A name="that it"&gt;&lt;/A&gt; event is 
relatively straightforward in that it signals the completion of the upload 
process. This is a good place to perform any filesystem maintenance that the 
application might otherwise need to accomplish. An example would be removing the 
just-uploaded file from the local disk to free up space. Another task that might 
be accomplished in the &lt;TT&gt;Event.COMPLETE&lt;/TT&gt; handler is to start the upload of 
subsequent files:&lt;/P&gt;
&lt;DIV class=codeSegmentsExpansionLinks&gt;Code View:&lt;/DIV&gt;&lt;PRE class=""&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

&amp;lt;title&amp;gt;Uploading a File in the Background&amp;lt;/title&amp;gt;

&amp;lt;style type="text/css"&amp;gt;
body {
    font-family: Verdana, Helvetica, Arial, sans-serif;
    font-size: 11px;
    color: #0B333C;
}
&amp;lt;/style&amp;gt;

&amp;lt;script type="text/javascript" src="AIRAliases.js"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;script type="text/javascript"&amp;gt;
var UPLOAD_URL = &amp;#8216;http://www.ketnerlake.com/work/watcher/
upload.cfm&amp;#8216;;

var file = null;

function doComplete( e )
{
    document.getElementById( &amp;#8216;progress&amp;#8216; ).style.visibility = 
&amp;#8216;hidden&amp;#8216;;
    document.getElementById( &amp;#8216;progress&amp;#8216; ).innerText = 
&amp;#8216;Uploading... 0%&amp;#8216;;

    document.getElementById( &amp;#8216;upload&amp;#8216; ).disabled = null;
}

function doLoad()
{
    file = air.File.desktopDirectory;
    file.addEventListener( air.Event.SELECT, doSelect );
    file.addEventListener( air.ProgressEvent.
    PROGRESS, doProgress );
    file.addEventListener( air.Event.
    COMPLETE, doComplete );

    document.getElementById( &amp;#8216;upload&amp;#8216; ).
    addEventListener( &amp;#8216;click&amp;#8216;, doUpload );
}

function doProgress( e )
{
    var loaded = e.bytesLoaded;
    var total = e.bytesTotal;
    var pct = Math.ceil( ( loaded / total ) * 100 );

    document.getElementById( &amp;#8216;progress&amp;#8216; ).innerText = 
&amp;#8216;Uploading... &amp;#8216; +
 pct.toString() + &amp;#8216;%&amp;#8216;;
}

function doSelect( e )
{
    var request = new air.URLRequest( UPLOAD_URL );

    request.contentType = &amp;#8216;multipart/form-data&amp;#8216;;
    request.method = air.URLRequestMethod.POST;

    document.getElementById( &amp;#8216;upload&amp;#8216; ).disabled = &amp;#8216;disabled&amp;#8216;;
    document.getElementById( &amp;#8216;progress&amp;#8216; ).style.visibility = 
&amp;#8216;visible&amp;#8216;;

    file.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=22440560416&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item><item><title>Sound</title><link>http://www.softxml.com/LearnTutorial.asp?id=41214096767&amp;f=adobeair&amp;fo=tutorials</link><description>&lt;H4 class=docSection2Title id=title-ID0EEXNM&gt;4.12.1. Play a Sound&lt;/H4&gt;&lt;A 
name=problem-id25&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EIXNM&gt;4.12.1.1. Problem&lt;/H5&gt;
&lt;P class=docText&gt;You&lt;A name=I_indexterm4_d1e8093&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e8094&gt;&lt;/A&gt; &lt;A name=I_indexterm4_d1e8098&gt;&lt;/A&gt;&lt;A 
name=I_indexterm4_d1e8099&gt;&lt;/A&gt;&lt;A name="need to"&gt;&lt;/A&gt;need to play a sound in your 
application.&lt;/P&gt;&lt;A name=solution-id25&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EDYNM&gt;4.12.1.2. Solution&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="Sound API"&gt;&lt;/A&gt;Use the Sound API within AIR to play an 
MP3 file.&lt;/P&gt;&lt;A name=discussion-id25&gt;&lt;/A&gt;
&lt;H5 class=docSection3Title id=title-ID0EIYNM&gt;4.12.1.3. Discussion&lt;/H5&gt;
&lt;P class=docText&gt;&lt;A name="for accessing"&gt;&lt;/A&gt;AIR includes complete support for 
accessing Flash Player APIs from JavaScript. This includes the &lt;TT&gt;Sound&lt;/TT&gt;&lt;A 
name="be used"&gt;&lt;/A&gt; class that can be used to play local or remote MP3 
files.&lt;/P&gt;
&lt;P class=docText&gt;Playing a sound is simple, and requires two main steps:&lt;/P&gt;
&lt;DIV style="FONT-WEIGHT: bold"&gt;
&lt;OL class=docList type=1&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Create a &lt;TT&gt;URLRequest&lt;/TT&gt; instance &lt;A 
name=I_indexterm4_d1e8123&gt;&lt;/A&gt;that references the local or remote 
sound.&lt;/P&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-WEIGHT: normal"&gt;
&lt;P class=docList&gt;Pass the &lt;TT&gt;URLRequest&lt;/TT&gt; to the &lt;TT&gt;Sound&lt;/TT&gt; instance, 
and play it.&lt;/P&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;/DIV&gt;
&lt;P class=docText&gt;Here is the relevant code snippet:&lt;/P&gt;&lt;PRE&gt;var soundPath =
  new air.URLRequest("app-resource:/sound.mp3");
var s = new air.Sound();
    s.load(soundPath);
    s.play();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;First, we create a &lt;TT&gt;URLRequest&lt;/TT&gt;&lt;A name="In this"&gt;&lt;/A&gt; 
that points to the location of the MP3 file we will play. In this case, we use 
an &lt;TT&gt;app-resource&lt;/TT&gt; URI that references the &lt;I&gt;sound.mp3&lt;/I&gt;&lt;A 
name="application install"&gt;&lt;/A&gt; file contained in the application install 
directory. You can also use any valid URI, including both file and HTTP 
URIs:&lt;/P&gt;&lt;PRE&gt;var soundPath =
  new air.URLRequest("app:/sound.mp3");
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;We then create an instance of the &lt;TT&gt;Sound&lt;/TT&gt;&lt;A 
name=call&gt;&lt;/A&gt; class, pass the reference to the MP3 path, and then call 
&lt;TT&gt;play&lt;/TT&gt;:&lt;/P&gt;&lt;PRE&gt;var s = new air.Sound();
    s.load(soundPath);
    s.play();
&lt;/PRE&gt;&lt;BR&gt;
&lt;P class=docText&gt;&lt;A name="with a"&gt;&lt;/A&gt;Here is the complete example with a Play 
button:&lt;/P&gt;&lt;PRE&gt;&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;

    &amp;lt;script src="AIRAliases.js" /&amp;gt;
    &amp;lt;script type="text/javascript"&amp;gt;

        function playSound()
        {
            var soundPath =
             new air.URLRequest("app:/sound.mp3");
            var s = new air.Sound();
                s.load(soundPath);
                s.</description><guid>http://www.softxml.com/LearnTutorial.asp?id=41214096767&amp;f=adobeair&amp;fo=tutorials</guid><category>adobeair</category></item></channel></rss>
