Search code examples
htmlactionscript-3airloader

Input elemnts in HTMLLoader are readonly in adobe AIR


Lets say i have a html file that contain a form:

<form method="post" action="url">
    <input type="text" id="fullname" />
    <input type="text" id="bodyText" />
    <input type="submit">
</form>

we have load this html file using HTMLLoader inside an swf file.

_htmlLoader = new HTMLLoader();
_htmlLoader.paintsDefaultBackground = false;
var req:URLRequest = new URLRequest(urlValue);
_htmlLoader.load(req);
_stage.addChild(_htmlLoader);

After loading this Swf file using Loader inside main application, text boxes are readonly and can't type in it. But we can change focus of them using Mouse.

var loader1:Loader = new Loader();
loader1.load(new URLRequest("path to file.swf"));
// ...
this.addChild(loader1);
// ...

What is the problem?


Solution

  • Is the HTMLLoader being attached after the Event.COMPLETE event has been fired? It may even be worth waiting for the HTMLLoader's document to fire a DOMReady event before attaching it the stage.

    Try something like this:

    _htmlLoader = new HTMLLoader();
    _htmlLoader.paintsDefaultBackground = false;
    var urlRequest:URLRequest = new URLRequest(urlRequest);
    _htmlLoader.addEventListener(Event.COMPLETE, completeHandler);
    _htmlLoader.load(urlRequest);
    
    function completeHandler(event:Event):void { _htmlLoader.window.document.addEventListener("DOMContentLoaded", readyHandler); }
    
    function readyHandler(event:Event):void { _stage.addChild(_htmlLoader); }
    

    The Flex documentation about handling HTML events mentions this:

    When a listener refers to a specific DOM element, it is good practice to wait for the parent HTMLLoader to dispatch the complete event before adding the event listeners. HTML pages often load multiple files and the HTML DOM is not fully built until all the files are loaded and parsed. The HTMLLoader dispatches the complete event when all elements have been created.

    It might be possible that the HTMLLoader is being attached the stage before the document is actually ready, which may explain some of the weirdness.

    If you have any more information that would be an awesome help...