ExternalInterface.addCallback for as3 not working

I want to call the AS function from JS.

I have the following ActionScript 3 code:

package  {
    import flash.display.*;
    import flash.events.*;
    import flash.system.*;
    import flash.external.ExternalInterface;
    public class Main extends Sprite {
        public function Main() 
        {
            ExternalInterface.addCallback("PlaySound", PlaySound);
        }
        public function PlaySound():void
        {

        }
    }
}

I need to call the PlaySound () function from JavaScript. I am trying to do it like this:

function thisMovie(movieName) {
   if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
   } else {
        return document[movieName];
   }
}

function m()
{
  var obj=thisMovie("Main");
  obj.PlaySound();
}

But obj does not have a PlaySound () method (obj is not null).

What's wrong?

+1
source share
2 answers

I use this to find a movie. This seems more reliable:

function thisMovie(movieName) {
    var movie;
    try
    {
        movie = document[movieName];
        movie = (movie == null) ? window[movieName] : movie;        
    }
    catch (e)
    {
        return null;
    }
    return movie;
}

I also found that ExternalInterface is not working properly when working from the local file system. Have you tried to run this from a web server?

, ... , PlaySound, . , ?

+3

, , SWF JS.

0

All Articles