Mutual calls between ActionScript and JavaScript
Let's talk about developing flexProgramAs and JS communication problems
1. As calls JS
As is a simple method to call Js. You can directly call this method by using externalinterface. Call.
For example: Externalinterface. Call ('Alert','1901');
The first parameter is the JS function name, and the second parameter is the parameter required by the function.
2. js calls the
To call as in JS, you must first add the callback function in externalinterface. addcallback in.
For example: Externalinterface. addcallback ("Function1", Callback1 );
The first parameter is the name of the function to be called by JS, and the second parameter is the function to which the function is called.
After adding the callback function and the callback function, the as part is completed, and then the JS part is completed.
First, find the object tag embedded in flash in HTML and find the ID of this object tag,
Then, the function in as is called directly using ID. functionname.
Example Code : Function Invokeflexfunctions ()
{
// Test is the ID of the object tag embedded in flash.
Test. function1 ();
Test. function2 ( " Hello, 1901 !~ " );
Alert (test. function3 ());
}
Add: If you need to call a method in as when the page is closed, you can use the following method:
Window. onbeforeunload = Function ()
{
Alert (test. function3 ());
}
========================================================== ======================================
If you do not know what I said, you can download the attachment at the end of the text and view the sample code directly.
[Attachment download]