相同的SWF的不同实例之间的LocalConnection? [英] LocalConnection between different instances of the same SWF?

查看:162
本文介绍了相同的SWF的不同实例之间的LocalConnection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个简单的音频播放器在AS3中。我想这个嵌入的音频播放器在我的HTML,当一个人打,其他人被暂停的多个实例。是否有可能使用LocalConnection相同的swf的不同实例之间的沟通?从我能测试,一旦连接是用一个实例,别人抛出一个错误...

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...

我的另一种选择是使用JavaScript。任何其他的想法?

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

推荐答案

对于大家感兴趣的话,这里是我的简单实现。

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

这篇关于相同的SWF的不同实例之间的LocalConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆