Flash JavaScript Communication methods Summary _javascript Tips
Source: Internet
Author: User
no Geturl and Fscommand methods . The ActionScript used by Flash is very similar to JavaScript, and the following describes how to invoke each other's functions:
1:javascript call a function in Flash Add in Flash Scripts
Import Flash.external.ExternalInterface;
Suppose the function to invoke is Hello,as code as follows
function Hello () {
return "Hello";
}
Externalinterface.addcallback ("Hello", this, hello);
The first argument is the name of the exported function, and the third parameter is the function name of as, so that you can call the as Hello function in JS
2:flash call JS function Externalinterface.call ("Hello2", "Jacky");
The first parameter is the function name of JS, followed by the JS function parameters
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 (a);
}
function Thismovie (moviename) {
if (Navigator.appName.indexOf ("Microsoft")!=-1) {
return Window[moviename]
}
else {
return Document[moviename]
}
}
Note that you cannot use document.getElementById such functions to get Flash objects in Web pages, only using the code in the Thismovie function
another way to see abroad: Can ' t call a function, but can change/set a variable and use the watch () method to execute the code whenever the V Alue is changed.
ActionScript Code:
function changetype (prop, Oldval, newval) {
Do your Stuff
return newval;
}
var strtype = "";
This.watch ("Strtype", changetype);
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