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

Sending Data

Problem

You want to send data to one or more movies playing on the same computer.

Solution

Pass the data as additional parameters to the send() method of the sending local connection object.

Discussion

You can send data to another movie using a local connection by passing the data as additional parameters to the send() method of the sending local connection object. The send() method requires at least two parameters: the name of the connection and the name of the method to invoke on the receiving movie. Any additional parameters passed to the send() method are automatically passed as parameters to the receiving movie’s method. Note that the name of the method you are invoking on the receiving movie cannot be one of the built-in method or properties of the LocalConnection class, or the send() call will fail. The built-in method and property names that cannot be used as the method name parameter are send, connect, close, allowDomain, allowInsecureDomain, client, and domain.

You should define the receiving method so it accepts the parameters sent to it. In this example, a local connection receiver class is created that contains a method named example(). The method expects three parameters: str, num, and bool; for example:

package {

  import flash.net.LocalConnection;

  public class ExampleReceiver {

    private var _receiver:LocalConnection;

    public function ExampleReceiver() {
      // Instantiate the local connection receiver and listen on the 
      // "_exampleChannel" channel for other movies ...

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