5 Replies Latest reply on Jun 19, 2007 2:41 AM by Imsko

    Calliing actionscript method from javascript

      I am trying to call an actionscript method from javascript but i it doesnt seem to work at all.
      i was trying to follow the example at adobes site ( http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_15683&sliceId=2)
      where they show examples using the external interface api

      the part that i have problems with is the code attached below.

      so when the javascript executes nothing happens. i tried to use firebug to see what the error might be and the error message i get is "getFlashMovie("ExternalInterfaceExample").sendTextToFlash(text); is not a function"

      i tried this in safari and firefox 2.0 on mac with flash player 9

      anybody experienced this problem?

        • 1. Re: Calliing actionscript method from javascript
          MaxManNH Level 2
          Have you tried getting it to work in the other direction first? If you can get Flash to fire a javascript command then perhaps it will be simpler to figure out why it won't work in the reverse direction?
          • 2. Re: Calliing actionscript method from javascript
            kglad Adobe Community Professional & MVP
            what's that javascript and html have to do with your swf??

            there's no sendTextToFlash() javascript function and there's no code embedding your swf.
            • 3. Re: Calliing actionscript method from javascript
              liquidleaf Level 1
              Hey - try this instead. This works in both IE and Firefox...

              var flashobject = document.getElementById("myflashmovie");
              (make sure you put id="myflashmovie" in both the <object> and <embed> params).

              Then, try

              However, make SURE that the flash movie has actually loaded before you are trying to call the Flash function from Javascript.

              Here's something I use while testing JS/Flash interaction. In your Flash code, insert
              ExternalInterface.call("alert", "JS has called a Flash function");
              (or whatever useful message you want).

              Then, when your Flash function has successfully been called, you'll get a JS alert.

              But try using getElementById first and see if that works for you.
              • 4. Re: Calliing actionscript method from javascript
                liquidleaf Level 1
                kglad - there doesn't need to be a sendTextToFlash JS function. "sendTextToFlash" is made into an object method as soon as it's made accessible via ExternalInterface.addCallback within the Flash file.

                Their idea is along the right lines, trying to invoke this kind of thing...

                I think the problem is that the flashobject isn't being referenced properly.
                • 5. Re: Calliing actionscript method from javascript
                  Imsko Level 1
                  thanks liquidleaf your solution worked perfectly. but only on IE and Safari, but there still nothing happens when you try it on firefox, calling JS from AS works but not the other way around