4 Replies Latest reply on Nov 13, 2009 1:16 AM by anucreative

    Controling a SWF from JS

      When developing an AIR app using HTML and JS I would like to have a Map, built in Flash, on the screen. Flash offers a much easier way to do map over lays etc. I have controlling buttons built in JS and HTML and would like them to send commands and set variables to the SWF.

      I know that AIR is basically a Flash environment with WebKit in there, so does the SWF map have access to variables created in the JS? Can I call methods from JS on the Map inside the SWF? I do not want to use FLEX or Flash for the core of this.

      I know this can be achieved using SWLIVECONNECT in a browser setting, but I would hate to have to include another JS lib just to solve this.

        • 1. Re: Controling a SWF from JS
          anirudhs Level 2

          Have you looked at ExternalInterface?

          It works between JS and embedded swf in an HTML AIR Application.
          • 2. Re: Controling a SWF from JS
            zacko_2 Level 1
            I have not. I briefly looked into it and found it confusing. I guess my biggest confusion arises from how to call this inside my HTML and JS application in AIR. What is the syntax? Overall that has been a struggling point for me when it comes to AIR and JS: How to call these things correctly. I am very proficient at AS 2.0, but 3.0 is a different beast entirely. I will look into this more, but if you had some sample JS code I could use/test with in AIR (i.e. air.what_goes_here?) that would be a huge help!

            Thanks for your response!
            • 3. Re: Controling a SWF from JS
              zacko_2 Level 1
              I have figured out how to do this using LocalConnection. The solution can be found here, with example code:
              Solution Using LocalConnection
              • 4. Re: Controling a SWF from JS

                I'm guessing you got the answer to this finally, but it seems the newer versions of AIR 1.5.x do give embedded SWFs access to Javascript. Using ExternalInterface.call works fine for us.


                // *Does* work

                if (ExternalInterface.available) {

                     x = ExternalInterface.call("callJSFromFlex");




                // *Doesn't* work

                if (ExternalInterface.available) {

                     ExternalInterface.addCallback("callFlexFromJS", callFlexFromJS);



                Where *we're* struggling is communication the other way (JS calling Flex code in the embedded SWF). ExternalInterface.addCallback doesn't seem to work in AIR 1.5.x. Fine in a browser, but not in AIR. Hopefully it's something that's coming...


                If anybody could give pointers on JS -> AS (in an embedded SWF), that'd be just dandy. There seems very little documentation/discussion around building HTML AIR apps and embedding SWFs into them (and ensuring they can communicate) - all articles seem to be about embedding HTML into Flex containers, or JS<->Flex communication in a browser.