本文介绍了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');
}

有人知道可能会发生什么吗?



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:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 16:17