We'll look at the following code:
Copy Code code as follows:
<?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 (' executive Navigatetourl ');";
var request:urlrequest = new URLRequest (URL);
Navigatetourl (Request, "_self");
}
Private Function Init2 (): void
{
Externalinterface.call ("function function1 () {alert (' Execute Externalinterface ');}");
}
Private Function Clickfun (): void
{
Externalinterface.call ("function function2 () {window.document.title = ' changed title ';}");
}
]]-->
</mx:Script>
<mx:button x= "y=" label= "1" click= "init1 ()"/>
x= "544" y= "<mx:button" label= "2" click= "Init2 ()"/>
<mx:button x= "404" y= "315" label= "change title" 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 (' executive Navigatetourl ');";
var request:urlrequest = new URLRequest (URL);
Navigatetourl (Request, "_self");
}
Private Function Init2 (): void
{
Externalinterface.call ("function function1 () {alert (' Execute Externalinterface ');}");
}
Private Function Clickfun (): void
{
Externalinterface.call ("function function2 () {window.document.title = ' changed title ';}");
}
]]-->
</mx:Script>
<mx:button x= "y=" label= "1" click= "init1 ()"/>
x= "544" y= "<mx:button" label= "2" click= "Init2 ()"/>
<mx:button x= "404" y= "315" label= "change title" click= "Clickfun ()"/>
</mx:Application>
Functions Init1 and Init2 are all through JavaScript pop-up balloons, Clickfun () to modify the page title.
3 functions performed individually are successful, but when
1. Executing the INIT1 function before calling the Clickfun function will find Clickfun execution failed.
2. Executing the INIT2 function before calling the Clickfun function will find Clickfun execution successful.
Could it be that navigatetourl will cause externalinterface execution to fail?? Please know the reason of the friend under the guidance.