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