什么时候可以开始使用Javascript调用ActionScript? [英] When can Javascript start calling Actionscript?

查看:105
本文介绍了什么时候可以开始使用Javascript调用ActionScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

有一个非轮询方式的Javascript指挥闪存权当它的外部接口是准备好了?

Is there a non-polling way for Javascript to command Flash right when its external interface is ready?

背景

在ActionScript中,我已经注册了一个功能的Javascript调用:

In Actionscript, I've registered a function for Javascript to call:

ExternalInterface.addCallback('doStuff", this.doStuff);

我用 SWFObject的以嵌入闪存到我的网页:

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

SWF对象允许您运行code当闪存已经成功地嵌入通过回调。我尝试运行$('flash播放器')。doStuff在这个回调,但它声称它是不确定的。看来,闪存需要一些时间来启动它的外部接口。所以,我一直在使用轮询黑客找出当外部接口已准备就绪:

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

这轮询并不理想。有一个视觉感知延迟doStuff的执行,它使我的整体code结构泥泞。

This poller is not ideal. There's a visually perceptible delay in the execution of doStuff and it makes my overall code structure muddy.

推荐答案

在JavaScript的:

In Javascript:

function flashIsReady()
{
    $('flashPlayer').doStuff();
}

在ActionScript代码:

In Actionscript:

if (ExternalInterface.available) {
    ExternalInterface.addCallback('doStuff', this.doStuff);
    ExternalInterface.call("flashIsReady");
}

这篇关于什么时候可以开始使用Javascript调用ActionScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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