0

I would like to use JavaScript in my air application but can't get the air app to load the loacal (included) html file.

This is the content of the html file:

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

This is the mxml file:

<?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>

If I change the location of mx:html like so: location="http://labs.adobe.com/"

It does show the html, both files are located in the same directory.

Using flex 4.6 sdk with flashbuilder with no errors or warnings when building the project.

HMR
  • 37,593
  • 24
  • 91
  • 160
  • If I put the script.html in bin folder (where flashdevelop puts the swf) then it works. Now I have to find a way to get the html compiled in the swf and what path I need to use as value for location. – HMR Dec 15 '12 at 10:43

1 Answers1

0

The answer for flashbuilder is quite simple. Put the html file(s) and js file(s) in a folder called assets and place that folder in the bin directory of your application.

Now when running the air app with F5(Projcet => Test Project) it works.

In the project folder there is a folder called bat. I checked out the bat files and Packager changes working dir to bin and then tells adt (Adobe Air Developer Tool) to include everything in the current directory (=bin).

Open a command prompt and go to the project folder, then typed the following commands:

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

For those not using flashbuilder the adt command is the following(project name is google):

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

Now an air file is created under the air folder, opened it with winrar (it's a zip file) and confirmed the assets directory is there.

Doubleclicking on the file starts the installer and after opening the installed app it works as well as when testing in flashdevelop.

HMR
  • 37,593
  • 24
  • 91
  • 160