这里使用ADL和ADT来开发一个基于html的air应用,ADL和ADT是基于命令行模式的工具。
一、首先建立一个目录用来放置应用的文件(目录名为 HelloWorld),任何一个基于html的air应用都包含以下3个文件。
1、一个xml格式的air应用配置文件,用来配置应用的元数据。
2、一个html格式的页面文件。
3、AIRAliases.js,定义了方便的air APIs类变量别名。
4、建立HelloWorld-app.xml。如下
<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/1.0">
</application>
5、建立HelloWorld.html。
<html>
<head>
//onLoad时触发appLoad()方法
</head>
<body onLoad="appLoad()">
</body>
</html>
6、把AIRAliases.js文件从frameworks 目录下拷贝到HelloWorld目录下。
二、运行HelloWorld
1、打开命令行:运行-》cmd,cd到HelloWorld目录下,输入adl HellWorld-app.xml。通过adl,可以运行没有打包发布的air应用。
如果没有错误,则会出现下图
2、生成air应用的安装程序
当能够正确执行时,便可以利用ADT来打包应用生成一个安装文件。安装文件其实是一个压缩文件,可以在已安装了AIR 运行环境的计算机上安装air应用。
为了确保应用的安全,一个air应用必须要进行数字签名。可以使用adt或者其它证书生成工具,也可以用商业的证书工具如VeriSign 、Thawte。
使用adt来生成证书
adt -certificate -cn SelfSigned 1024-RSA sampleCert.pfx samplePassword
生成的证书要放在HelloWorld目录下,然后使用adt来打包应用。
adt -package -storetype pkcs12 -keystore sampleCert.pfx HelloWorld.air HelloWorld-app.xml HelloWorld.html AIRAliases.js
然后输入密码。
正确的话就会在HelloWorld目录下生成一个HelloWorld.air文件。双击它便可安装和运行。
三、使用AIRIntrospector.js来调试
在html文件中引入<script type="text/javascript" src="AIRIntrospector.js"></script>
AIRIntrospector.js文件位于frameworks目录下。只有在开发和调试的时候可以使用AIRIntrospector.js,发布的时候去掉它。AIRIntrospector.js会提供一个图形界面的控制台。有4个方法, log(), warn(), info(), error(), dump().<html>
</html>
ADL exit and error codes
The following table describes the exit codes printed by ADL:
Exit code | Description |
---|---|
0 | Successful launch. ADL exits after the AIR application exits. |
1 | Successful invocation of an already running AIR application. ADL exits immediately. |
2 | Usage error. The arguments supplied to ADL are incorrect. |
3 | The runtime cannot be found. |
4 | The runtime cannot be started. Often, this occurs because the version or patch level specified in the application does not match the version or patch level of the runtime. |
5 | An error of unknown cause occurred. |
6 | The application descriptor file cannot be found. |
7 | The contents of the application descriptor are not valid. This error usually indicates that the XML is not well formed. |
8 | The main application content file (specified in the <content> element of the application descriptor file) cannot be found. |
9 | The main application content file is not a valid SWF or HTML file. |