Mutual calls between ActionScript and JavaScript

Source: Internet
Author: User
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]

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.