Adobe FLEX学习笔记(2)-Hello Wo…

这里使用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">  //目前air的版本为1.0
    <id>examples.html.HelloWorld</id>  //应用的id,唯一标识
    <version>0.1</version>  //程序的版本
    <filename>HelloWorld</filename>  //用来安装应用时的名字
    <initialWindow>  //初始配置节点,以下只是部分属性
        <content>HelloWorld.html</content>  //应用启动时的首页
        <visible>true</visible>  //初始就可见
        <width>400</width>  //应用的宽度
        <height>200</height>  //应用的高度
    </initialWindow>
</application>

5、建立HelloWorld.html。

<html>
<head>
    <title>Hello World</title>
    <script type="text/javascript" src="AIRAliases.js"></script>  //引入AIRAliases.js,方便利用别名来引用air的APIs,比如如果不用别名,在air中创建一个air文件对象的语法如下,var textFile = new runtime.flash.filesystem.File("app:/textfile.txt"),如果使用别名则为var textFile = new air.File("app:/textfile.txt")。
    <script type="text/javascript">

//onLoad时触发appLoad()方法
        function appLoad(){
            air.trace("Hello World");  //air.trace为别名,改方法用来在使用ADL时在命令行输出
        }
    </script>
</head>
<body onLoad="appLoad()">
    <h1>Hello World</h1>
</body>
</html>

6、把AIRAliases.js文件从frameworks 目录下拷贝到HelloWorld目录下。

二、运行HelloWorld

1、打开命令行:运行-》cmd,cd到HelloWorld目录下,输入adl HellWorld-app.xml。通过adl,可以运行没有打包发布的air应用。

Adobe FLEX学习笔记(2)-Hello World应用 - 北一止水 -

  air.trace("Hello World"),中的Hello World会出现在命令行

如果没有错误,则会出现下图

Adobe FLEX学习笔记(2)-Hello World应用 - 北一止水 -

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>
    <head>
        <title>Source Viewer Sample</title>
        <script type="text/javascript" src="scripts/AIRIntrospector.js"></script>
        <script type="text/javascript">
            function logBtn()
            {
                var button1 = document.getElementByIdx("btn1");
                air.Introspector.Console.log(button1);    //调用的方法
            }
        </script>
    </head>
    <body>
        <p>Click to view the button object in the Console.</p>
        <input type="button" id="btn1"
            οnclick="logBtn()"
            value="Log" />
    </body>
</html>

Adobe FLEX学习笔记(2)-Hello World应用 - 北一止水 -  

 四、adl退出和错误代码

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.

 

<script type="text/javascript" id="wumiiRelatedItems"> </script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值