externalinterface - 从 SWF 调用 javascript [英] externalinterface - calling javascript from SWF

查看:21
本文介绍了externalinterface - 从 SWF 调用 javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的动作脚本代码中调用一个 javascript 函数,但它不起作用;

im trying to call a javascript function from my actionscript code but its not working;

as3:

if (ExternalInterface.available)
  {
  try
  {
    ExternalInterface.addCallback("changeDocumentTitle",null);
  } 
  catch(error:Error)

js(使用 swfobject 的速度文件内部)

js (inside velocity file using swfobject)

function changeDocumentTitle() 
    {
        alert('call from SWF');
    }

有人知道会发生什么吗?

anyone know what could be happenin?

推荐答案

如果您尝试从 Flex 应用程序中调用 JS 函数,您希望使用 ExternalInterface.call(...) 而不是 ExternalInterface.addCallback(……).来自文档:

If you are trying to invoke a JS function from within your Flex app, you want to use ExternalInterface.call(...) and not ExternalInterface.addCallback(...). From the docs:

公共静态函数调用(functionName:String, ... arguments):*

public static function call(functionName:String, ... arguments):*

调用由 Flash Player 容器公开的函数,传递零个或多个参数.如果函数不可用,调用返回null;否则返回函数提供的值.Opera 或 Netscape 浏览器不允许递归;在这些浏览器上,递归调用会产生空响应.(Internet Explorer 和 Firefox 浏览器支持递归.)

Calls a function exposed by the Flash Player container, passing zero or more arguments. If the function is not available, the call returns null; otherwise it returns the value provided by the function. Recursion is not permitted on Opera or Netscape browsers; on these browsers a recursive call produces a null response. (Recursion is supported on Internet Explorer and Firefox browsers.)

如果容器是 HTML 页面,则此方法会调用脚本元素中的 JavaScript 函数.

If the container is an HTML page, this method invokes a JavaScript function in a script element.

http://livedocs.adobe.com/flex/3/langref/flash/external/ExternalInterface.html

addCallback() 用于将 Flash 应用程序中的 ActionScript 函数公开给 HTML 容器,以便它可以通过 JavaScript 调用.

addCallback() is used if you want to expose an ActionScript function from your Flash app to the HTML container so that it can be invoked via JavaScript.

这篇关于externalinterface - 从 SWF 调用 javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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