Summary of communication methods between flash javascript

Source: Internet
Author: User

The getURL and fsCommand methods are not required.
The actionscript used by flash is very similar to javascript. The following describes how to call functions for each other:
1: javascript calls functions in flash
Add in the flash script
Import flash. external. ExternalInterface;
Assume that the function to be called is hello, and the as code is as follows:
Function hello (){
Return "hello ";
}
ExternalInterface. addCallback ("hello", this, hello );
// The first parameter is the name of the exported function, and the third parameter is the name of the as function, so that the as hello function can be called in js.
2: flash calls js Functions
ExternalInterface. call ("hello2", "jacky ");
// The first parameter is the js function name, followed by the js function parameter
3: How to call each other
The html code is as follows:
<Object type = "application/x-shockwave-flash" data = "test.swf" width = "525" height = "390" name = "test">
<Param name = "allowScriptAccess" value = "sameDomain"/>
<Param name = "movie" value = "test.swf"/>
<Param name = "quality" value = "high"/>
<Param name = "scale" value = "noScale"/>
<Param name = "wmode" value = "transparent"/>
</Object>
The javascript code is as follows:
Function callFromFlash (){
Var a = thisMovie ("test"). hello ();
Alert ();
}
Function thisMovie (movieName ){
If (navigator. appName. indexOf ("Microsoft ")! =-1 ){
Return window [movieName]
}
Else {
Return document [movieName]
}
}
// Note: you cannot use the document. getElementById function to obtain the flash object on the webpage. You can only use the code in the thisMovie function.
Another method seen outside China:
You can't call a function, but you can change/set a variable and use the watch () method to execute the code whenever the value is changed.
ActionScript Code:
Function changeType (prop, oldval, newval ){
// Do your stuff
Return newval;
}
Var strType = "";
This. watch ("strType", changeType );

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.