17.1. Communicating with Other Movieson the Same Computer

Problem

You want to communicate from one Flash movie to one or more Flash movies playing on the same client computer.

Solution

Use a LocalConnection object to invoke a function in the receiving movie from the sending movie. Use LocalConnection.connect( ) to listen for messages in the receiving movie and define the function that will be invoked. Use LocalConnection.send( ) from the sending movie to invoke a function on the remote computer. Both the sending and receiving movies must specify the same named channel for communication.

Discussion

When two or more Flash movies are playing on the same client computer, they can communicate with each other via a local connection created with the LocalConnection class. As long as the movies are playing on the same computer, a connection can be made regardless of the domains from which the movies are being served.

Tip

By default, movies accept communications from movies on the same domain only. However, you can configure them to receive from other domains as well. See Recipe 17.4.

To successfully communicate between multiple movies on the same computer you must do three things:

  1. Configure the receiving movie(s) to listen for communications.

  2. Tell the receiving movie(s) what to do when messages are received.

  3. Send messages to the receiving movie(s) from the sending movie.

A receiving movie must listen for messages over a specific, named local connection. To establish this communication channel, ...

Get Actionscript Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.