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

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

问题描述



我试图从我的ActionScript代码调用一个javascript函数,但它不工作;

as3:

  if(ExternalInterface.available)
{
try
{
ExternalInterface.addCallback(changeDocumentTitle,null);

catch(error:Error)

js swfobject)

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

有人知道可能会发生什么吗?
<如果你想从你的Flex应用程序中调用一个JS函数,你想要使用ExternalInterface.call(...)而不是ExternalInterface.addCallback()。 ..)。从文档:


公共静态函数调用(函数名:字符串,...参数):*



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

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


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



addCallback()是如果您想要将Flash应用程序中的ActionScript函数公开给HTML容器,那么可以通过JavaScript调用它。


HI,

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 (inside velocity file using swfobject)

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

anyone know what could be happenin?

解决方案

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:

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

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

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() 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天全站免登陆