0

エア アプリケーションで 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 は表示されますが、両方のファイルが同じディレクトリにあります。

プロジェクトをビルドするときにエラーや警告なしで flashbuilder で flex 4.6 SDK を使用します。

4

1 に答える 1

0

flashbuilder の答えは非常に単純です。html ファイルと js ファイルを assets というフォルダーに置き、そのフォルダーをアプリケーションの bin ディレクトリに置きます。

F5(Projcet => Test Project)でエアアプリを実行すると動作します。

プロジェクト フォルダーには、bat というフォルダーがあります。私はbatファイルをチェックアウトし、Packagerは作業ディレクトリをbinに変更し、現在のディレクトリ(= bin)にすべてを含めるようadt(Adobe Air Developer Tool)に指示します。

コマンド プロンプトを開いてプロジェクト フォルダーに移動し、次のコマンドを入力します。

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 ファイルです)、assets ディレクトリがあることを確認しました。

ファイルをダブルクリックするとインストーラーが起動し、インストールされたアプリを開いた後、flashdevelop でテストする場合と同様に機能します。

于 2012-12-15T13:44:38.567 に答える