Call JavaScipt or be called by JavaScript

Source: Internet
Author: User
Call JavaScipt or be called by JavaScript I. Call the Flex method in JavaScript
In Flex, you can use ExternalInterface to call the Flex method by adding the specified public method to the callable method list of the Flex application. In a Flex application, you can call addCallback () to add a method to this list. AddCallback registers an ActionScript method as a method that can be called by JavaScript and VBScript.
The addCallback () function is defined as follows:
AddCallback (function_name: String, closure: Function): void
The function_name parameter is the method name called by the script on the Html page. The closure parameter is the local method to be called. This parameter can be a method or an object instance.

For example:

Import flash. external .*;
Public function myFunc (): Number {
Return 42;
}
Public function initApp (): void {
ExternalInterface. addCallback ("myFlexFunction", myFunc );
}

On the Html page, obtain the reference of the SWF object, that is, useThe Id attribute of the declared Swf, for example, MyFlexApp. Then you can use the following method to call the method in Flex.

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.