1. as and js communication instances
If as3 calls a function in JAVAscript, add it directly in.
If (ExternalInterface. available ){
ExternalInterface. call ("sendToJavaScript", value );
}
ExternalInterface. available mainly checks whether the player is in a container that provides external interfaces. If swf is not in the webpage, ExternalInterface. call transmits parameters to the external api.
SendToJavaScript is the function name (custom) value in js.
You can try to add
<Script type = "text/javascript">
Function sendToJavaScript (value ){
Alert (value)
}
</Script> in this way, the value in flash will pop up with alert, which is only the first step. Of course, we recommend that you use try to throw an error during testing.
2. js and as communication instances
Write data to a webpage
<Script type = "text/javascript">
Function thisMovie (movieName ){
If (navigator. appName. indexOf ("Microsoft ")! =-1 ){
Return window [movieName];
} Else {
Return document [movieName];
}
} // Judge the browser
Function sendToActionScript (value ){
ThisMovie ("flash Animation name"). sendToActionScript (value );
}
</Script>
<Form name = "form1">
<Input type = "text" name = "input" value = ""/>
<Input type = "button" value = "Send"/> <br/>
</Form>
Note: The flash Animation name includes the flash in the webpage. In objct, the id must also be the flash name.
If (ExternalInterface. available ){
Try {
ExternalInterface. addCallback ("sendToActionScript", receivedFromJavaScript );
} Catch (e: Error ){
Trace (e. message )}
} Else {
Trace ("External interface is not available for this container .");
} // End if
Note that when developing the game, we may directly send a request to end the game and use js to process the request and return a result. In this case, flash cannot read the result. Of course, you can make button request capability as event mechanism problems,
In addition, thisMovie ("flash Animation name"). sendToActionScript (value); a function must be written separately after sendToJavaScript (value) and then called.