JavaScript and ActionScript interact to implement code _javascript techniques

Source: Internet
Author: User
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);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.