O'Reilly logo

ActionScript 3.0 Cookbook by Joey Lott, Darron Schall, Keith Peters

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

Creating Local Connections

Problem

You want to communicate from one or more Flash movie(s) to another Flash movie playing on the same client computer.

Solution

Use the LocalConnection class in the flash.net package 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(s) to invoke a function in the remote movie. 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 one another via a local connection created with the flash.net.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 18.4.

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

  1. Configure the receiving movie to listen for communications.

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

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

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