Search code examples
apache-flexairflex4externalinterface

Call Flex4 function by any event happen in mx:html container in windowed application


I am working with Flex 4 windowed application. I have a mx:HTML container with location attribute like http://bla.com/abc.html. That abc.html has a html button and i want when that html button is clicked then a flex windowed application function should be called. How can i do that please guide.

Dummy Flex 4 windowed application screen shot: http://i41.tinypic.com/2u8kuxk.jpg


Solution

  • Try , accessing flex from javascript.

    http://blog.everythingflex.com/2008/02/25/air-actionscript-javascript-bridge/

    or

    <html>
    <head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script language="javascript" type="text/javascript">
        <!--
            function addBlu(a, b) { return (a+b); }
        -->
    </script>
    </head>
    </html>
    

    And with my poor AS3 code:

    import flash.html.HTMLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    
    var html:HTMLLoader = new HTMLLoader();
    html.load(new URLRequest("callJS.html"));
    html.width = 0;
    html.height = 0;
    html.addEventListener(Event.COMPLETE, onLoaded);
    
    addChild(html);
    
    function onLoaded(e:Event) :void
    {
      trace("result (4+8) : "+e.target.window.addBlu(4, 8));
    }