Home >Web Front-end >JS Tutorial >Summary of communication methods between flash javascript_javascript skills

Summary of communication methods between flash javascript_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:57:26906browse
Do not use getURL and fsCommand methods
The actionscript used by flash is very similar to javascript. The following describes how to call functions from each other:
1: javascript calls functions in flash
Add
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 exported function name, and the third parameter is the function name of as, so that you can call as in js The hello function
2: flash calls the js function
ExternalInterface.call("hello2", "jacky");
//The first parameter is the js function name , followed by the parameters of the js function
3: How to call each other
html code is as follows:







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 functions such as document.getElementById cannot be used to obtain the flash object in the web page. You can only use the code in thisMovie function
Another method seen abroad:
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);
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn