Javascript什么时候可以开始调用Actionscript?
问题
是否有一种非轮询方式让Javascript在外部接口准备好时立即命令Flash?
背景
在 Actionscript 中,我注册了一个供 Javascript 调用的函数:
ExternalInterface.addCallback('doStuff", this.doStuff);
我使用 SWFObject 将 Flash 嵌入到我的页面中:
swfobject.embedSWF(
'flash/player.swf',
'flashPlayer',
'100%',
'100%',
'9',
'expressInstallSwfTODO.swf',
{},
{allowfullscreen: true},
{},
function(status) {
if (!status.success) {
alert('Failed to embed Flash player');
} else {
$('flashPlayer').doStuff();
}
}.bind(this)
);
SWFObject 允许您在通过回调成功嵌入 Flash 时运行代码。我尝试在此回调中运行 $('flashPlayer').doStuff,但它声称它未定义。看来Flash需要一些时间来启动其外部接口。因此,我一直在使用轮询黑客来查明外部接口何时准备就绪:
new PeriodicalExecutuer(
function(poller) {
if ($('flashPlayer').doStuff) {
$('flashPlayer').doStuff();
poller.stop()
}
},
0.2
);
这个轮询器并不理想。 doStuff 的执行存在视觉上可察觉的延迟,这使我的整体代码结构变得混乱。
Question
Is there a non-polling way for Javascript to command Flash right when its external interface is ready?
Background
In Actionscript, I've registered a function for Javascript to call:
ExternalInterface.addCallback('doStuff", this.doStuff);
I use SWFObject to embed the Flash into my page:
swfobject.embedSWF(
'flash/player.swf',
'flashPlayer',
'100%',
'100%',
'9',
'expressInstallSwfTODO.swf',
{},
{allowfullscreen: true},
{},
function(status) {
if (!status.success) {
alert('Failed to embed Flash player');
} else {
$('flashPlayer').doStuff();
}
}.bind(this)
);
SWFObject lets you run code when Flash has been successfully embedded through a callback. I attempt to run $('flashPlayer').doStuff in this callback, but it claims it's undefined. It seems that Flash needs some time to boot up its external interface. So I've been using a polling hack to find out when the external interface is ready:
new PeriodicalExecutuer(
function(poller) {
if ($('flashPlayer').doStuff) {
$('flashPlayer').doStuff();
poller.stop()
}
},
0.2
);
This poller is not ideal. There's a visually perceptible delay in the execution of doStuff and it makes my overall code structure muddy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 JavaScript 中:
在 Actionscript 中:
In Javascript:
In Actionscript:
我做了一个轮询解决方案。在actionscript中,我有一个像这样的函数:
在javascript中,在'onFlashReady'事件之后我也编码到初始化中,我开始一个像这样的间隔:
I did a polling solution. In actionscript I have a function like this:
And in javascript, after the 'onFlashReady' event I also have coded into intialization, I start an interval like this: