2

I'm building a simple audio player in AS3. I would like to embed multiple instance of this audio player in my html and when one's playing, others are paused. Is it possible to use LocalConnection to communicate between different instance of the same swf? From what I could test, once the connection is made with one instance, the others throw an error...

My other option is to use javascript. Any other ideas?

subb
  • 1,578
  • 1
  • 15
  • 27
  • To be honest, nope. Local Connection works pretty much like a walkie-talkie. I think External Interface/javascript is the way forward, although it might be a b**** to setup at first. goodluck! – George Profenza Aug 21 '09 at 20:18

2 Answers2

4

For everyone interested, here's my simple implementation.

Javascript Code

//keep a reference to every player in the page
players = [];

//called by every player
function register(id)
{
    players.push(id);
}

//stop every player except the one sending the call
function stopOthers(from_id)
{
    for(var i = 0; i < players.length; i++)
    {
        var id = players[i];
        if(id != from_id)
        {
            //setEnabled is a callback defined in AS3
            thisMovie(id).setEnabled(false);
        }
    }
}

//utility function to retreive the right player
function thisMovie(movieName)
{
     if (navigator.appName.indexOf("Microsoft") != -1) {
         return window[movieName];
     } else {
         return document[movieName];
     }
}

AS3 Code

if(ExternalInterface.available)
{
    ExternalInterface.addCallback("setEnabled", setEnabled);
    ExternalInterface.call("register", ExternalInterface.objectID);
}

function setEnabled(value:Boolean):void
{
    //do something
}

//when I want to stop other players
if(ExternalInterface.available)
    ExternalInterface.call("stopOthers", ExternalInterface.objectID);
subb
  • 1,578
  • 1
  • 15
  • 27
1

It works good in IE, FF.

in chrome return document[movieName]; returns undefined.

i just replaced with return document.getElementById(movieName). now works Chrome also.

palPalani
  • 105
  • 1
  • 1
  • 10