Flex and JavaScript interoperability

Flex and JavaScript interoperability

Flex generated swf file will eventually be deployed to ActiveX pages (html, jsp, asp, aspx, etc.), because ActiveX is an independent body it can not directly access the page element data, same asp, aspx, etc. Service is not responsible for client code operate it, so Flex's interactive information becomes very isolated. Web user program at the different pages of information exchange is very important, and often the information should be clear what the next page; if Flex then obtain copies of these information at the practical application of Flex on the greatly reduced! So look online to find information, they found that their worries are unnecessary. Flex objects provide flexibility to the current Web page and JavaScript to call each other and flexible. That is to say through the JavaScript method called intra-Flex, Flex at same time can also directly call the page-related JavaScript methods.

Flex provides the ExternalInterface and JavaScript object used to carry out interoperability. Subjects were provided addCallBack and Cell Methods:

Ways addCallBack

Register for an internal method used to call JavaScript.

function callMe (name: String): String (

return name + ":" + txtUserName.text;


Are in fact JavaScript should not directly call the internal methods of Flex, then how to make the JavaScript can call it?

First of all, through ExternalInterface.addCallback ( "myFunction", callMe); Registration methods can be put on the Ways Applicaion. Initialize the incident.

Ways the first parameter is: name of the external call is JavaScript method name to call.

The second parameter is the Ways: Flex agent implementation of the internal function.

JavaScript calls the following ways:

function Button1_onclick () (

alert (document.all ( 'related to ActiveX controls Name'). myFunction ( 'bbq'));


Call Ways

Used to call the current page in the JavaScript method.

<Script id = "clientEventHandlersJS" language = "javascript">

function getuserid ()


return 'henry';


</ Script>

In Flex you can call the following ways getuserid () method.

var id: String = ExternalInterface.call ( "getuserid");

Alert.show (id);

Flex and JavaScript interoperability

Flex and JavaScript interoperability

Flex and JavaScript integration at work has been done very well, you do not need to spend too much on the job be able to achieve and page data elements for data exchange; same can also have some ajax function call.

Next page study different examples of how the Flex application to share information.

Finally an old one or are interested to know many friends in Flex.

Flex the SDK Help file written quite detailed, basically to find the methods used.

分类:AJAX 时间:2009-03-08 人气:960
blog comments powered by Disqus


iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.037 (s). 11 q(s)