Call JavaScript from AIR

Hi all,

I’m having a hell of a time trying to call JavaScript from an AIR application. Here’s what I’m trying to do:

  1. Load an HTML page using HTMLLoader.

  2. Access a link by its ID in the HTMLLoader object and simulate the JavaScript click() function on that link.

Here’s the JavaScript function in the loaded HTML page (it simply submits a form on the page):

function submitAssistantForm(direction)
{
    document.theForm.direction.value=direction;
    document.theForm.submit();
    return;
}

And here’s the ActionScript code I’m trying:

var html:HTMLLoader = new HTMLLoader();
html.addEventListener(Event.COMPLETE, splash);
html.load(new URLRequest("...URL omitted..."));

private function splash(e:Event):void
{
    // try to access the element by its ID and call the Javascript click() function on it
    html.window.document.getElementById('HrNext').click(); // this gives error "click is not a function"

    // try to call the Javascript function directly by its name
    html.window.submitAssistantForm('next'); // this gives error "TypeError: Result of expression 'document.theForm' [undefined] is not an object."
}

By the way, if I add the HTMLLoader object to the stage and manually click the link with my mouse, everything works perfectly. So I have to believe it’s possible to programmatically send a click event to the link.

I feel like I’m so close. Can anyone point me in the right direction?

Thanks,
Rob