在Flash中使用ExternalInterface的 [英] Using ExternalInterface in Flash

查看:529
本文介绍了在Flash中使用ExternalInterface的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编辑一些闪光,使外部JavaScript函数调用,但没有成功。这是我的ActionScript 2.0 code:

I'm trying to edit some flash to make an external javascript function call, but with no success. Here's my actionscript 2.0 code:

//testing external .js calls

import flash.external.ExternalInterface;

//attempting to make external js call

ExternalInterface.call("createPlaylist","It's my Life!");

和这里是我的javascript;

and here's my javascript;

function createPlaylist(mess){
  alert("called createPlaylist: " + mess);
}

我已经看到了很多例子,我主要困惑的使用 ExternalInterface.addCallback 的。我不需要的JavaScript返回任何闪光,所以这个必要吗?

I've seen lots of examples and I'm mainly confused about the use of ExternalInterface.addCallback. I don't need the javascript to return anything to flash, so is this necessary?

无论出于何种原因,我从来没有看到警报。有没有人看到我的code什么问题?有一些 ExternalInterface的库我没有?此外,有什么用 ExternalInterface的(即,错误检查等),最好的办法在此先感谢...

For whatever reason, I never see the alert. Does anyone see any problems in my code? Is there some ExternalInterface library I don't have? Also, what's the BEST way to use ExternalInterface (ie; error checking, etc.) Thanks in advance...

推荐答案

ExternalInterface.addCallback是javascript才能够调用到您的Flash应用程序。例如,如果你想要一个HTML按钮启动/停止视频时,只需添加一个回调的命名方法,你的JS能比调用[FlashObject] .callback方法名。

ExternalInterface.addCallback is for javascript to be able to call into your Flash application. If for example you want a HTML button that starts/stops a video you just add a callback for a named method and your js can than call [FlashObject].callback method name.

我会说,加ExternalInterface的方法在应用程序中的最佳方式是建立负责为每个交互情况下,在应用程序的JS通信类。例如:

I would say that the best way to add ExternalInterface methods in your application is to set up a class responsible for JS communication for each interaction case in the app. For example:

public class ExternalVideoControl {

    private var video:MediaDisplay;

    public function ExternalVideoControl(video:MediaDisplay) {
        //ExternalInterface.addCallback  - one callback for each method you want to expose, pointing to a method within this class;
        //add listeners on the video player and point them to methods in this class, for example onProgress
    }
    public function playVideo():void {
        //play the video on the mediaDisplay
    }
    private function onProgress(event:ProgressEvent):void {
        //ExternalInterface.call - report progress back to javascript
    }
}

要更直接地测试ExternalInterface的,尝试调用

To test ExternalInterface more directly, try calling

ExternalInterface.call("alert", "Hello World!");

这篇关于在Flash中使用ExternalInterface的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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