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;
Public Function Invokejavascript (): void
{
Lblresult.text=externalinterface.call ("Returnthename", txtName.Text);
}
]]>
</mx:Script>
<mx:panel width= "height=" title= "ActionScript invoke JavaScript" verticalcenter= "0" horizontalcenter= "0" >
<mx:textinput id= "txtname" text= "[Please enter first name]"/>
<mx:button id= "Btnconnect" label= "OK" click= "Invokejavascript" () "x=" 229 "y=" 204 "/>"
<mx:label id= "Lblresult" text= "Test" x= "205" y= "", "width=" height= ""
</mx:Panel>
</mx:Application>
Add a method function to JavaScript inside the HTML page returnthename (a) {return "success!" +a};
The above is the method of as calling JS
Here is the method of JS modulation
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" creationcomplete= "init ()" layout= "Absolute" >
<mx:Script>
<! [cdata[
Import Flash.external.ExternalInterface;
Private Function init (): void
{
Externalinterface.addcallback ("addTo100", add);//Declaration of methods that can be invoked
}
Private function Add (): int
{
var i:int;
var sum:int=0;
for (I=1; i<100; i++)
{
sum+= i;
}
return sum;
}
]]>
</mx:Script>
</mx:Application>
Add <button onclick= "Addmethod ()" to the HTML page > click Call </button>
JS file Plus method function Addmethod{var s= javascriptcallactionscript.addto100 (); alert (s);}