Search code examples
javascripthtmlapache-flexbuttonexecute

Run javascript inside HTML component in Adobe AIR Flex 4?


I have the following component in an AIR application from Flex 4:

<mx:HTML id="viewObject"
         x="10" y="42" width="634" height="313"
         location="http;//localhost:8080/mypage.php" />

Now I want to run a javascript when the page loads but the javascript isn't inside the target page. I want to run the following javascript:

javascript:alert('Hello world.');

I tried approaching it by setting the location property again to the javascript after the page has loaded like below.

<s:Button x="10" y="10" label="Button">
    <s:click>
        <![CDATA[
        viewObject.location = "javascript:alert('hello world');";
        ]]>
    </s:click>
</s:Button>

Unfortunately for me, that doesn't seem to work. Can anybody help me out with this problem?


Solution

  • That's because location is like using the address bar. What you need to do is something like this:

    htmlComponent.htmlLoader.window.alert('hello world');
    

    I think that should work.