【问题标题】:Can't get air app to load html file included in project无法让空气应用程序加载项目中包含的 html 文件
【发布时间】:2012-12-03 03:42:32
【问题描述】:

我想在我的空中应用程序中使用 JavaScript,但无法让空中应用程序加载本地(包含)html 文件。

这是html文件的内容:

<html>
<head>
<script>
function setHeader(st) {
    document.getElementById('hiTitle').innerHTML = st;
}
</script>
</head>
<body>
<h1 id="hiTitle">Hello there</h1>
</body>
</html>

这是mxml文件:

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml">
    <mx:Script>
    <![CDATA[
    private function tracehtml():void {
        trace(htmlZ);
        htmlZ.htmlLoader.window.setHeader("never works");
    }
    ]]>
    </mx:Script>

    <mx:Panel x="10" y="10" width="252" height="100%"
    layout="absolute" title="The local html file">
        <mx:HTML
            id="htmlZ"
            location="script.html"
            enabled="true"
            paddingLeft="4"
            paddingRight="4"
            width="100%" height="100%"/>
    </mx:Panel>

    <mx:Button x="270" y="65" label="Highlight &gt;&gt;"
        click="tracehtml()"/>

</mx:WindowedApplication>

如果我像这样更改 mx:html 的位置: location="http://labs.adobe.com/"

它确实显示了 html,两个文件都位于同一个目录中。

在构建项目时将 flex 4.6 sdk 与 flashbuilder 一起使用,不会出现错误或警告。

【问题讨论】:

  • 如果我将 script.html 放在 bin 文件夹中(flashdevelop 放置 swf 的位置),那么它可以工作。现在我必须找到一种方法来获取在 swf 中编译的 html,以及我需要使用什么路径作为位置值。

标签: javascript apache-flex air flashdevelop


【解决方案1】:

flashbuilder 的答案很简单。将 html 文件和 js 文件放在名为 assets 的文件夹中,并将该文件夹放在应用程序的 bin 目录中。

现在,当使用 F5(Projcet => Test Project) 运行 air 应用程序时,它可以工作了。

在项目文件夹中有一个名为 bat 的文件夹。我检查了 bat 文件,Packer 将工作目录更改为 bin,然后告诉 adt (Adobe Air Developer Tool) 将所有内容包含在当前目录 (=bin) 中。

打开命令提示符并转到项目文件夹,然后键入以下命令:

bat\SetupSDK.bat
bat\CreateCertificate.bat
(wait a minute)
bat\SetupApplication.bat
bat\Packager.bat

对于那些不使用 flashbuilder 的人,adt 命令如下(项目名称是 google):

adt -package  -storetype pkcs12 -keystore "bat\Google.p12" -storepass fd air\Google.air application.xml -C bin .

现在在air文件夹下创建了一个air文件,用winrar打开它(它是一个zip文件)并确认资产目录在那里。

双击文件启动安装程序,打开已安装的应用程序后它可以正常工作,并且在 flashdevelop 中进行测试时也是如此。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-20
    相关资源
    最近更新 更多