Add up Flash (8)-ActionScript 3.0 Web page acquisition parameters, JavaScript and ActionScript call each other
Introduced
Demonstrates using Flash ActionScript 3.0 to get configuration parameters, page parameters, and the interaction between JS and as
Parameter fetch-Gets the configuration parameter (flashvars) via Application.application.stage.loaderinfo.parameters[param, and gets the URL parameter via JavaScript
Interacting with JavaScript-using Externalinterface to make calls between ActionScript and JavaScript
Flash End
Main.as
/**//* * Note: * 1, if you need Flash and JavaScript interaction, then the HTML tag containing the SWF file must have ID * 2, such as Cross-domain call, you need to set the relevant plug-in parameters, such as <param name= "all
Owscriptaccess "value =" Always "/> * 3, Flash end related security class configuration: Similar to Flash.system.Security.allowDomain (" * ");
* * Package {import Flash.display.MovieClip;
Import Flash.external.ExternalInterface;
public class Main extends MovieClip {public Function main (): void {Loadvarsdemo ();
Ascalljs ();
Jscallas ();
//Get the parameters for the page-side configuration//The following example is used to read the following configuration on the page side//<param name= "Flashvars" value= "name=webabcd&age=29" />//<param name= "movie" value= "demo.swf?dateofbirth=1980-02-14"/> Private Function Loadva
Rsdemo (): void {lblvars.text = "name:" + stage.loaderinfo.parameters["name"] + "" + "Age:" + stage.loaderinfo.parameters["" "+" "+" Birthday: "+ Stage.loaderinfo. parameters ["dateOfBirth"];
Lblswfurl.text = Stage.loaderInfo.url; }//ActionScript invokes JavaScript private function Ascalljs (): void {//Invoke specified JavaScript
The function of the end, and sequentially specifies the parameters passed to the JavaScript End Function Externalinterface.call ("Jsmethod", "param1", "param2");
}//JavaScript called ActionScript, ActionScript-side functions Private Function Jscallas (): void {
Registers a function that needs to be called by JavaScript Externalinterface.addcallback ("Asmethod", output); Public function output (p1:string, p2:string): void {lblresult.text = "parameter 1:" + p1 + "Parameter 2:" + P2}}}