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

<channel>
	<title>Flex the world &#187; AIR 迷你教程</title>
	<atom:link href="http://www.flextheworld.com/tag/air-%e8%bf%b7%e4%bd%a0%e6%95%99%e7%a8%8b/feed" rel="self" type="application/rss+xml" />
	<link>http://www.flextheworld.com</link>
	<description>Flex, AIR, FMS, P2P and Things......</description>
	<lastBuildDate>Fri, 10 Sep 2010 08:08:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>AIR 迷你教程 — 在AIR 2.0 程序中嵌入TOMCAT（NativeProcess 实例）</title>
		<link>http://www.flextheworld.com/2010/01/air-2-tomcat-nativeprocess.html</link>
		<comments>http://www.flextheworld.com/2010/01/air-2-tomcat-nativeprocess.html#comments</comments>
		<pubDate>Thu, 21 Jan 2010 06:04:05 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[AIR 迷你教程]]></category>
		<category><![CDATA[AIR 2.0]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=670</guid>
		<description><![CDATA[AIR 2.0 有很多令人期待和振奋的功能，使得AIR向成熟的桌面应用程序开发环境又进了一大步。上一篇文章里介绍了ServerSocket的用法，这篇教程中将向大家介绍NativeProcess，在AIR2.0中我们可以使用程序默认的打开方式直接打开一个外部的应用程序 (file.openWithDefaultApplication()) 或者 通过今天要讲的启动进程方式运行一个程序。
AIR与本地应用程序的交互是AIR 2.0的一个重要更新，这个功能的实现可以帮助我们做到在AIR 1.5时代很难完成的事情，比如我在项目中就需要操作一些硬件，但AIR不能直接操作端口，所以只能借助其他的小程序来实现，现在我们就可以很容易的操作这些小程序以达到操作硬件的目的，而Flex (AIR)与JAVA的结合很早就已经开始了，但由于早期AIR的局限性，想要把JAVA直接部署在客户端还是比较麻烦的事情，但是从AIR2.0开始我们不用担心了。现在我们用很简单的方式就可以在AIR程序中集成TOMCAT, 一次性的将后台与AIR部署到客户端。
程序的原版（Flash Builder 4版）同样是从http://coenraets.org/获得，有兴趣的朋友可以关注这个博客。我的例子仍然使用FLEX 3.
Demo过程

下载安装 AIR 2.0 beta runtime.
下载AIRAppWithEmbeddedTomcat..exe 或者 AIRAppWithEmbeddedTomcat.dmg (NativeProcess 必须在程序发布为相应平台的应用程序后才可以使用，发布的方法这里就不介绍了，可以参看http://help.adobe.com/en_US/FlashPlatform/develop/air/building_apps/WS789ea67d3e73a8b22388411123785d839c-8000.html)
安装运行AIRAppWithEmbeddedTomcat.exe, 修改JAVA_HOME，如果默认的路径不对
点击 &#8220;启动&#8221; 可以开启TOMCAT(端口是8080)。在JSP实例和RemoteObject实例中可以看见加载JSP页面和使用RemoteObject获取数据的测试。


控制台
 

JSP 加载测试

RemoteObject 测试

源代码

?View Code ACTIONSCRIPT3&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;!--www.flextheworld.com--&#62;
&#60;mx:WindowedApplication applicationComplete=&#34;init()&#34; xmlns:mx=&#34;http://www.adobe.com/2006/mxml&#34; layout=&#34;vertical&#34; height=&#34;600&#34; width=&#34;800&#34; &#62;
	&#60;mx:Script&#62;
        &#60;!&#91;CDATA&#91;
            [...]]]></description>
			<content:encoded><![CDATA[<p>AIR 2.0 有很多令人期待和振奋的功能，使得AIR向成熟的桌面应用程序开发环境又进了一大步。上一篇文章里介绍了ServerSocket的用法，这篇教程中将向大家介绍NativeProcess，在AIR2.0中我们可以使用程序默认的打开方式直接打开一个外部的应用程序 (<span style="font-family: Monaco, 'Times New Roman', 'Bitstream Charter', Times, serif; line-height: normal; font-size: 11px; ">file.openWithDefaultApplication()<span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: 13px; line-height: 19px; ">) 或者 通过今天要讲的启动进程方式运行一个程序。</span></span></p>
<p>AIR与本地应用程序的交互是AIR 2.0的一个重要更新，这个功能的实现可以帮助我们做到在AIR 1.5时代很难完成的事情，比如我在项目中就需要操作一些硬件，但AIR不能直接操作端口，所以只能借助其他的小程序来实现，现在我们就可以很容易的操作这些小程序以达到操作硬件的目的，而Flex (AIR)与JAVA的结合很早就已经开始了，但由于早期AIR的局限性，想要把JAVA直接部署在客户端还是比较麻烦的事情，但是从AIR2.0开始我们不用担心了。现在我们用很简单的方式就可以在AIR程序中集成TOMCAT, 一次性的将后台与AIR部署到客户端。</p>
<p>程序的原版（Flash Builder 4版）同样是从http://coenraets.org/获得，有兴趣的朋友可以关注这个博客。我的例子仍然使用FLEX 3.</p>
<p style="margin-top: 10px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; background-position: initial initial; padding: 0px; border: 0px initial initial;"><strong>Demo过程</strong></p>
<ol style="margin-top: 5px; margin-right: 0px; margin-bottom: 5px; margin-left: 20px; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; list-style-type: decimal; list-style-position: initial; list-style-image: initial; background-position: initial initial; padding: 0px; border: 0px initial initial;">
<li style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; background-position: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">下载安装 <a style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; color: #000000; background-position: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;" href="http://labs.adobe.com/downloads/air2.html" target="_blank">AIR 2.0 beta runtime</a>.</li>
<li style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; background-position: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">下载AIRAppWithEmbeddedTomcat..exe 或者 AIRAppWithEmbeddedTomcat.dmg (NativeProcess 必须在程序发布为相应平台的应用程序后才可以使用，发布的方法这里就不介绍了，可以参看http://help.adobe.com/en_US/FlashPlatform/develop/air/building_apps/WS789ea67d3e73a8b22388411123785d839c-8000.html)</li>
<li style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; background-position: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">安装运行AIRAppWithEmbeddedTomcat.exe, 修改JAVA_HOME，如果默认的路径不对</li>
<li style="outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 13px; vertical-align: baseline; background-image: initial; background-repeat: initial; background-attachment: initial; -webkit-background-clip: initial; -webkit-background-origin: initial; background-color: transparent; background-position: initial initial; padding: 0px; margin: 0px; border: 0px initial initial;">点击 &#8220;启动&#8221; 可以开启TOMCAT(端口是8080)。在JSP实例和RemoteObject实例中可以看见加载JSP页面和使用RemoteObject获取数据的测试。</li>
</ol>
<p><span id="more-670"></span></p>
<p><strong>控制台</strong></p>
<p><strong> </strong></p>
<p><img class="alignnone size-full wp-image-672" title="a" src="http://www.flextheworld.com/wp-content/uploads/2010/01/a1.gif" alt="a" width="700" height="503" /></p>
<p><strong>JSP 加载测试</strong></p>
<p><strong><img class="alignnone size-full wp-image-673" title="b" src="http://www.flextheworld.com/wp-content/uploads/2010/01/b.gif" alt="b" width="693" height="499" /></strong></p>
<p><strong>RemoteObject 测试</strong></p>
<p><strong><img class="alignnone size-full wp-image-674" title="c" src="http://www.flextheworld.com/wp-content/uploads/2010/01/c.gif" alt="c" width="690" height="499" /></strong></p>
<p><strong>源代码</strong></p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p670code2'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6702"><td class="code" id="p670code2"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;!--</span>www<span style="color: #000066; font-weight: bold;">.</span>flextheworld<span style="color: #000066; font-weight: bold;">.</span>com<span style="color: #000066; font-weight: bold;">--&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication applicationComplete=<span style="color: #990000;">&quot;init()&quot;</span> xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;vertical&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;600&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;800&quot;</span> <span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Alert<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #009900; font-style: italic;">//用于启动和停止Tomcat的进程</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> startTomcatProcess<span style="color: #000066; font-weight: bold;">:</span>NativeProcess<span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> stopTomcatProcess<span style="color: #000066; font-weight: bold;">:</span>NativeProcess<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> tomcatHomeDir<span style="color: #000066; font-weight: bold;">:</span>File<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>NativeProcess<span style="color: #000066; font-weight: bold;">.</span>isSupported<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;不支持进程控制，请先将程序发布为当前操作系统应用程序&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #009900; font-style: italic;">//如果tomcat不存在，重新复制到app store文件夹</span>
                tomcatHomeDir = File<span style="color: #000066; font-weight: bold;">.</span>applicationStorageDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;tomcat&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>tomcatHomeDir<span style="color: #000066; font-weight: bold;">.</span>exists<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> tomcatOriginalDir<span style="color: #000066; font-weight: bold;">:</span>File = File<span style="color: #000066; font-weight: bold;">.</span>applicationDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;tomcat&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #004993;">trace</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Copying tomcat to appStorageDirectory...&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    tomcatOriginalDir<span style="color: #000066; font-weight: bold;">.</span>copyTo<span style="color: #000000;">&#40;</span>tomcatHomeDir<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> f<span style="color: #000066; font-weight: bold;">:</span>File<span style="color: #000066; font-weight: bold;">;</span>
                    f<span style="color: #000066; font-weight: bold;">.</span>openWithDefaultApplication<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
                tomcatHome<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = tomcatHomeDir<span style="color: #000066; font-weight: bold;">.</span>nativePath<span style="color: #000066; font-weight: bold;">;</span>             
&nbsp;
                <span style="color: #009900; font-style: italic;">// 读取保存的配置（第一次运行以后生成）</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> xml<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a> = readConfig<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>xml <span style="color: #000066; font-weight: bold;">!</span>= <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    javaHome<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = xml<span style="color: #000066; font-weight: bold;">.</span>javaHome<span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">return</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #009900; font-style: italic;">// 如果第一次使用，设置默认Path</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=capabilities%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:capabilities.html"><span style="color: #004993;">Capabilities</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">os</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toLowerCase</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;win&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #009900; font-style: italic;">// 默认的JAVA_HOME (windows)</span>
                    javaHome<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;C:<span style="">\\</span>Program Files<span style="">\\</span>Java<span style="">\\</span>jdk1.6.0&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">else</span> <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=capabilities%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:capabilities.html"><span style="color: #004993;">Capabilities</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">os</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toLowerCase</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;mac&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #009900; font-style: italic;">// 默认的JAVA_HOME (Mac)</span>
                    javaHome<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> startTomcat<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #009900; font-style: italic;">// 将本次的JAVA_HOMR写入配置文件</span>
                writeConfig<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #004993;">log</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Starting Tomcat...&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> File<span style="color: #000066; font-weight: bold;">.</span>lineEnding<span style="color: #000066; font-weight: bold;">;</span>
                startTomcatProcess = <span style="color: #0033ff; font-weight: bold;">new</span> NativeProcess<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                execute<span style="color: #000000;">&#40;</span>startTomcatProcess<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;start&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> stopTomcat<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #004993;">log</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> = <span style="color: #990000;">&quot;Stopping Tomcat...&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> File<span style="color: #000066; font-weight: bold;">.</span>lineEnding<span style="color: #000066; font-weight: bold;">;</span>
                stopTomcatProcess = <span style="color: #0033ff; font-weight: bold;">new</span> NativeProcess<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                execute<span style="color: #000000;">&#40;</span>startTomcatProcess<span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;stop&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> execute<span style="color: #000000;">&#40;</span>process<span style="color: #000066; font-weight: bold;">:</span>NativeProcess<span style="color: #000066; font-weight: bold;">,</span> arg<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #009900; font-style: italic;">// 先获取JVM</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> file<span style="color: #000066; font-weight: bold;">:</span>File = <span style="color: #0033ff; font-weight: bold;">new</span> File<span style="color: #000000;">&#40;</span>javaHome<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=capabilities%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:capabilities.html"><span style="color: #004993;">Capabilities</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">os</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">toLowerCase</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;win&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    file = file<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;bin/javaw.exe&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">else</span>
                <span style="color: #000000;">&#123;</span>
                    file = file<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Home/bin/java&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #009900; font-style: italic;">// 启动TOMCAT</span>
                <span style="color: #0033ff; font-weight: bold;">try</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> nativeProcessStartupInfo<span style="color: #000066; font-weight: bold;">:</span>NativeProcessStartupInfo = <span style="color: #0033ff; font-weight: bold;">new</span> NativeProcessStartupInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    nativeProcessStartupInfo<span style="color: #000066; font-weight: bold;">.</span>executable = file<span style="color: #000066; font-weight: bold;">;</span>
                    nativeProcessStartupInfo<span style="color: #000066; font-weight: bold;">.</span>workingDirectory = tomcatHomeDir<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;bin&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> processArgs<span style="color: #000066; font-weight: bold;">:</span>Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>String<span style="color: #000066; font-weight: bold;">&gt;</span> = <span style="color: #0033ff; font-weight: bold;">new</span> Vector<span style="color: #000066; font-weight: bold;">.&lt;</span>String<span style="color: #000066; font-weight: bold;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    processArgs<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;-Dcatalina.home=&quot;</span><span style="color: #000066; font-weight: bold;">+</span>tomcatHomeDir<span style="color: #000066; font-weight: bold;">.</span>nativePath<span style="color: #000066; font-weight: bold;">;</span>
                    processArgs<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;-classpath&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                    processArgs<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">2</span><span style="color: #000000;">&#93;</span> = tomcatHomeDir<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;bin/bootstrap.jar&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>nativePath<span style="color: #000066; font-weight: bold;">;</span>
                    processArgs<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">3</span><span style="color: #000000;">&#93;</span> = <span style="color: #990000;">&quot;org.apache.catalina.startup.Bootstrap&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                    processArgs<span style="color: #000000;">&#91;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000000;">&#93;</span> = arg<span style="color: #000066; font-weight: bold;">;</span>
                    nativeProcessStartupInfo<span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=arguments%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:arguments.html"><span style="color: #004993;">arguments</span></a> = processArgs<span style="color: #000066; font-weight: bold;">;</span>
                    startTomcatProcess = <span style="color: #0033ff; font-weight: bold;">new</span> NativeProcess<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    startTomcatProcess<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">start</span><span style="color: #000000;">&#40;</span>nativeProcessStartupInfo<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    startTomcatProcess<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">.</span>STANDARD_OUTPUT_DATA<span style="color: #000066; font-weight: bold;">,</span>
                        outputDataHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    startTomcatProcess<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">.</span>STANDARD_ERROR_DATA<span style="color: #000066; font-weight: bold;">,</span>
                        errorOutputDataHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=error%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:error.html"><span style="color: #004993;">Error</span></a><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span>e<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;Error&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> outputDataHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> process<span style="color: #000066; font-weight: bold;">:</span>NativeProcess = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">as</span> NativeProcess<span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = process<span style="color: #000066; font-weight: bold;">.</span>standardOutput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readUTFBytes</span><span style="color: #000000;">&#40;</span>process<span style="color: #000066; font-weight: bold;">.</span>standardOutput<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #004993;">log</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">public</span> <span style="color: #339966; font-weight: bold;">function</span> errorOutputDataHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> process<span style="color: #000066; font-weight: bold;">:</span>NativeProcess = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">as</span> NativeProcess<span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = process<span style="color: #000066; font-weight: bold;">.</span>standardError<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readUTFBytes</span><span style="color: #000000;">&#40;</span>startTomcatProcess<span style="color: #000066; font-weight: bold;">.</span>standardError<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #004993;">log</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #004993;">data</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> readConfig<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> file<span style="color: #000066; font-weight: bold;">:</span>File = File<span style="color: #000066; font-weight: bold;">.</span>applicationStorageDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;config.xml&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>file<span style="color: #000066; font-weight: bold;">.</span>exists<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> fileStream<span style="color: #000066; font-weight: bold;">:</span>FileStream = <span style="color: #0033ff; font-weight: bold;">new</span> FileStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    fileStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span>file<span style="color: #000066; font-weight: bold;">,</span> FileMode<span style="color: #000066; font-weight: bold;">.</span>READ<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> xml<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a> = <a href="http://www.google.com/search?q=xml%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:xml.html"><span style="color: #004993;">XML</span></a><span style="color: #000000;">&#40;</span>fileStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readUTFBytes</span><span style="color: #000000;">&#40;</span>fileStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">bytesAvailable</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    fileStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">return</span> xml<span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">else</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #0033ff; font-weight: bold;">null</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> writeConfig<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> xml<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">'&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;'</span> <span style="color: #000066; font-weight: bold;">+</span> File<span style="color: #000066; font-weight: bold;">.</span>lineEnding<span style="color: #000066; font-weight: bold;">;</span>
                xml <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;config&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> File<span style="color: #000066; font-weight: bold;">.</span>lineEnding<span style="color: #000066; font-weight: bold;">;</span>
                xml <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;javaHome&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> javaHome<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;&lt;/javaHome&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> File<span style="color: #000066; font-weight: bold;">.</span>lineEnding<span style="color: #000066; font-weight: bold;">;</span>
                xml <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;tomcatHome&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> tomcatHome<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;&lt;/tomcatHome&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> File<span style="color: #000066; font-weight: bold;">.</span>lineEnding<span style="color: #000066; font-weight: bold;">;</span>
                xml <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;&lt;/config&gt;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> File<span style="color: #000066; font-weight: bold;">.</span>lineEnding<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #6699cc; font-weight: bold;">var</span> file<span style="color: #000066; font-weight: bold;">:</span>File = File<span style="color: #000066; font-weight: bold;">.</span>applicationStorageDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;config.xml&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> fileStream<span style="color: #000066; font-weight: bold;">:</span>FileStream = <span style="color: #0033ff; font-weight: bold;">new</span> FileStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                fileStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span>file<span style="color: #000066; font-weight: bold;">,</span> FileMode<span style="color: #000066; font-weight: bold;">.</span>WRITE<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                fileStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span>xml<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                fileStream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
    <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>RemoteObject id=<span style="color: #990000;">&quot;srv&quot;</span> destination=<span style="color: #990000;">&quot;contacts&quot;</span> endpoint=<span style="color: #990000;">&quot;http://localhost:8080/messagebroker/amf&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>TabNavigator <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>VBox <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> label=<span style="color: #990000;">&quot;控制台&quot;</span> paddingLeft=<span style="color: #990000;">&quot;8&quot;</span> paddingRight=<span style="color: #990000;">&quot;8&quot;</span> paddingBottom=<span style="color: #990000;">&quot;8&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Form <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>FormItem label=<span style="color: #990000;">&quot;Java Home&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
                    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>TextInput id=<span style="color: #990000;">&quot;javaHome&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>FormItem<span style="color: #000066; font-weight: bold;">&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>FormItem label=<span style="color: #990000;">&quot;Tomcat Home (嵌入的TOMCAT)&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
                    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>TextInput id=<span style="color: #990000;">&quot;tomcatHome&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">enabled</span>=<span style="color: #990000;">&quot;false&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>FormItem<span style="color: #000066; font-weight: bold;">&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Form<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>HBox<span style="color: #000066; font-weight: bold;">&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label=<span style="color: #990000;">&quot;启动&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;startTomcat()&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label=<span style="color: #990000;">&quot;停止&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;stopTomcat()&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label=<span style="color: #990000;">&quot;清除信息&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;log.text=''&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
            <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>HBox<span style="color: #000066; font-weight: bold;">&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>TextArea id=<span style="color: #990000;">&quot;log&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>VBox<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>VBox label=<span style="color: #990000;">&quot;嵌入的JSP实例&quot;</span> paddingLeft=<span style="color: #990000;">&quot;8&quot;</span> paddingRight=<span style="color: #990000;">&quot;8&quot;</span> paddingBottom=<span style="color: #990000;">&quot;8&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>HTML id=<span style="color: #990000;">&quot;html&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label=<span style="color: #990000;">&quot;读取JSP&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;html.location='http://localhost:8080'&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>VBox<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
        <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>VBox label=<span style="color: #990000;">&quot;嵌入的RemoteObject实例&quot;</span> paddingLeft=<span style="color: #990000;">&quot;8&quot;</span> paddingRight=<span style="color: #990000;">&quot;8&quot;</span> paddingBottom=<span style="color: #990000;">&quot;8&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>DataGrid <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> dataProvider=<span style="color: #990000;">&quot;{srv.findAll.lastResult}&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>columns<span style="color: #000066; font-weight: bold;">&gt;</span>
                    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>DataGridColumn dataField=<span style="color: #990000;">&quot;id&quot;</span> headerText=<span style="color: #990000;">&quot;Id&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
                    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>DataGridColumn dataField=<span style="color: #990000;">&quot;firstName&quot;</span> headerText=<span style="color: #990000;">&quot;First Name&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
                    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>DataGridColumn dataField=<span style="color: #990000;">&quot;lastName&quot;</span> headerText=<span style="color: #990000;">&quot;Last Name&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
                    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>DataGridColumn dataField=<span style="color: #990000;">&quot;city&quot;</span> headerText=<span style="color: #990000;">&quot;City&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
                <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>columns<span style="color: #000066; font-weight: bold;">&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>DataGrid<span style="color: #000066; font-weight: bold;">&gt;</span>
            <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label=<span style="color: #990000;">&quot;获取数据&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;srv.findAll()&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>VBox<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>TabNavigator<span style="color: #000066; font-weight: bold;">&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p><strong>下载</strong></p>
<p><strong> </strong><br />
源代码: <a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=21" title=" downloaded 221 times" >AIRAppWithEmbeddedTomcat.zip (221)</a></p>
<p>windows demo: <a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=22" title=" downloaded 176 times" >AIRAppWithEmbeddedTomcat.exe (176)</a></p>
<p>Mac Demo: <a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=23" title=" downloaded 120 times" >AIRAppWithEmbeddedTomcat.dmg (120)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2010/01/air-2-tomcat-nativeprocess.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AIR 迷你教程 &#8212; 用AIR 2.0创建迷你Web服务器（ServerSocket 实例）</title>
		<link>http://www.flextheworld.com/2010/01/air-2-serversocket.html</link>
		<comments>http://www.flextheworld.com/2010/01/air-2-serversocket.html#comments</comments>
		<pubDate>Wed, 06 Jan 2010 07:33:34 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[AIR 迷你教程]]></category>
		<category><![CDATA[未分类]]></category>
		<category><![CDATA[AIR 2.0]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=660</guid>
		<description><![CDATA[AIR 2.0 一个非常重要的更新是支持了对Socket的监听，包括TCP (ServerSocket)以及UDP(DatagramSocket)。另外也支持了以UDP方式对外发送信息。这两个功能的增加无疑大大的增加了AIR的应用范围，比如&#8230;&#8230;&#8230;..这一下想个具体的还是比较困难，比如协作型的应用程序。
这篇教程将使用ServerSocket功能做一个HTML服务器，这个不是我原创的，是看到一个老外写的，觉得很有意思，是一个ServerSocket的好例子，原文在 http://coenraets.org/blog/2009/12/air-2-0-web-server-using-the-new-server-socket-api/. 原文是Flash Builder 4 版本的，这里我给大家的是Flex 3版本, 使用源代码请先下载AIR 2.0 SDK
Demo过程

下载安装 AIR 2.0 beta runtime.
下载MiniAIRWebServer.air
安装运行 MiniAIRWebServer.air.
运行 http://localhost:8765/HelloWorld.html （端口以你在运行MiniAIRWebServer.air后输入的为准, 注意安装MiniAIRWebServer.air后安装文件夹下的webroot/HelloWorld.html, 我们运行的就是这个文件）

运行效果如下:

源代码

?View Code ACTIONSCRIPT3&#60;?xml version=&#34;1.0&#34; encoding=&#34;utf-8&#34;?&#62;
&#60;mx:WindowedApplication xmlns:mx=&#34;http://www.adobe.com/2006/mxml&#34; layout=&#34;vertical&#34; close=&#34;closeHandler()&#34; creationComplete=&#34;init()&#34;&#62;
	&#60;mx:Script&#62;
		&#60;!&#91;CDATA&#91;
			import flash.events.Event;
            import flash.events.ProgressEvent;
            [...]]]></description>
			<content:encoded><![CDATA[<p>AIR 2.0 一个非常重要的更新是支持了对Socket的监听，包括TCP (ServerSocket)以及UDP(DatagramSocket)。另外也支持了以UDP方式对外发送信息。这两个功能的增加无疑大大的增加了AIR的应用范围，比如&#8230;&#8230;&#8230;..这一下想个具体的还是比较困难，比如协作型的应用程序。</p>
<p>这篇教程将使用ServerSocket功能做一个HTML服务器，这个不是我原创的，是看到一个老外写的，觉得很有意思，是一个ServerSocket的好例子，原文在 http://coenraets.org/blog/2009/12/air-2-0-web-server-using-the-new-server-socket-api/. 原文是Flash Builder 4 版本的，这里我给大家的是Flex 3版本, 使用源代码请先下载<a href="http://labs.adobe.com/downloads/air2.html" target="_blank">AIR 2.0 SDK</a></p>
<p>Demo过程</p>
<ol>
<li>下载安装 <a href="http://labs.adobe.com/downloads/air2.html" target="_blank">AIR 2.0 beta runtime</a>.</li>
<li>下载MiniAIRWebServer.air</li>
<li>安装运行 MiniAIRWebServer.air.</li>
<li>运行 http://localhost:8765/HelloWorld.html （端口以你在运行MiniAIRWebServer.air后输入的为准, 注意安装MiniAIRWebServer.air后安装文件夹下的webroot/HelloWorld.html, 我们运行的就是这个文件）</li>
</ol>
<p>运行效果如下:</p>
<p><img class="alignnone size-full wp-image-664" title="airserver" src="http://www.flextheworld.com/wp-content/uploads/2010/01/airserver.jpg" alt="airserver" width="341" height="235" /></p>
<p>源代码</p>

<div class="wp_codebox_msgheader wp_codebox_hide"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p660code4'); return false;">View Code</a> ACTIONSCRIPT3</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p6604"><td class="code" id="p660code4"><pre class="actionscript3" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">&lt;?</span>xml <span style="color: #004993;">version</span>=<span style="color: #990000;">&quot;1.0&quot;</span> encoding=<span style="color: #990000;">&quot;utf-8&quot;</span><span style="color: #000066; font-weight: bold;">?&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication xmlns<span style="color: #000066; font-weight: bold;">:</span>mx=<span style="color: #990000;">&quot;http://www.adobe.com/2006/mxml&quot;</span> layout=<span style="color: #990000;">&quot;vertical&quot;</span> <span style="color: #004993;">close</span>=<span style="color: #990000;">&quot;closeHandler()&quot;</span> creationComplete=<span style="color: #990000;">&quot;init()&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
		<span style="color: #000066; font-weight: bold;">&lt;!</span><span style="color: #000000;">&#91;</span>CDATA<span style="color: #000000;">&#91;</span>
			<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.events</span><span style="color: #000066; font-weight: bold;">.</span>ServerSocketConnectEvent<span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span>ServerSocket<span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.net</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=socket%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:socket.html"><span style="color: #004993;">Socket</span></a><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.utils</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">import</span> mx<span style="color: #000066; font-weight: bold;">.</span>controls<span style="color: #000066; font-weight: bold;">.</span>Alert<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
&nbsp;
            <span style="color: #009900; font-style: italic;">//ServerSocket，用于监听TCP下的链接</span>
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> serverSocket<span style="color: #000066; font-weight: bold;">:</span>ServerSocket<span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #6699cc; font-weight: bold;">var</span> mimeTypes<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=object%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:object.html"><span style="color: #004993;">Object</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #009900; font-style: italic;">// 支持的类型</span>
                mimeTypes<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;.css&quot;</span><span style="color: #000000;">&#93;</span>     = <span style="color: #990000;">&quot;text/css&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                mimeTypes<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;.gif&quot;</span><span style="color: #000000;">&#93;</span>     = <span style="color: #990000;">&quot;image/gif&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                mimeTypes<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;.htm&quot;</span><span style="color: #000000;">&#93;</span>     = <span style="color: #990000;">&quot;text/html&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                mimeTypes<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;.html&quot;</span><span style="color: #000000;">&#93;</span>     = <span style="color: #990000;">&quot;text/html&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                mimeTypes<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;.ico&quot;</span><span style="color: #000000;">&#93;</span>     = <span style="color: #990000;">&quot;image/x-icon&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                mimeTypes<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;.jpg&quot;</span><span style="color: #000000;">&#93;</span>     = <span style="color: #990000;">&quot;image/jpeg&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                mimeTypes<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;.js&quot;</span><span style="color: #000000;">&#93;</span>     = <span style="color: #990000;">&quot;application/x-javascript&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                mimeTypes<span style="color: #000000;">&#91;</span><span style="color: #990000;">&quot;.png&quot;</span><span style="color: #000000;">&#93;</span>     = <span style="color: #990000;">&quot;image/png&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
&nbsp;
                <span style="color: #009900; font-style: italic;">// 初始化服务器文件夹</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> webroot<span style="color: #000066; font-weight: bold;">:</span>File = File<span style="color: #000066; font-weight: bold;">.</span>applicationStorageDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;webroot&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000066; font-weight: bold;">!</span>webroot<span style="color: #000066; font-weight: bold;">.</span>exists<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    File<span style="color: #000066; font-weight: bold;">.</span>applicationDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;webroot&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">.</span>copyTo<span style="color: #000000;">&#40;</span>webroot<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> listen<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">try</span>
                <span style="color: #000000;">&#123;</span>
&nbsp;
                    serverSocket = <span style="color: #0033ff; font-weight: bold;">new</span> ServerSocket<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #009900; font-style: italic;">//监听链接</span>
                    serverSocket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=event%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:event.html"><span style="color: #004993;">Event</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">CONNECT</span><span style="color: #000066; font-weight: bold;">,</span> socketConnectHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #009900; font-style: italic;">//绑定端口</span>
                    serverSocket<span style="color: #000066; font-weight: bold;">.</span>bind<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000000;">&#40;</span>port<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #009900; font-style: italic;">//开始</span>
                    serverSocket<span style="color: #000066; font-weight: bold;">.</span>listen<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #004993;">log</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= <span style="color: #990000;">&quot;正在监听 &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> port<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;端口...<span style="">\n</span>&quot;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=error%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:error.html"><span style="color: #004993;">Error</span></a><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;端口 &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> port<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span> 
                        <span style="color: #990000;">&quot; 也许正在被使用，请尝试另一个端口.<span style="">\n</span>(&quot;</span> <span style="color: #000066; font-weight: bold;">+</span>
                        <span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span> <span style="color: #000066; font-weight: bold;">+</span><span style="color: #990000;">&quot;)&quot;</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;错误&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> socketConnectHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span>ServerSocketConnectEvent<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> socket<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=socket%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:socket.html"><span style="color: #004993;">Socket</span></a> = event<span style="color: #000066; font-weight: bold;">.</span>socket<span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #009900; font-style: italic;">//监听数据</span>
                socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">addEventListener</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">SOCKET_DATA</span><span style="color: #000066; font-weight: bold;">,</span> socketDataHandler<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> socketDataHandler<span style="color: #000000;">&#40;</span>event<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=progressevent%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:progressevent.html"><span style="color: #004993;">ProgressEvent</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0033ff; font-weight: bold;">try</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> socket<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=socket%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:socket.html"><span style="color: #004993;">Socket</span></a> = event<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">target</span> <span style="color: #0033ff; font-weight: bold;">as</span> <a href="http://www.google.com/search?q=socket%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:socket.html"><span style="color: #004993;">Socket</span></a><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> bytes<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readBytes</span><span style="color: #000000;">&#40;</span>bytes<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> request<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = <span style="color: #990000;">&quot;&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> bytes<span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #004993;">log</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> <span style="color: #000066; font-weight: bold;">+</span>= request<span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> filePath<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a> = request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">substring</span><span style="color: #000000;">&#40;</span><span style="color: #000000; font-weight:bold;">4</span><span style="color: #000066; font-weight: bold;">,</span> request<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">indexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;HTTP/&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #6699cc; font-weight: bold;">var</span> file<span style="color: #000066; font-weight: bold;">:</span>File = File<span style="color: #000066; font-weight: bold;">.</span>applicationStorageDirectory<span style="color: #000066; font-weight: bold;">.</span>resolvePath<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;webroot&quot;</span> <span style="color: #000066; font-weight: bold;">+</span> filePath<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span>file<span style="color: #000066; font-weight: bold;">.</span>exists <span style="color: #000066; font-weight: bold;">&amp;&amp;</span> <span style="color: #000066; font-weight: bold;">!</span>file<span style="color: #000066; font-weight: bold;">.</span>isDirectory<span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #6699cc; font-weight: bold;">var</span> stream<span style="color: #000066; font-weight: bold;">:</span>FileStream = <span style="color: #0033ff; font-weight: bold;">new</span> FileStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">open</span><span style="color: #000000;">&#40;</span> file<span style="color: #000066; font-weight: bold;">,</span> FileMode<span style="color: #000066; font-weight: bold;">.</span>READ <span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">content</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=bytearray%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:bytearray.html"><span style="color: #004993;">ByteArray</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">readBytes</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">content</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        stream<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;HTTP/1.1 200 OK<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Content-Type: &quot;</span> <span style="color: #000066; font-weight: bold;">+</span> getMimeType<span style="color: #000000;">&#40;</span>filePath<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #990000;">&quot;<span style="">\n</span><span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeBytes</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">content</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    <span style="color: #0033ff; font-weight: bold;">else</span>
                    <span style="color: #000000;">&#123;</span>
                        socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;HTTP/1.1 404 Not Found<span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;Content-Type: text/html<span style="">\n</span><span style="">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                        socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">writeUTFBytes</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;&lt;html&gt;&lt;body&gt;&lt;h2&gt;Page Not Found&lt;/h2&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                    socket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">catch</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=error%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:error.html"><span style="color: #004993;">Error</span></a><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    Alert<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">show</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">error</span><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">message</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #990000;">&quot;错误&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> getMimeType<span style="color: #000000;">&#40;</span>path<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> mimeType<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">index</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=int%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:int.html"><span style="color: #004993;">int</span></a> = path<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">lastIndexOf</span><span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span> <span style="color: #000066; font-weight: bold;">&gt;</span> <span style="color: #000066; font-weight: bold;">-</span><span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    mimeType = mimeTypes<span style="color: #000000;">&#91;</span>path<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">substring</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">index</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0033ff; font-weight: bold;">return</span> mimeType == <span style="color: #0033ff; font-weight: bold;">null</span> <span style="color: #000066; font-weight: bold;">?</span> <span style="color: #990000;">&quot;text/html&quot;</span> <span style="color: #000066; font-weight: bold;">:</span> mimeType<span style="color: #000066; font-weight: bold;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
            <span style="color: #0033ff; font-weight: bold;">private</span> <span style="color: #339966; font-weight: bold;">function</span> closeHandler<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span><span style="color: #000000;">&#123;</span>
            	<span style="color: #0033ff; font-weight: bold;">if</span><span style="color: #000000;">&#40;</span>serverSocket<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
            		serverSocket<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
            	<span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
	<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>Script<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
	<span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>HBox verticalAlign=<span style="color: #990000;">&quot;middle&quot;</span><span style="color: #000066; font-weight: bold;">&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Label <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;Port:&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>TextInput id=<span style="color: #990000;">&quot;port&quot;</span> <span style="color: #004993;">text</span>=<span style="color: #990000;">&quot;8765&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;50&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
        <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>Button label=<span style="color: #990000;">&quot;Listen&quot;</span> <span style="color: #004993;">click</span>=<span style="color: #990000;">&quot;listen()&quot;</span><span style="color: #000066; font-weight: bold;">/&gt;</span>
    <span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>HBox<span style="color: #000066; font-weight: bold;">&gt;</span>
&nbsp;
    <span style="color: #000066; font-weight: bold;">&lt;</span>mx<span style="color: #000066; font-weight: bold;">:</span>TextArea id=<span style="color: #990000;">&quot;log&quot;</span> <span style="color: #004993;">width</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #004993;">height</span>=<span style="color: #990000;">&quot;100%&quot;</span> <span style="color: #000066; font-weight: bold;">/&gt;</span>
<span style="color: #000066; font-weight: bold;">&lt;/</span>mx<span style="color: #000066; font-weight: bold;">:</span>WindowedApplication<span style="color: #000066; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p>下载:</p>
<a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=19" title=" downloaded 310 times" >MIniAIRWebServer.air (310)</a>
<a class="downloadlink" href="http://www.flextheworld.com/wp-content/plugins/download-monitor/download.php?id=20" title=" downloaded 314 times" >MIniAIRWebServer.zip (314)</a>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2010/01/air-2-serversocket.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Adobe AIR 迷你教程 &#8212; 监测网络状态，离线/在线应用程序的实现</title>
		<link>http://www.flextheworld.com/2009/01/adobe-air-web-status.html</link>
		<comments>http://www.flextheworld.com/2009/01/adobe-air-web-status.html#comments</comments>
		<pubDate>Thu, 01 Jan 2009 18:52:50 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[AIR 迷你教程]]></category>
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=74</guid>
		<description><![CDATA[AIR与Flex web应用的另一区别在于可以动态监测网络状态，可以让开发者在网络连通或断线时用不同的方式处理程序，在Demo中我将用以下情况来表现AIR的离线与在线应用。
1. 用户在文本框中输入内容。文本框下方的保存按钮会动态显示当前网络状态: (在线)保存与(离线)保存.
2. 在用户点击保存按钮时如果网络在线，将对话框内容保存在服务器。
3. 如果保存时处于断线状态，将内容保存在本地文件中。
4. 当网络恢复时检查本地文件，如果有已经保存的内容，将内容传入服务器。
源代码很简单，不到100行，大家可以在最下方下载。现在我开始讲解
Demo操作方法
1. 按装运行demo，如果网络连接正常，你会看到文本框下的按钮为 (在线) 保存。
2. 输入任意信息，点击 （在线）保存 。你会看倒信息 “内容已上传服务器”。
3. 切断网络。大概3－5秒后你会看到文本框下方按钮变为（离线）保存。
4. 点击保存，你会看倒信息“内容已经在本地保存，会在下次连线时自动上传到服务器”。
5. 接痛网络,大概3－－5秒后你会看倒信息 “缓存内容已上传服务器”。
6. Demo结束。
1. 启动应用程序后监控网络状态。
我们在 App的CreationComplete()中调用netWorkSyc来监控网络状态。
private function networkSyc():void{
//创建一个联接，使用HEAD表示不需要加载玩全部的页面。
var request:URLRequest = new URLRequest( &#8220;http://www.google.com&#8221;);
request.method = &#8220;HEAD&#8221;;
//用url创建监测对象，每3秒检查一次网络状态，如果网络状态发生变化，将结果返回到netWorkStatusHandle()
urlMonitor = new URLMonitor(request);
urlMonitor.pollInterval = 3000;
urlMonitor.addEventListener(StatusEvent.STATUS,netWorkStatusHandle);
urlMonitor.start();
}
//网络状态改变时响应该事件
private function netWorkStatusHandle(e:StatusEvent):void{
if(urlMonitor.available){
//如果有本地文件，假装上传服务器
if(this.checkLoaclFile()){
//Kevin TODO 上传服务骑
this.showAlert(&#8220;缓存内容已上传服务器&#8221;);
}
saveBtn.label = &#8220;（在线）保存&#8221;
}else{
saveBtn.label = &#8220;（离线）保存&#8221;
}
}
上面的networkSyc()方法中我使用了两个类的对象来实现网络监控，URLRequest 和 URLMonitor。我用URLRequest来建立一个连接对象request，连接的地址是www.google.com。然后已request作为构造参数创建URLMonitor对象。我就是靠它来完成对网络状态的监控。
监控原理很简单，当第一次执行networkSyc()时，urlMonitor会尝试连接www.google.com，然后将连接的结果发回到 netWorkStatusHandle(), 如果连接成功，urlMonitor.available会为true,反之为false。接下来每3秒检查一次网络状态，如果发生改变(连接成功变为连接失败或者连接失败变为连接成功)，那么将再度触发StatusEvent.STATUS事件，调用netWorkStatusHandle()返回网络状态。
以上就是AIR监控网络的方式，大家如果感兴趣想知道更多URLMonitor的内容，可以在Help中搜索ServiceMonitor,它的sub class就是URLMonitor和SockterMonitor。
Demo中并没有真正在本地保存文件，保存与读取文件的方法我会在下一篇教程&#8211;“AIR的文件操作”中教给大家。

源文件下载
Demo
]]></description>
			<content:encoded><![CDATA[<p>AIR与Flex web应用的另一区别在于可以动态监测网络状态，可以让开发者在网络连通或断线时用不同的方式处理程序，在Demo中我将用以下情况来表现AIR的离线与在线应用。</p>
<p>1. 用户在文本框中输入内容。文本框下方的保存按钮会动态显示当前网络状态: (在线)保存与(离线)保存.<br />
2. 在用户点击保存按钮时如果网络在线，将对话框内容保存在服务器。<br />
3. 如果保存时处于断线状态，将内容保存在本地文件中。<br />
4. 当网络恢复时检查本地文件，如果有已经保存的内容，将内容传入服务器。</p>
<p>源代码很简单，不到100行，大家可以在最下方下载。现在我开始讲解</p>
<h2>Demo操作方法</h2>
<p>1. 按装运行demo，如果网络连接正常，你会看到文本框下的按钮为 (在线) 保存。<br />
2. 输入任意信息，点击 （在线）保存 。你会看倒信息 “内容已上传服务器”。<br />
3. 切断网络。大概3－5秒后你会看到文本框下方按钮变为（离线）保存。<br />
4. 点击保存，你会看倒信息“内容已经在本地保存，会在下次连线时自动上传到服务器”。<br />
5. 接痛网络,大概3－－5秒后你会看倒信息 “缓存内容已上传服务器”。<br />
6. Demo结束。<span id="more-74"></span></p>
<h2>1. 启动应用程序后监控网络状态。</h2>
<p>我们在 App的CreationComplete()中调用netWorkSyc来监控网络状态。</p>
<p><span style="color: #2772b9;">private function networkSyc():void{<br />
//创建一个联接，使用HEAD表示不需要加载玩全部的页面。<br />
var request:URLRequest = new URLRequest( &#8220;http://www.google.com&#8221;);<br />
request.method = &#8220;HEAD&#8221;;</p>
<p>//用url创建监测对象，每3秒检查一次网络状态，如果网络状态发生变化，将结果返回到netWorkStatusHandle()<br />
urlMonitor = new URLMonitor(request);<br />
urlMonitor.pollInterval = 3000;<br />
urlMonitor.addEventListener(StatusEvent.STATUS,netWorkStatusHandle);<br />
urlMonitor.start();<br />
}</p>
<p>//网络状态改变时响应该事件<br />
private function netWorkStatusHandle(e:StatusEvent):void{<br />
if(urlMonitor.available){<br />
//如果有本地文件，假装上传服务器<br />
if(this.checkLoaclFile()){<br />
//Kevin TODO 上传服务骑<br />
this.showAlert(&#8220;缓存内容已上传服务器&#8221;);<br />
}<br />
saveBtn.label = &#8220;（在线）保存&#8221;<br />
}else{<br />
saveBtn.label = &#8220;（离线）保存&#8221;<br />
}<br />
}</span></p>
<p>上面的networkSyc()方法中我使用了两个类的对象来实现网络监控，URLRequest 和 URLMonitor。我用URLRequest来建立一个连接对象request，连接的地址是www.google.com。然后已request作为构造参数创建URLMonitor对象。我就是靠它来完成对网络状态的监控。</p>
<p>监控原理很简单，当第一次执行networkSyc()时，urlMonitor会尝试连接www.google.com，然后将连接的结果发回到 netWorkStatusHandle(), 如果连接成功，urlMonitor.available会为true,反之为false。接下来每3秒检查一次网络状态，如果发生改变(连接成功变为连接失败或者连接失败变为连接成功)，那么将再度触发StatusEvent.STATUS事件，调用netWorkStatusHandle()返回网络状态。</p>
<p>以上就是AIR监控网络的方式，大家如果感兴趣想知道更多URLMonitor的内容，可以在Help中搜索ServiceMonitor,它的sub class就是URLMonitor和SockterMonitor。</p>
<p>Demo中并没有真正在本地保存文件，保存与读取文件的方法我会在下一篇教程&#8211;“AIR的文件操作”中教给大家。</p>
<p><img class="aligncenter size-full wp-image-75" title="webstate" src="http://www.flextheworld.com/wp-content/uploads/2009/01/webstate.png" alt="webstate" width="400" height="270" /></p>
<p><a href="http://www.live-share.com/files/365260/AIR_demos.zip.html">源文件下载</a><br />
<a href="http://www.live-share.com/files/365261/NetworkMonitor.air.html">Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/01/adobe-air-web-status.html/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Adobe AIR迷你教程 &#8212; 本地文件(XML文件)的操作（1）</title>
		<link>http://www.flextheworld.com/2009/01/adobe-air-localfile-xml.html</link>
		<comments>http://www.flextheworld.com/2009/01/adobe-air-localfile-xml.html#comments</comments>
		<pubDate>Thu, 01 Jan 2009 18:41:14 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[AIR 迷你教程]]></category>
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=65</guid>
		<description><![CDATA[买了战争机器2，写完教程准备杀到睡觉，现在先做第一步，写教程。AIR的文件操作不难，看完教程应该可以满足你对文件的所有基本操作。这篇教程主要以实际操作中遇到的情况来讲解
我们想想文件操作都会有什么内容，无非是创建，修改，删除，移动，拷贝。在这个过程中我们会涉及到一些周边的操作，比如文件夹，文件选择器，文件列表，文件信息获取等。 我就围绕创建，修改，删除，移动，拷贝来展开我们的教程。因为内容比较多，基于迷你教程每篇都短小，易读的原则。我分为两篇，今天先讲第一篇，基本的操作，下一篇我再加入上面所说周边的操作相对深一步的讲解。
Air的文件操做主要涉及两个类，FIle和FileStream。一般来说我们不会直接以文本形式保存文件，那样的内容不易于修改，所以这里我以xml 文件为例。
Note: 下面所有的function可以直接复制到你的代码中运行
1.创建新文件。
public function createFileDemo():void{
var file:File = File.desktopDirectory.resolvePath(&#8220;test.xml&#8221;) //尝试从系统桌面获取test.xml文件。
var fileStream:FileStream = new FileStream(); // 创建FileStream 对象，用于读写文件
fileStream.open(file,FileMode.WRITE); //以WRITE方式打开file, 如果file中对应的文件不存在，创建新文件
//准备文件的内容
var content:XML =
我们的第一个文件创建完毕
fileStream.writeUTFBytes(content.toXMLString()); //像文件中写入内容。
fileStream.close(); //完成写入，这时我们打开桌面的test.txt可以看到内容。
}
上面五句代码让我在我的桌面创建了名为test.xml的文件，并且写入了content。
这里有三个地方我们要注意
1. File.desktopDirectory &#8212; 因为AIR可以在Mac和Windows下运行，所以我们最好不要指定固定的地址，这里File.desktopDirectory的意思就是指向我系统的桌面，因为我是mac，所以实际返回的是 /kevinluo/Desktop. 除此之外我们还可以得到如下面这些地址
File.documentsDirectory; //指向用户文档文件夹
File.applicationDirectory; //应用程序安装目录
File.getRootDirectories(); //文件系统根目录
等等，我就不一一列举了，具体的大家可以看File帮助中描述。
2.File.desktopDirectory.resolvePath(&#8220;test.xml&#8221;) &#8212; 获取桌面下的test.xml。这里我们还可以这样写
var file:File = File.desktopDirectory
file = file.resolvePath(&#8220;test.xml&#8221;)
不过我建议还是直接写在一排，如果像这样分开写的话，当fileStream.open(file,FileMode.WRITE) 打开文件时，如果文件不存在就会报错而不会像上面那样创建新的文件。
3. fileStream.open(file,FileMode.WRITE) &#8211;FileMode.WRITE是打开文件的方法，打开文件的方法一共有如下四种
FileMode.READ // 只读方式打开文件
FileMode.WRITE // 写方式打开文件，文件的原有内容会被清除。文件不存在的话创建新文件
FileMode.APPEND //追加方式打开文件，写入的内容总是会添加到文件的末尾。文件不存在的话创建新文件
FileMode.UPDATE //直接打开文件，可以根据需要在指定位置插入数据。文件不存在的话创建新文件
这里我们以WRITE方式创建了新文件，并写入了“我们的第一个文件创建完毕”。
2. 读取已有的文件，修改内容，再更新文件。
publuc function modifyFileDemo():void{
var file2:File = File.desktopDirectory.resolvePath(&#8220;test.xml&#8221;); //读取刚才创建的test.xml
var fs:FileStream [...]]]></description>
			<content:encoded><![CDATA[<p>买了战争机器2，写完教程准备杀到睡觉，现在先做第一步，写教程。AIR的文件操作不难，看完教程应该可以满足你对文件的所有基本操作。这篇教程主要以实际操作中遇到的情况来讲解</p>
<p>我们想想文件操作都会有什么内容，无非是创建，修改，删除，移动，拷贝。在这个过程中我们会涉及到一些周边的操作，比如文件夹，文件选择器，文件列表，文件信息获取等。 我就围绕创建，修改，删除，移动，拷贝来展开我们的教程。因为内容比较多，基于迷你教程每篇都短小，易读的原则。我分为两篇，今天先讲第一篇，基本的操作，下一篇我再加入上面所说周边的操作相对深一步的讲解。</p>
<p>Air的文件操做主要涉及两个类，FIle和FileStream。一般来说我们不会直接以文本形式保存文件，那样的内容不易于修改，所以这里我以xml 文件为例。</p>
<p>Note: 下面所有的function可以直接复制到你的代码中运行<span id="more-65"></span></p>
<h2>1.创建新文件。</h2>
<p><span style="color: #2772b9;">public function createFileDemo():void{</span></p>
<p><span style="color: #2772b9;">var file:File = File.desktopDirectory.resolvePath(&#8220;test.xml&#8221;) //尝试从系统桌面获取test.xml文件。<br />
var fileStream:FileStream = new FileStream(); // 创建FileStream 对象，用于读写文件<br />
fileStream.open(file,FileMode.WRITE); //以WRITE方式打开file, 如果file中对应的文件不存在，创建新文件</span></p>
<p><span style="color: #2772b9;">//准备文件的内容<br />
var content:XML =<br />
我们的第一个文件创建完毕</span></p>
<p><span style="color: #2772b9;">fileStream.writeUTFBytes(content.toXMLString()); //像文件中写入内容。<br />
fileStream.close(); //完成写入，这时我们打开桌面的test.txt可以看到内容。</span></p>
<p><span style="color: #2772b9;">}</span></p>
<p>上面五句代码让我在我的桌面创建了名为test.xml的文件，并且写入了content。</p>
<p>这里有三个地方我们要注意</p>
<p>1. File.desktopDirectory &#8212; 因为AIR可以在Mac和Windows下运行，所以我们最好不要指定固定的地址，这里File.desktopDirectory的意思就是指向我系统的桌面，因为我是mac，所以实际返回的是 /kevinluo/Desktop. 除此之外我们还可以得到如下面这些地址</p>
<p><span style="color: #2772b9;">File.documentsDirectory; //指向用户文档文件夹<br />
File.applicationDirectory; //应用程序安装目录<br />
File.getRootDirectories(); //文件系统根目录</span></p>
<p>等等，我就不一一列举了，具体的大家可以看File帮助中描述。</p>
<p>2.File.desktopDirectory.resolvePath(&#8220;test.xml&#8221;) &#8212; 获取桌面下的test.xml。这里我们还可以这样写</p>
<p><span style="color: #2772b9;">var file:File = File.desktopDirectory<br />
file = file.resolvePath(&#8220;test.xml&#8221;)</span></p>
<p>不过我建议还是直接写在一排，如果像这样分开写的话，当fileStream.open(file,FileMode.WRITE) 打开文件时，如果文件不存在就会报错而不会像上面那样创建新的文件。</p>
<p>3. fileStream.open(file,FileMode.WRITE) &#8211;FileMode.WRITE是打开文件的方法，打开文件的方法一共有如下四种</p>
<p><span style="color: #2772b9;">FileMode.READ // 只读方式打开文件<br />
FileMode.WRITE // 写方式打开文件，文件的原有内容会被清除。文件不存在的话创建新文件<br />
FileMode.APPEND //追加方式打开文件，写入的内容总是会添加到文件的末尾。文件不存在的话创建新文件<br />
FileMode.UPDATE //直接打开文件，可以根据需要在指定位置插入数据。文件不存在的话创建新文件</span></p>
<p>这里我们以WRITE方式创建了新文件，并写入了“我们的第一个文件创建完毕”。</p>
<h2>2. 读取已有的文件，修改内容，再更新文件。</h2>
<p><span style="color: #2772b9;">publuc function modifyFileDemo():void{</span></p>
<p>var file2:File = File.desktopDirectory.resolvePath(&#8220;test.xml&#8221;); //读取刚才创建的test.xml<br />
var fs:FileStream = new FileStream();<br />
fs.open(file2,FileMode.READ); //以只读方式打开<br />
var ct:XML = new XML(fs.readUTFBytes(fs.bytesAvailable)); //获取xml内容<br />
ct.content = &#8220;我们的第一个文件修改完毕&#8221; //修改content节点下的内容<br />
fs.open(file2,FileMode.WRITE); //重新以写方式打开文件，目的在于清除原有的内容<br />
fs.writeUTFBytes(ct.toXMLString()) //写入修改过后的XML<br />
fs.close()</p>
<p>}</p>
<p>这里我用了READ和WRITE的组合。在实际的使用中我们可以判断一个xml文件的大小来限制单个文件写入过大。</p>
<h2>3.删除文件。</h2>
<p>删除文件是最简单的。</p>
<p>public function deleteFIleDemo():void{</p>
<p><span style="color: #2772b9;">var file2:File = File.desktopDirectory.resolvePath(&#8220;test.xml&#8221;);<br />
if(file2.exists){ //判断文件是否存在<br />
file2.deleteFile() //删除文件<br />
}</span></p>
<p>}</p>
<p>如果使用file2.moveToTrash()则将文件移到垃圾箱</p>
<h2>4.拷贝文件/移动文件</h2>
<p><span style="color: #2772b9;">public function copyFileDemo():void{</span></p>
<p>var sourceFile:File = File.desktopDirectory.resolvePath(&#8220;test.xml&#8221;) //获取源文件<br />
var newFile:File = File.desktopDirectory.resolvePath(&#8220;test2.xml&#8221;) //创建目标文件<br />
sourceFile.copyTo(newFile,true) //执行拷贝，如果是移动的话sourceFile.moveTo(newFile,true)</p>
<p>}</p>
<h2>5. 异步与同步</h2>
<p>AIR对文件的操作分为异步与同步两种方式。上面1&#8211;4介绍的是同步方式，其中的一些方法有另一个异步方式，看下面的列表</p>
<p><span style="color: #2772b9;">File.copyTo() &#8212; File.copyToAsync()<br />
File.moveTo() &#8212; File.moveToAsync()<br />
File.deleteDirectory() &#8212; File.deleteDirectoryAsync()<br />
File.deleteFile() &#8212; File.deleteFileAsync()<br />
File.getDirectoryListing() &#8211; File.getDirectoryListingAsync()<br />
File.moveToTrash() &#8212; File.moveToTrashAsync()</span></p>
<p>FileStream.open &#8212; FileStream.openAsync()</p>
<p>使用异步方式时我们需要监听EVENT.COMPLETE和IOErrorEvent.IO_ERROR事件来获取file的操作结果。我拿上面的拷贝做个例子</p>
<p>pirvate funnction copyFile(sourceFIlePath:String, targetFIlePath:String):void{</p>
<p>var sourceFile:File = File.desktopDirectory.resolvePath(sourceFIlePath) //获取源文件<br />
var newFile:File = File.desktopDirectory.resolvePath(targetFIlePath) //创建目标文件<br />
sourceFile.addEventListener(Event.COMPLETE,completeHandle) //监听文件操作complete事件<br />
sourceFile.copyToAsync(newFile,true) ; //开始拷贝，异步方式<br />
this. showLoadingBar() //打开loading图标</p>
<p>}</p>
<p>private function completeHandle():void{</p>
<p>Alert.show(&#8220;拷贝文件完成&#8221;)<br />
this.closeLoadingBar() //关闭loading图标</p>
<p>}</p>
<p>异步方式的好处是我们可以从中实行一些别的操作，比如出现一个loading的提示之类。</p>
<p>OK, 休息了</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/01/adobe-air-localfile-xml.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adobe AIR迷你教程 &#8212; 创建多窗口以及弹出窗口与父窗口的通讯</title>
		<link>http://www.flextheworld.com/2009/01/adobe-air-multi-windows.html</link>
		<comments>http://www.flextheworld.com/2009/01/adobe-air-multi-windows.html#comments</comments>
		<pubDate>Thu, 01 Jan 2009 18:37:35 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[AIR 迷你教程]]></category>
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=62</guid>
		<description><![CDATA[今天说一下AIR中的window, 作为桌面应用，免不了会有多窗口存在的可能。所以这也是AIR于Flex web的另一区别。flex web应用的“窗口”都是内部窗口，不管你怎么拖拽它也不会超出flash player的范围。而我们今天说的air中的窗口，是没有范围限制的，任一窗口都可以说是一个“独立”的存在，不受主程序窗口的限制。
Demo主要有以下功能
1. 简单继承window类创建MyWindow。加入parentWindow属性以及advOpen()方法, 设置MyWindow默认样式。
2. 从主程序中弹出窗口1，从窗口1中弹出窗口2。每个窗口里有image和button
3. 窗口1可以关闭主程序窗口，窗口2可以关闭窗口1。（关闭父窗口）
1. 简单继承window类创建MyWindow。加入parentWindow属性以及advOpen()方法, 设置MyWindow默认样式。
下面是我继承于WIndow的MyWindow，构造方法中设置了默认样式，parentWindow用于在打开窗口时保存父窗口对象。
public class MyWindow extends Window
{
public var parentWindow:Object;
public function MyWindow()
{
this.systemChrome = &#8220;none&#8221;; //不显示系统窗口
this.showStatusBar = false; //不显示底部状态栏
this.showGripper = false; //不显示底部大小控制按钮
}
/**
* 自定义open()打开窗口并且保存调用此方法的对象
*/
public function advOpen(parentWindow:Object,openWindowActive:Boolean = true):void{
this.parentWindow = parentWindow;
this.open(true)
}
}
2. 从主程序中弹出窗口1，从窗口1中弹出窗口2。每个窗口里有image和button
3. 窗口1可以关闭主程序窗口，窗口2可以关闭窗口1。（关闭父窗口）
下面是窗口1类，继承于MyWindow。在主程序中用了与下面相同的openWin打开窗口1，可以看倒在调用winX.advOpen时传入了当前对象作为被打开窗口的parentWindow. 下面的closeParent()中利用保存的 parentWindow关闭父窗口。
&#60;local:MyWindow xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221; width=&#8221;435&#8243; height=&#8221;320&#8243; xmlns:local=&#8221;*&#8221;&#62;
&#60;mx:Script&#62;
&#60;![CDATA[
import mx.core.Window;
//打开窗口2
private function openWin():void{
var win2:PicTwo = new PicTwo();
win2.advOpen(this);
win2.move(500,50)
}
//关闭父窗口
private function closeParent():void{
if(this.parentWindow.hasOwnProperty("close")){ //检查父窗口中是否有close方法。
this.parentWindow.close(); //调用父窗口的close方法
}
}
]]&#62;
&#60;/mx:Script&#62;
&#60;mx:Canvas&#62;
&#60;mx:Image [...]]]></description>
			<content:encoded><![CDATA[<p>今天说一下AIR中的window, 作为桌面应用，免不了会有多窗口存在的可能。所以这也是AIR于Flex web的另一区别。flex web应用的“窗口”都是内部窗口，不管你怎么拖拽它也不会超出flash player的范围。而我们今天说的air中的窗口，是没有范围限制的，任一窗口都可以说是一个“独立”的存在，不受主程序窗口的限制。</p>
<h2>Demo主要有以下功能</h2>
<p>1. 简单继承window类创建MyWindow。加入parentWindow属性以及advOpen()方法, 设置MyWindow默认样式。<br />
2. 从主程序中弹出窗口1，从窗口1中弹出窗口2。每个窗口里有image和button<br />
3. 窗口1可以关闭主程序窗口，窗口2可以关闭窗口1。（关闭父窗口）<span id="more-62"></span></p>
<h2>1. 简单继承window类创建MyWindow。加入parentWindow属性以及advOpen()方法, 设置MyWindow默认样式。</h2>
<p>下面是我继承于WIndow的MyWindow，构造方法中设置了默认样式，parentWindow用于在打开窗口时保存父窗口对象。</p>
<p><span style="color: #2772b9;">public class MyWindow extends Window<br />
{<br />
public var parentWindow:Object;</p>
<p>public function MyWindow()<br />
{<br />
this.systemChrome = &#8220;none&#8221;; //不显示系统窗口<br />
this.showStatusBar = false; //不显示底部状态栏<br />
this.showGripper = false; //不显示底部大小控制按钮<br />
}</p>
<p>/**<br />
* 自定义open()打开窗口并且保存调用此方法的对象<br />
*/<br />
public function advOpen(parentWindow:Object,openWindowActive:Boolean = true):void{<br />
this.parentWindow = parentWindow;<br />
this.open(true)<br />
}</p>
<p>}</span></p>
<h2>2. 从主程序中弹出窗口1，从窗口1中弹出窗口2。每个窗口里有image和button</h2>
<h2>3. 窗口1可以关闭主程序窗口，窗口2可以关闭窗口1。（关闭父窗口）</h2>
<p>下面是窗口1类，继承于MyWindow。在主程序中用了与下面相同的openWin打开窗口1，可以看倒在调用winX.advOpen时传入了当前对象作为被打开窗口的parentWindow. 下面的closeParent()中利用保存的 parentWindow关闭父窗口。</p>
<p><span style="color: #2772b9;">&lt;local:MyWindow xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; layout=&#8221;absolute&#8221; width=&#8221;435&#8243; height=&#8221;320&#8243; xmlns:local=&#8221;*&#8221;&gt;<br />
&lt;mx:Script&gt;<br />
&lt;![CDATA[<br />
import mx.core.Window;</p>
<p>//打开窗口2<br />
private function openWin():void{<br />
var win2:PicTwo = new PicTwo();<br />
win2.advOpen(this);<br />
win2.move(500,50)<br />
}</p>
<p>//关闭父窗口<br />
private function closeParent():void{<br />
if(this.parentWindow.hasOwnProperty("close")){ //检查父窗口中是否有close方法。<br />
this.parentWindow.close(); //调用父窗口的close方法<br />
}<br />
}<br />
]]&gt;<br />
&lt;/mx:Script&gt;<br />
&lt;mx:Canvas&gt;<br />
&lt;mx:Image source=&#8221;@Embed(&#8216;images/2.png&#8217;)&#8221; /&gt;<br />
&lt;mx:Button label=&#8221;打开我的表情2&#8243; click=&#8221;openWin()&#8221; x=&#8221;325&#8243; y=&#8221;174&#8243;/&gt;<br />
&lt;mx:Button label=&#8221;关闭父窗口&#8221; click=&#8221;closeParent()&#8221; x=&#8221;342&#8243; y=&#8221;204&#8243;/&gt;<br />
&lt;/mx:Canvas&gt;<br />
&lt;/local:MyWindow&gt;</span></p>
<p>主程序</p>
<p><span style="color: #2772b9;">&lt;mx:WindowedApplication showStatusBar=&#8221;false&#8221; showGripper=&#8221;false&#8221; xmlns:mx=&#8221;http://www.adobe.com/2006/mxml&#8221; width=&#8221;430&#8243; height=&#8221;328&#8243; layout=&#8221;absolute&#8221;&gt;<br />
&lt;mx:Script&gt;<br />
&lt;![CDATA[<br />
import mx.core.Window;<br />
private function openWin():void{<br />
//新建window对象<br />
var win:PicOne = new PicOne();<br />
win.advOpen(this); //弹出窗口<br />
win.move(50,50);</p>
<p>}<br />
]]&gt;<br />
&lt;/mx:Script&gt;<br />
&lt;mx:Canvas&gt;<br />
&lt;mx:Image source=&#8221;@Embed(&#8216;images/1.png&#8217;)&#8221; /&gt;<br />
&lt;mx:Button label=&#8221;打开我的表情1&#8243; click=&#8221;openWin()&#8221; x=&#8221;325&#8243; y=&#8221;174&#8243;/&gt;<br />
&lt;/mx:Canvas&gt;</p>
<p>&lt;/mx:WindowedApplication&gt;</span></p>
<p><img class="aligncenter size-full wp-image-63" title="popupwindow" src="http://www.flextheworld.com/wp-content/uploads/2009/01/popupwindow.png" alt="popupwindow" width="400" height="282" /></p>
<p><a href="http://www.live-share.com/files/366603/AIRPopupWindowDemo.zip.html">源文件下载</a><br />
<a href="http://www.live-share.com/files/366604/AIRPopupWindowDemo.air.html">Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/01/adobe-air-multi-windows.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adobe AIR迷你教程 &#8212; 使用自定义窗口以及对窗口的移动，缩放，关闭操作</title>
		<link>http://www.flextheworld.com/2009/01/adobe-air-custom-window.html</link>
		<comments>http://www.flextheworld.com/2009/01/adobe-air-custom-window.html#comments</comments>
		<pubDate>Thu, 01 Jan 2009 18:34:11 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[AIR 迷你教程]]></category>
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=58</guid>
		<description><![CDATA[这个教程主要针对对flex有一定基础，准备开始AIR开发的朋友。由于AIR是针对桌面应用程序，所以相对于flex的web应用，自然就多出了对应用程序窗口的控制。而 AIR的一大特点就是允许开发者使用自定义的窗口代替系统窗口从而使开发者对程序UI的设计更加随心所欲，设计出独具个性风格的跨平台的桌面应用程序。
罗嗦的话到次为止，下面正式开始主题，本教程主要实现了以下功能。
1. 屏蔽系统窗口、 flash窗口、窗口底部状态栏。使用自定义窗口。
2. 对自定义窗口的缩放、移动、关闭。
在实现以上操作的过程中，我加入了一些额外的操作来丰富我们的demo，都是很简单，很实用的东西。
3. 移动窗口时实现半透明效果，移动结束时还原。
4. 关闭窗口动画。
5. 窗口背景填充。
1. 屏蔽系统窗口， flash窗口，窗口底部状态栏。使用自定义窗口。
当一个AIR项目创建成功后，你会发现相对与 web项目，你的工程目录下多了一个名为 XXX-app.xml的文件，这是我们项目的配制文件，实现自定义窗口就是靠它。打开它，修改如下代码:
&#60;!&#8211; The type of system chrome to use (either &#8220;standard&#8221; or &#8220;none&#8221;). Optional. Default standard. &#8211;&#62;
&#60;!&#8211;&#60;systemChrome&#62;&#60;/systemChrome&#62; &#8211;&#62;
去掉对systemChrome的注释，改为
&#60;!&#8211; The type of system chrome to use (either &#8220;standard&#8221; or &#8220;none&#8221;). Optional. Default standard. &#8211;&#62;
&#60;systemChrome&#62;none&#60;/systemChrome&#62;
这样我们就去掉了系统窗口，转而使用了flash的自带窗口，下面我们把flash窗口也去掉。在你的主mxml文件中设置WindowedApplication 的这些属性
&#60;mx:WindowedApplication showTitleBar=&#8221;false&#8221; borderThickness=&#8221;0&#8243; showStatusBar=&#8221;false&#8221; showGripper=&#8221;false&#8221; &#8230;.. /&#62;
这样就完全去掉了所有的窗口，程序运行后只显现应用程序的内容。大家可以参考帮助手册来了解以上属性的意思。说到这里就引出了下一个问题，屏蔽了所有窗口以后如何对窗口进行基本的，放大，缩放，关闭操作呢。我们看下面。
2. 对自定义窗口的缩放，移动，关闭。
AIR比flex web应用多了一个类叫NativeWindow,我们就是靠这个类对窗口就行操作。在demo中，我用了以下几个方法来移定窗口，他们都在鼠标MouseDown event中被触发。
this.nativeWindow.startResize(&#8220;L&#8221;);
this.nativeWindow.startResize(&#8220;R&#8221;);
this.nativeWindow.startResize(&#8220;T&#8221;);
this.nativeWindow.startResize(&#8220;B&#8221;);
this.nativeWindow.startResize(&#8220;TL&#8221;);
this.nativeWindow.startResize(&#8220;RB&#8221;);
很容易可以看出，L R B [...]]]></description>
			<content:encoded><![CDATA[<p>这个教程主要针对对flex有一定基础，准备开始AIR开发的朋友。由于AIR是针对桌面应用程序，所以相对于flex的web应用，自然就多出了对应用程序窗口的控制。而 AIR的一大特点就是允许开发者使用自定义的窗口代替系统窗口从而使开发者对程序UI的设计更加随心所欲，设计出独具个性风格的跨平台的桌面应用程序。</p>
<p>罗嗦的话到次为止，下面正式开始主题，本教程主要实现了以下功能。</p>
<p>1. 屏蔽系统窗口、 flash窗口、窗口底部状态栏。使用自定义窗口。<br />
2. 对自定义窗口的缩放、移动、关闭。<span id="more-58"></span></p>
<p>在实现以上操作的过程中，我加入了一些额外的操作来丰富我们的demo，都是很简单，很实用的东西。</p>
<p>3. 移动窗口时实现半透明效果，移动结束时还原。<br />
4. 关闭窗口动画。<br />
5. 窗口背景填充。</p>
<h2>1. 屏蔽系统窗口， flash窗口，窗口底部状态栏。使用自定义窗口。</h2>
<p>当一个AIR项目创建成功后，你会发现相对与 web项目，你的工程目录下多了一个名为 XXX-app.xml的文件，这是我们项目的配制文件，实现自定义窗口就是靠它。打开它，修改如下代码:</p>
<p><span style="color: #2772b9;">&lt;!&#8211; The type of system chrome to use (either &#8220;standard&#8221; or &#8220;none&#8221;). Optional. Default standard. &#8211;&gt;<br />
&lt;!&#8211;&lt;systemChrome&gt;&lt;/systemChrome&gt; &#8211;&gt;</span></p>
<p>去掉对systemChrome的注释，改为</p>
<p><span style="color: #2772b9;">&lt;!&#8211; The type of system chrome to use (either &#8220;standard&#8221; or &#8220;none&#8221;). Optional. Default standard. &#8211;&gt;<br />
&lt;systemChrome&gt;none&lt;/systemChrome&gt;</span></p>
<p>这样我们就去掉了系统窗口，转而使用了flash的自带窗口，下面我们把flash窗口也去掉。在你的主mxml文件中设置WindowedApplication 的这些属性</p>
<p><span style="color: #2772b9;">&lt;mx:WindowedApplication showTitleBar=&#8221;false&#8221; borderThickness=&#8221;0&#8243; showStatusBar=&#8221;false&#8221; showGripper=&#8221;false&#8221; &#8230;.. /&gt;</span></p>
<p>这样就完全去掉了所有的窗口，程序运行后只显现应用程序的内容。大家可以参考帮助手册来了解以上属性的意思。说到这里就引出了下一个问题，屏蔽了所有窗口以后如何对窗口进行基本的，放大，缩放，关闭操作呢。我们看下面。</p>
<h2>2. 对自定义窗口的缩放，移动，关闭。</h2>
<p>AIR比flex web应用多了一个类叫NativeWindow,我们就是靠这个类对窗口就行操作。在demo中，我用了以下几个方法来移定窗口，他们都在鼠标MouseDown event中被触发。</p>
<p><span style="color: #2772b9;">this.nativeWindow.startResize(&#8220;L&#8221;);<br />
this.nativeWindow.startResize(&#8220;R&#8221;);<br />
this.nativeWindow.startResize(&#8220;T&#8221;);<br />
this.nativeWindow.startResize(&#8220;B&#8221;);<br />
this.nativeWindow.startResize(&#8220;TL&#8221;);<br />
this.nativeWindow.startResize(&#8220;RB&#8221;);</span></p>
<p>很容易可以看出，L R B T代表 Left, Right, Bottom 和 Top, 所以在调用startResize时设置适当的参数我们就可以轻易的实现对窗口各个方向的缩放。对于窗口的移定，在mouseDown event中使用</p>
<p><span style="color: #2772b9;">this.nativeWindow.startMove();</span></p>
<p>而对窗口的关闭，则很简单的在按钮click事件调用this.close()。</p>
<p>好了，以上就是对自定义窗口的操作。下面的东西我是用来完善我的demo，使它cool一点。相信大家在自己的应用程序中也会需要类似的东西，一个应用程序除了功能，细节上的处理也是很重要的。</p>
<h3>3. 移动窗口时实现半透明效果，移动结束时还原。</h3>
<p>要实现这个效果我们需要重新打开我们的XXX-app.xml文件，设置以下内容。<br />
<span style="color: #2772b9;"><br />
&lt;!&#8211; Whether the window is transparent. Only applicable when systemChrome is none. Optional. Default false. &#8211;&gt;<br />
&lt;transparent&gt;true&lt;/transparent&gt;<br />
</span><br />
这个可以允许我们让应用程序的背景透明，这个很有用，比方说QQ宠物就是一个背景透明的应用程序，利用背景透明，我们可以开发出很独特的应用程序。接下来要做的就简单了。</p>
<p>在上面移动窗口的mouseDown事件中加入 this.alpha = 0.x; 下面是demo中的代码。我将透明度设为0.6,this. alpha只针对应用程序的背景设置透明，如果你想让更多的东西透明，只需要对相应的控件设置alpha既可。</p>
<p><span style="color: #2772b9;">private function moveMe():void{<br />
this.nativeWindow.startMove();<br />
this.alpha = 0.6;<br />
}</span></p>
<p>让透明还原我在mouseUp事件中设置alpha =1;</p>
<p>private function mouseUpHandle():void{<br />
this.alpha = 1;<br />
}</p>
<p>这样简单的设置也许就会使你的应用程序看起来不一样，怎么不试试呢：）</p>
<h2>4. 关闭窗口动画。</h2>
<p>我使用了下面的Iris效果对在窗口关闭时使用。有什么效果呢，大家关闭一下就知道了。 flex中内置了很多效果给我们使用，很多时候我们只需要适当的组合，就能得到意想不到的效果，比如 Move与 WipeDown一起可以实现Mac系统，菜单向下滑出的效果。诸如此类，只要有想像力，我们可以用很简单的代码，实现很有用的功能。 在demo 中，如下设置得到关闭动画</p>
<p><span style="color: #2772b9;">&lt;mx:WindowedApplication closeEffect=&#8221;irisIn&#8221; &#8230;.. /&gt;</span></p>
<p>&lt;mx:Iris id=&#8221;irisIn&#8221; duration=&#8221;500&#8243; showTarget=&#8221;false&#8221; /&gt;</p>
<h2>5. 窗口背景填充。</h2>
<p>这个功能其实在开发程序的时候用的不多，我是不想让demo看起来太单调所以加了背景，我们知道flex是不能像Html那样轻易的让背景重复显示的，所以我们的用一些特殊方法处理以下，demo中的 setBackground方法用于设置整个背景。这里面涉及到的 Bitmap, BitmapData, Graphics类的具体作用，大家感兴趣的话可以看帮助手册，我的观点是当里用到的时候查帮助也不迟，只要知道有这么些个类可以为你干什么活就好。</p>
<p><span style="color: #2772b9;">private function setBackground():void{</span></p>
<p>var backgroundImage :Bitmap;<br />
var backgroundBitmapData :BitmapData;</p>
<p>backgroundImage = new bg();<br />
backgroundBitmapData = new BitmapData( backgroundImage.width, backgroundImage.height );<br />
backgroundBitmapData.draw( backgroundImage );</p>
<p>workarea.graphics.beginBitmapFill( backgroundBitmapData, null,true );<br />
workarea.graphics.drawRect(0,0, 2000, 2000);<br />
workarea.graphics.endFill();<br />
}</p>
<p>以上就是demo的全部内容，下面有源文件和Demo给大家下载。 因为AIR是跨平台的应用程序，所以不管在Mac或者Window上开发过程都是一样的。Demo是在 Leopard下开发。</p>
<p><img class="aligncenter size-full wp-image-59" title="airwindow" src="http://www.flextheworld.com/wp-content/uploads/2009/01/airwindow.png" alt="airwindow" width="400" height="344" /></p>
<p><a href="http://www.live-share.com/files/363500/AIRWindow_demo.zip.html">源文件下载</a><br />
<a href="http://www.live-share.com/files/363502/AIRWindowDemo.air.html">Demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/01/adobe-air-custom-window.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adobe AIR迷你教程 &#8212; 在Flex builder3 中创建、发布AIR程序以及 AIR程序的安装运行</title>
		<link>http://www.flextheworld.com/2009/01/adobe-air-create-air.html</link>
		<comments>http://www.flextheworld.com/2009/01/adobe-air-create-air.html#comments</comments>
		<pubDate>Thu, 01 Jan 2009 18:25:32 +0000</pubDate>
		<dc:creator>Kevin Luo</dc:creator>
				<category><![CDATA[AIR 迷你教程]]></category>
		<category><![CDATA[AIR]]></category>

		<guid isPermaLink="false">http://www.flextheworld.com/?p=54</guid>
		<description><![CDATA[这篇教程算是AIR的 Hello world，写给那些知道一点AIR，想要开始AIR开发的人。读这篇教程你可以没有任何Flex的基础，我会告诉你如何创建你的第一个项目，并且发布一个HelloWorld程序。
下面我们开始讲解以下的内容。
1. 准备工作。
2. 第一个 AIR程序（编写、运行、调试）
3. 发布AIR程序。
4. 安装已发布的AIR安装包。
1.准备工作。
AIR 的开发环境非常简单，你唯一需要的就是FlexBuilder3,下载地址我就不提供了，只需要在google中搜索&#8221;Flex builder3 下载&#8221;，你会得到一大把地址。 Flexbuilder的安装也很简单，直接运行安装程序，然后一路按照导航菜单下去既可。
2. 第一个 AIR程序（编写、运行、调试）（图片点击可以放大）
现在我们打开刚安装好的FlexBuilder3,见下图,选择 打开File &#8212; New &#8212; Flex project.

接 下来是输入程序名，我写的是My first air app, 在Applicaiton Type那选择Desktop application(runs in Adobe AIR),接这直接点Finish,项目将创建在安装FlexBuilder时设置的work space里，这个文件夹没什么特别（你以后可以把你的项目放在任意的文件夹中，使用File &#8212; Import &#8212; Flex project导入）

现 在你可以在左侧的导航中看见你的项目My first air app。你可以看倒项目主程序main.mxml和配制文件main-app.xml（在AIR迷你教程&#8211;使用自定义窗口&#8230;,中我们有用到这个文 件，现在不需要管他）。右边的主窗口区域就是已经打开的main.mxml的内容。

按 照下图的内容写我们的第一个air程序，也可以算我们第一个flex程序(Flex和AIR开发完全一样，只是在 AIR中多了一些包的支持使我们的程序成为桌面程序)。程序中有一个按钮，点击触发click事件，接着trace(trace是flex中用来在控制面 版输出信息的命令，在Debug模式中我们经常会使用它来帮助我们调试程序)出 event 的内容，并且执行弹出窗口现在一段文字。

下面我们运行程序，按照下图，右键点击main.mxml &#8212; Run As &#8212; Adobe AIR Application.

运行后我们点击按钮，完成我们整个demo的内容。

好，现在我们已经结束从编写到运行的过程。下面我们来调试(Debug)。如图，我们在第9行代码左边蓝色小点的位置，左键单击，这样你应该可以看倒和图上一样的蓝色小点了，这就是我们设置的程序断点，在调试模式中，程序会在这样的位置停下来。

我们开始调试，右键点击main.mxml &#8212; Debug [...]]]></description>
			<content:encoded><![CDATA[<p>这篇教程算是AIR的 Hello world，写给那些知道一点AIR，想要开始AIR开发的人。读这篇教程你可以没有任何Flex的基础，我会告诉你如何创建你的第一个项目，并且发布一个HelloWorld程序。</p>
<p>下面我们开始讲解以下的内容。</p>
<p>1. 准备工作。<br />
2. 第一个 AIR程序（编写、运行、调试）<br />
3. 发布AIR程序。<br />
4. 安装已发布的AIR安装包。</p>
<p><span style="font-size: large;"><strong>1.准备工作。</strong></span></p>
<p>AIR 的开发环境非常简单，你唯一需要的就是FlexBuilder3,下载地址我就不提供了，只需要在google中搜索&#8221;Flex builder3 下载&#8221;，你会得到一大把地址。 Flexbuilder的安装也很简单，直接运行安装程序，然后一路按照导航菜单下去既可。<span id="more-54"></span></p>
<p><strong><span style="font-size: large;">2. 第一个 AIR程序（编写、运行、调试）（图片点击可以放大）</span></strong></p>
<p>现在我们打开刚安装好的FlexBuilder3,见下图,选择 打开File &#8212; New &#8212; Flex project.</p>
<p><a href="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGnsZo27AI/AAAAAAAAACM/M7bgRllbu-k/s1600-h/1" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGnsZo27AI/AAAAAAAAACM/M7bgRllbu-k/s400/1" alt="" width="398" height="233" /></a></p>
<p>接 下来是输入程序名，我写的是My first air app, 在Applicaiton Type那选择Desktop application(runs in Adobe AIR),接这直接点Finish,项目将创建在安装FlexBuilder时设置的work space里，这个文件夹没什么特别（你以后可以把你的项目放在任意的文件夹中，使用File &#8212; Import &#8212; Flex project导入）</p>
<p><a href="http://2.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVNiakGI/AAAAAAAAACU/QNUFTo4l-aU/s1600-h/2.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://2.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVNiakGI/AAAAAAAAACU/QNUFTo4l-aU/s400/2.jpg" alt="" width="398" height="200" /></a></p>
<p>现 在你可以在左侧的导航中看见你的项目My first air app。你可以看倒项目主程序main.mxml和配制文件main-app.xml（在AIR迷你教程&#8211;使用自定义窗口&#8230;,中我们有用到这个文 件，现在不需要管他）。右边的主窗口区域就是已经打开的main.mxml的内容。</p>
<p><a href="http://2.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVD7KdtI/AAAAAAAAACc/dJPVOD02MTQ/s1600-h/3.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://2.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVD7KdtI/AAAAAAAAACc/dJPVOD02MTQ/s400/3.jpg" alt="" width="398" height="233" /></a></p>
<p>按 照下图的内容写我们的第一个air程序，也可以算我们第一个flex程序(Flex和AIR开发完全一样，只是在 AIR中多了一些包的支持使我们的程序成为桌面程序)。程序中有一个按钮，点击触发click事件，接着trace(trace是flex中用来在控制面 版输出信息的命令，在Debug模式中我们经常会使用它来帮助我们调试程序)出 event 的内容，并且执行弹出窗口现在一段文字。</p>
<p><a href="http://4.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVTLfJGI/AAAAAAAAACk/g5Q0-rIWqMk/s1600-h/4.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://4.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVTLfJGI/AAAAAAAAACk/g5Q0-rIWqMk/s400/4.jpg" alt="" width="398" height="167" /></a></p>
<p>下面我们运行程序，按照下图，右键点击main.mxml &#8212; Run As &#8212; Adobe AIR Application.</p>
<p><a href="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVbg2GFI/AAAAAAAAACs/f3rKOv4k7Mk/s1600-h/5.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVbg2GFI/AAAAAAAAACs/f3rKOv4k7Mk/s400/5.jpg" alt="" width="398" height="223" /></a></p>
<p>运行后我们点击按钮，完成我们整个demo的内容。</p>
<p><a href="http://4.bp.blogspot.com/_ewlmUWn6UWQ/SRGoV2KhvZI/AAAAAAAAAC0/ycYfCnVa8xs/s1600-h/6.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://4.bp.blogspot.com/_ewlmUWn6UWQ/SRGoV2KhvZI/AAAAAAAAAC0/ycYfCnVa8xs/s400/6.jpg" alt="" width="398" height="173" /></a></p>
<p>好，现在我们已经结束从编写到运行的过程。下面我们来调试(Debug)。如图，我们在第9行代码左边蓝色小点的位置，左键单击，这样你应该可以看倒和图上一样的蓝色小点了，这就是我们设置的程序断点，在调试模式中，程序会在这样的位置停下来。</p>
<p><a href="http://4.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVTLfJGI/AAAAAAAAACk/g5Q0-rIWqMk/s1600-h/4.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://4.bp.blogspot.com/_ewlmUWn6UWQ/SRGoVTLfJGI/AAAAAAAAACk/g5Q0-rIWqMk/s400/4.jpg" alt="" width="398" height="167" /></a></p>
<p>我们开始调试，右键点击main.mxml &#8212; Debug As &#8212; Adobe AIR Application.</p>
<p><a href="http://1.bp.blogspot.com/_ewlmUWn6UWQ/SRGsrF6ZrpI/AAAAAAAAAC8/gRACN2r1Elk/s1600-h/7.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://1.bp.blogspot.com/_ewlmUWn6UWQ/SRGsrF6ZrpI/AAAAAAAAAC8/gRACN2r1Elk/s400/7.jpg" alt="" width="398" height="223" /></a><br />
然 后你可能会看倒这样的提示，这是问你是否要将我们的主窗口切换到调试模式。你可以看见图片右上角有显示“Flex” 旁边有一个flex的图标，你可以点开那个菜单看见里面有三种视图Debugging, Development和Profiling。 我们已经用了其中2个，Development就是我们上面写程序的视图，Debugging是我们即将要切换到的视图，Profiling是用来帮助我 们检查程序的性能的工具，可以帮助我们解决Memory leak等等的问题，这个不需要知道，以后有机会用到的时候再研究也不迟。 现在点Yes继续。</p>
<p><a href="http://2.bp.blogspot.com/_ewlmUWn6UWQ/SRGsrcJ1EaI/AAAAAAAAADE/kqh_8u3kqXU/s1600-h/8.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://2.bp.blogspot.com/_ewlmUWn6UWQ/SRGsrcJ1EaI/AAAAAAAAADE/kqh_8u3kqXU/s400/8.jpg" alt="" width="398" height="220" /></a></p>
<p>程 序运行后，点击按钮，你会发现程序停在了下面的位置，一个绿色的横杠标示出程序现在停在了短点的位置，这个时候我们就可以查看这一时刻当前对象的各种我们 感兴趣的信息了，你可以试着切换屏幕右上窗口的 Variables选像卡，会看到当前活动的对象，这里我们也不多说，尝试多调试下程序后你自然就明白Variables里面的内容了，都是很直观的信 息。 接下来如果我们点上面绿色的箭头，程序会继续执行直到遇到下一个断点，如果按F6，会单步执行。</p>
<p><a href="http://4.bp.blogspot.com/_ewlmUWn6UWQ/SRGsrUWbaxI/AAAAAAAAADM/9zF2XkDHERU/s1600-h/9.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://4.bp.blogspot.com/_ewlmUWn6UWQ/SRGsrUWbaxI/AAAAAAAAADM/9zF2XkDHERU/s400/9.jpg" alt="" width="398" height="215" /></a></p>
<p>以上就是全部第2点的内容。</p>
<p><span style="font-size: large;"><strong>3. 发布AIR程序。</strong></span></p>
<p>既然 AIR是桌面应用程序，那它自然也需要按装，现在我们就来看怎么把我们写好的程序发布成按装包。点击图上红色圆圈的按钮，弹出如图所示窗口。在Export file中填上你想要的按装包的名字，点击Next</p>
<p><a href="http://1.bp.blogspot.com/_ewlmUWn6UWQ/SRGyS_DKp-I/AAAAAAAAADU/1xsDAEXQk0Q/s1600-h/10.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://1.bp.blogspot.com/_ewlmUWn6UWQ/SRGyS_DKp-I/AAAAAAAAADU/1xsDAEXQk0Q/s400/10.jpg" alt="" width="398" height="183" /></a></p>
<p>这里我们发布程序需要有一个Key,那是你程序的证书。因为第一次发布，所以点Create。</p>
<p><a href="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGyV4wgmTI/AAAAAAAAAD0/tbT2HvUOvps/s1600-h/14.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGyV4wgmTI/AAAAAAAAAD0/tbT2HvUOvps/s400/14.jpg" alt="" width="398" height="204" /></a></p>
<p>打开如图所示窗口，填上名字，密码，点击Browser选择保存位置。我的是Mac击所以界面有些不一样，但是操作和windows是一样的。我保存了名叫MyKey的证书。</p>
<p><a href="http://2.bp.blogspot.com/_ewlmUWn6UWQ/SRGyThZULpI/AAAAAAAAADc/nJr9tq9dgak/s1600-h/11.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://2.bp.blogspot.com/_ewlmUWn6UWQ/SRGyThZULpI/AAAAAAAAADc/nJr9tq9dgak/s400/11.jpg" alt="" width="398" height="193" /></a></p>
<p><a href="http://1.bp.blogspot.com/_ewlmUWn6UWQ/SRGygbioyVI/AAAAAAAAAD8/jq-H1H7PGjM/s1600-h/15.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://1.bp.blogspot.com/_ewlmUWn6UWQ/SRGygbioyVI/AAAAAAAAAD8/jq-H1H7PGjM/s400/15.jpg" alt="" width="398" height="190" /></a></p>
<p><a href="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGyU2wE-zI/AAAAAAAAADk/kiB5w9HFXwA/s1600-h/12.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGyU2wE-zI/AAAAAAAAADk/kiB5w9HFXwA/s400/12.jpg" alt="" width="398" height="200" /></a></p>
<p>上图点击OK后你可以看倒证书已经选择完毕。填上你的密码，点击Finish.</p>
<p><a href="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGyVVFKpTI/AAAAAAAAADs/7knH3VYHH10/s1600-h/13.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://3.bp.blogspot.com/_ewlmUWn6UWQ/SRGyVVFKpTI/AAAAAAAAADs/7knH3VYHH10/s400/13.jpg" alt="" width="398" height="195" /></a></p>
<p>如下红色圆圈所示，在你的项目文件夹里出现一个main.air的文件，那就是我们发布的AIR程序安装包了。</p>
<p><a href="http://1.bp.blogspot.com/_ewlmUWn6UWQ/SRGygZrcGbI/AAAAAAAAAEE/IM06Zs88FpE/s1600-h/16.jpg" rel="shadowbox[post-54];player=img;" target="_blank"><img style="border: 1px solid #ffffff; padding: 2px; background: transparent none repeat scroll 0% 0%;" src="http://1.bp.blogspot.com/_ewlmUWn6UWQ/SRGygZrcGbI/AAAAAAAAAEE/IM06Zs88FpE/s400/16.jpg" alt="" width="398" height="174" /></a><br />
<span style="font-size: large;"><strong><br />
4. 安装已发布的AIR安装包。</strong></span></p>
<p>使 用AIR程序的人当然不需要flexbuilder这样的东西，他们只需要按装已下air程序的运行环境。就像run java app需要java runtime, 运行 air需要 air runtime,这里是下载地址 http://labs.adobe.com/downloads/air.html. 下载 windows版或者mac版。 下载后安装既可。</p>
<p>按装完runtime之后，双击main.air就可以开始将air程序，安装过程和普通应用程序无异。</p>
<p>好了，看完以上内容，相信你已经可以开始自己的AIR程序。至于更深入的内容大家可以继续看以后的AIR教程。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flextheworld.com/2009/01/adobe-air-create-air.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
