17.2. Sending Data Using Local Connections

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 methods of the LocalConnection class, such as send, connect, etc. For a complete list of the built-in methods of a local connection, see the “Language Reference” section of ActionScript for Flash MX: The Definitive Guide, or the Reference panel (Window Reference) in Flash.

You should define the receiving method so it accepts the parameters sent to it. In this example, the receiving movie contains a local connection with a method named myMethod( ). The method expects three parameters: str, num, and bool.

receiving_lc = new LocalConnection( ); receiving_lc.connect("_myConnection"); receiving_lc.myMethod = function (str, num, bool) { _root.output_txt.text = "The parameters are: " + str + newline + num + newline + bool; ...

Get Actionscript Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.