ActionScript and JavaScript Interactive instance program (Modify) _javascript tips

Source: Internet
Author: User
Tags cdata

mxml page:

<?xml version= "1.0" encoding= "Utf-8"?> <s:application xmlns:fx= "http://ns.adobe.com/mxml/2009" Library://ns.adobe.com/flex/spark "xmlns:mx=" library://ns.adobe.com/flex/mx "width=" 100% "height=" 100% "Xmlns:code" = "http://code.google.com/p/flex-iframe/" creationcomplete= "Initapp ()" > <fx:Declarations> <!-- Place non-visual elements (such as services, value objects) here--> </fx:Declarations> <fx:Script> <! [cdata[import flash.external.*;//Introduce externalinterface public function Initapp (): void {Externalinterface.addcallback ( 
"Myjsfunction", MYASFUNCN); 
Button.addeventlistener (Mouseevent.click,buttonclick); 
Public Function MYASFUNCN (js:string): String {return "JS:" +js+ "accessed as:" +asinput.text; 
Private Function ButtonClick (event:mouseevent): void {trace (asinput.text); 
Label.text = "As Call js ..."; 
var result:string = Calljs (Asinput.text); 
Label.text = "return value:" + result; 
Private Function Calljs (arg:string): String {return Externalinterface.call ("Jsmethod", Arg);Private Function Asmethod (arg:string): String {label.text = arg; Return "JS called as success! 
"; ]]> </fx:Script> <s:vgroup width= "100%" height= "100%" > <s:vgroup width= "100%" > <mx:button x = "169.5" y= "162" label= "click" fontsize= "" id= "button"/> <mx:textinput id= "asinput" x= "122" y= "" "/> <s:labe L id= "label"/> </s:VGroup> </s:VGroup> <code:iframe source= "myhtml.html" width= "$" height= "500"/& 
Gt </s:Application>

HTML page:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  

If you try the above method, you will find that you embed a parent SWF file in the embedded HTML meeting, as follows

This is obviously not the result I want. The code is then modified as follows:

Mxml page

<?xml version= "1.0" encoding= "Utf-8"?> <s:application xmlns:fx= "http://ns.adobe.com/mxml/2009" Library://ns.adobe.com/flex/spark "xmlns:mx=" library://ns.adobe.com/flex/mx "width=" 100% "height=" 100% "Xmlns:code" = "http://code.google.com/p/flex-iframe/" creationcomplete= "Initapp ()" > <fx:Declarations> <!-- Place non-visual elements (such as services, value objects) here--> </fx:Declarations> <fx:Script> <! 
[cdata[import flash.external.*; 
Import Mx.controls.Alert; Import mx.rpc.events.ResultEvent; 
Introduce externalinterface public Function Initapp (): void {externalinterface.addcallback ("Saycallback", callBack); 
Public Function CallBack (str:string): string{return "Hello" +STR; 
} protected function Button1_clickhandler (event:mouseevent): void {externalinterface.call (' SayHelloWorld ', ' Jim '); 
var array:array = new Array (); 
Array.push ("A", "B", "C", "D", "E"); 
Myiframe.calliframefunction (' Jsmethod ', Array,function (str:string): void{label.text=str; 
}); } public static FUnction str (): string{return "AAA"; }]]> </fx:Script> <s:vgroup width= "100%" height= "100%" > <s:bordercontainer width= "100%" height= "300 "Backgroundcolor=" #00ffaa "> <s:hgroup width=" 100% "> <s:button label=" Calls JS "click=" Button1_clickhandler ( Event) "/> <mx:button x=" 169.5 "y=" 162 "label=" click "fontsize=" "id=" button "/> <mx:textinput" id= "Asinput" x= " "122" y= "/>" <s:label id= "Label"/> </s:HGroup> </s:BorderContainer> <s:bordercontainer Widt H= "100%" height= "> <code:iframe id=" myiframe "source=" com/myhtml.html "width=" 100% "height=" 100% "/> < /s:bordercontainer> </s:VGroup> </s:Application>

HTML page:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >  

In this way, the HTML JS script can call the as script directly without having to embed the SWF file again.

The above is a small set to introduce ActionScript and JavaScript Interactive instance program (modify), I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

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.