How Flex and JavaScript interact
It is believed that many inexperienced people have no idea about how to interact with Flex and JavaScript. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
In the process of learning Flex, you may encounter the problem of interaction between Flex and JavaScript, here to share with you, mainly including Flex calling functions in JavaScript and JavaScript calling functions in Flex.
Flex interacts with JavaScript
Flex interacts with JavaScript, mainly relying on Flex's ExternalInterface, which provides addCallBack and call methods.
◆, let's take a look at the functions in JavaScript called by Flex.
FlexConnectJavaScript.mxml
Add functionreturnTheName (a) {return "HUANGXI";} / to FlexConnectJavaScript.html
Summary
1.ExternalInterface.call ("returnTheName", "huangxi"), where * parameters are the same as the function in JavaScript, and the second argument is the passing parameter.
◆, let's take a look at JavaScript calling functions in Flex.
JavaScriptConnectFlex.mxml
Add calculation to JavaScriptConnectFlex.html. Add functionaddMethod () {vars=JavaScriptConnectFlex.addTo100 (); alert (s);} /
1.ExternalInterface.addCallback ("addTo100", add); defines methods that can be called by JavaScript
two。 It can be seen that JavaScript wants to call the Flex function, Flex needs to declare it, while Flex does not need to call the JavaScript function.
After reading the above, have you mastered how Flex and JavaScript interact? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!