Flex Javascript communication

Communication between JavaScript and Flex applications can be done in many ways. Using SWFAddress and communicate with the help of the uri or using ExternalInterface flash communication interface are the most used.

The disadvantages of using SWFAddress is that the communication is slow and it had to change the uri, which is not always something the developer needs. In general the the Flex application listens for uri changes, simply by setting a timeout for a listener with very short period of time, like 10 milliseconds, and if some change occurs get’s the uri, parses it and process the changes.

From the beginning the hard-coded listening of the uri change is not a good idea. Even for very short timeouts it become risky when the user can click and skip an important refresh inside the flex application.

I strongly recommend the use of the build in ExternalInterface. The communication via ExternalInterface can be done in both directions to JavaScript to Flex and vice versa, which is the main advantage is the lack of programmatically added listening processes. Here all it’s done by the interface and the response from the other side is guaranteed.

There are tricky parts, of course, but in general it’s a secure and reliable way to talk between these two technologies.

A sample of the process you can find here.

5 thoughts on “Flex Javascript communication

  1. Communication using SWFAddress is appropriate only if the application requires deep linking. It doesn’t require any timeouts on the Flex side since there is an event dispatched on each address change.

  2. And than how the Flex app knows about changes in the uri? The SWFAddress is listening about this kind of changes by running the uri parsing function every N milliseconds. That is done with a timer, of course with given timeout.


  3. There is a timer inside the JavaScript part of SWFAddress which listens for changes of the address. It’s used in Firefox, Safari and Opera but Internet Explorer doesn’t require it. Soon all these browsers will implement a new HTML5 feature that will allow us to skip this interval checks completely.

    The ActionScript part of SWFAddress receives notifications using ExternalInterface and does not constantly listen for changes.

  4. I’d agree with you. Actually more problems rise when the timeouts are set programmatically. The lack of a built in functionality discourages more than helps to use SWFAddress.

    best regards

Leave a Reply

Your email address will not be published. Required fields are marked *