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.