Flash as3

关注公众号 jb51net

关闭
首页 > 网页制作 > Flash > Flash as3 > AS3 navigateToURL

AS3 navigateToURL导致ExternalInterface 执行失败问题

作者:

AS3 navigateToURL导致ExternalInterface 执行失败问题
我们先看下面代码:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<!--[CDATA[
import flash.external.ExternalInterface;
private function init1():void
{
var url:String = "javascript:alert('执行navigateToURL');";
var request:URLRequest = new URLRequest(url);
navigateToURL(request,"_self");
}
private function init2():void
{
ExternalInterface.call("function function1(){alert('执行ExternalInterface');}");
}
private function clickfun():void
{
ExternalInterface.call("function function2(){window.document.title = '更改后的标题';}");
}
]]-->
</mx:Script>
<mx:Button x="150" y="92" label="1" click="init1()"/>
<mx:Button x="544" y="92" label="2" click="init2()"/>
<mx:Button x="404" y="315" label="更改标题" click="clickfun()"/>
</mx:Application>
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">

<mx:Script>
<!--[CDATA[
import flash.external.ExternalInterface;

private function init1():void
{
var url:String = "javascript:alert('执行navigateToURL');";
var request:URLRequest = new URLRequest(url);
navigateToURL(request,"_self");
}
private function init2():void
{
ExternalInterface.call("function function1(){alert('执行ExternalInterface');}");
}

private function clickfun():void
{
ExternalInterface.call("function function2(){window.document.title = '更改后的标题';}");
}

]]-->
</mx:Script>
<mx:Button x="150" y="92" label="1" click="init1()"/>
<mx:Button x="544" y="92" label="2" click="init2()"/>
<mx:Button x="404" y="315" label="更改标题" click="clickfun()"/>

</mx:Application>

函数init1和init2都是通过javascript弹出提示框,clickfun()为修改网页标题。
3个函数单独执行都是成功的,但当
1.先执行init1函数后再调用clickfun函数,会发现clickfun执行失败。
2.先执行init2函数后再调用clickfun函数,会发现clickfun执行成功。
难道是navigateToURL会导致ExternalInterface 执行失败??请知道原因的朋友指导下。
您可能感兴趣的文章:
阅读全文