Skip navigation
Hatchling Studios
Currently Being Moderated

Call Javascript From AIR - Flash

Sep 1, 2010 12:20 AM

I'm developing an AIR application in Flash that needs to call external javascript functions. Is it possible to call external js functions from AIR (Flash) or call js functions embedded in an html file? Any help or examples are appreciated.

 
Replies
  • Currently Being Moderated
    Sep 1, 2010 2:22 AM   in reply to Hatchling Studios

    Hi, what did you mean ? Call a JS function in an html which is in a  HTML component ?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 1, 2010 7:01 AM   in reply to Hatchling Studios

    Ok, I dont think you can call a JS file directly but load a simple HTML file like this:

     

    <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));
    }

     

    This will trace: result (4+8) : 12

     

    Hope this help.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 20, 2010 12:09 AM   in reply to Neobox75

    How would I call a javascript function thats not inside the html page.

     

    I want to include JQuery (or other libraries) into an AIR project. I then want to call these JQuery functions on any webpage loaded into the HTMLLoader.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 20, 2010 2:48 AM   in reply to springframework

    Hi, I dont know but you can create wrapers functions on ur html file that query your jquery functions if u dont find how to do that

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 24, 2010 12:05 AM   in reply to springframework

    Hi,

     

    Assuming you would like to build a JavaScript project that needs to use JQuery (or other JS framework) how would you proceed? You would include a .js file in some HTML files in which you need such support. Using this approach, you can use js framework functionality from js and html.

     

    You can use this approach with AIR too (just like you are using AIRAliases.js or AIRIntrospector.js).

     

    If i did not understand your workflow correctly, please provide me with more details and i will see if i can help you.

     

    Regards,

    Mihnea Ovidenie

    AIR Engineering

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 24, 2010 1:48 PM   in reply to mihnea1975

    I want to do the opposite of what you are describing.

     

    I want to include a .js file into an .as or .mxml file

     

    I then want to be able to execute that javascript file on any HTMLLoader that I have.

     

     

    earlier it was shown that you can execute javascript from actionscript if the javascript is inside the html of the HTMLLoader like this:

     

    function onLoaded(e:Event) :void
    {
        trace("result (4+8) : "+e.target.window.addBlu(4, 8));
    }

     

     

     

    but how would I call JQuery functions on the html inside the HTMLLoader if JQuery is not included in it.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 26, 2010 9:54 PM   in reply to Hatchling Studios

    Hi,

     

        Instead of writting a jquery or javascript function inside a html page you can include your .js file in the index.template.html file which is generated by the air application <script language="javascript" src="your filename"></script>.

     

    Then u can call the javascript function from your .as or mxml file like this

     

    ExternalInterface.call(

    functionname,arguments);

    Thats it.

     

    Thanks & Regards,

    Flex Rock.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points