Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Actionscript 3 AS3 ExternalInterface.call,为什么它不';你不能在Chrome或IE上工作吗?_Actionscript 3_Externalinterface - Fatal编程技术网

Actionscript 3 AS3 ExternalInterface.call,为什么它不';你不能在Chrome或IE上工作吗?

Actionscript 3 AS3 ExternalInterface.call,为什么它不';你不能在Chrome或IE上工作吗?,actionscript-3,externalinterface,Actionscript 3,Externalinterface,上面的代码似乎可以在Firefox上运行,但当我在Chrome或IE上尝试时,它不起作用(它会导致错误并停止swf的执行) 有什么提示吗?ExternalInterface适用于所有主要浏览器的最新版本。您应该做的第一件事是在检查中包装该调用,以查看它当前是否可用: import flash.external.ExternalInterface; var pageURL:String = ExternalInterface.call('window.location.href.toString'

上面的代码似乎可以在Firefox上运行,但当我在Chrome或IE上尝试时,它不起作用(它会导致错误并停止swf的执行)


有什么提示吗?

ExternalInterface
适用于所有主要浏览器的最新版本。您应该做的第一件事是在检查中包装该调用,以查看它当前是否可用:

import flash.external.ExternalInterface;
var pageURL:String = ExternalInterface.call('window.location.href.toString');
Chrome和IE的问题可能是调用window.location.href。最好将其放入JS函数中,然后从AS调用该函数,如下所示:

if(ExternalInterface.available)
{
  ExternalInterface.call('window.location.href.toString');
}
另外,在尝试调用之前,请确保您尝试调用的函数已经存在于DOM中-如果您在添加脚本之前添加SWF,并立即调用
ExternalInterface
,那么它将失败,因为
reportHref
尚不存在

最后,从SWF内部调用
window.location
对象可能会由于沙盒而失败,如果从页面中的JS函数进行调用,则不会出现这种情况

ExternalInterface
上的文档非常全面,有很好的例子:


ExternalInterface
适用于所有主要浏览器的最新版本。您应该做的第一件事是在检查中包装该调用,以查看它当前是否可用:

import flash.external.ExternalInterface;
var pageURL:String = ExternalInterface.call('window.location.href.toString');
Chrome和IE的问题可能是调用window.location.href。最好将其放入JS函数中,然后从AS调用该函数,如下所示:

if(ExternalInterface.available)
{
  ExternalInterface.call('window.location.href.toString');
}
另外,在尝试调用之前,请确保您尝试调用的函数已经存在于DOM中-如果您在添加脚本之前添加SWF,并立即调用
ExternalInterface
,那么它将失败,因为
reportHref
尚不存在

最后,从SWF内部调用
window.location
对象可能会由于沙盒而失败,如果从页面中的JS函数进行调用,则不会出现这种情况

ExternalInterface
上的文档非常全面,有很好的例子:

不在IE9中工作

//JS:

function reportHref(){
    return window.location.href.toString(); 
    // I'm not sure this is good cross-browser JS. 
    // If it isn't, you can at least test it directly in the browser
    // and get a javascript error that you can work on.
}

//AS:
var result:String = "";
if(ExternalInterface.available)
{
    result = ExternalInterface.call("reportHref");
}
else
{
    result = "External Interface unavailable";
}
trace(result);
无处不在

if(ExternalInterface.available)
{
  ExternalInterface.call('window.location.href.toString');
}
不在IE9工作

//JS:

function reportHref(){
    return window.location.href.toString(); 
    // I'm not sure this is good cross-browser JS. 
    // If it isn't, you can at least test it directly in the browser
    // and get a javascript error that you can work on.
}

//AS:
var result:String = "";
if(ExternalInterface.available)
{
    result = ExternalInterface.call("reportHref");
}
else
{
    result = "External Interface unavailable";
}
trace(result);
无处不在

if(ExternalInterface.available)
{
  ExternalInterface.call('window.location.href.toString');
}


你所描述的正是我所做的。但是,当swf在Chrome或IE下运行时,似乎在以下行之前停止执行:ExternalInterface.call(“reportHref”)或ExternalInterface.call(“window.location.href.toString”)我正在使用swobject嵌入swf文件,也许这就是问题所在?您得到了什么错误?你已经为Chrome和IE安装了flash调试器播放器了吗?()如果它不起作用,你应该会出错。另外,请参见这里的示例:-您可能需要运行检查以确定JS和AS何时准备就绪,如本文所述,以找出问题所在。此外,在JS和AS中,您可以将调用包装在
try{}catch{}
阻止并跟踪错误,找出你做错了什么。在firefox中,一切正常。我需要弄清楚如何用chrome调试flash,并了解阻塞错误是什么…从该url安装调试程序flash player。和F12,并检查控制台。在这两者之间,您应该能够得到AS或JS错误。您所描述的正是我所做的。但是,当swf在Chrome或IE下运行时,似乎在以下行之前停止执行:ExternalInterface.call(“reportHref”)或ExternalInterface.call(“window.location.href.toString”)我正在使用swobject嵌入swf文件,也许这就是问题所在?您得到了什么错误?你已经为Chrome和IE安装了flash调试器播放器了吗?()如果它不起作用,你应该会出错。另外,请参见这里的示例:-您可能需要运行检查以确定JS和AS何时准备就绪,如本文所述,以找出问题所在。此外,在JS和AS中,您可以将调用包装在
try{}catch{}
阻止并跟踪错误,找出你做错了什么。在firefox中,一切正常。我需要弄清楚如何用chrome调试flash,并了解阻塞错误是什么…从该url安装调试程序flash player。和F12,并检查控制台。在这两者之间,你应该能够得到AS或JS错误。谢谢,很好的提示,但实际上这不是你感兴趣的地方。正如我在上面所说的,问题已经解决了。谢谢,很好的提示,但实际上这不是我感兴趣的地方。正如我在上面所说的,问题已经解决了。@JcFx我已经解决了。至少在给出答案的地方。。。这是我被禁止这么做的原因吗?我不知道——我从来没见过有人被禁止。最好问一个版主。因为你的声誉点,我想你可能有权这么做;)对不起……为什么我的问题被否决了?@JcFx我已经在做了。至少在给出答案的地方。。。这是我被禁止这么做的原因吗?我不知道——我从来没见过有人被禁止。最好问一个版主。因为你的声誉点,我想你可能有权这么做;)对不起…为什么我的问题被否决了?