O'Reilly logo

Actionscript Cookbook by Joey Lott

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required