Accessibility

Director Article

 

Making Connections—Simple Use of LocalConnection Objects


Table of Contents

About LocalConnection Objects

LocalConnection objects were first introduced as part of Macromedia Flash Player 6 and the initial release of Macromedia Flash Communication Server MX, but due to the fact that they are officially supported as part of Flash Player 6, that also means the feature is ready for use within Flash MX authoring and projectors as well. Subsequently support for LocalConnection object usage was then also included in the Director MX release and the accompanying update to Shockwave Player 8.5. Support for LocalConnection objects continues today in the current versions of Macromedia Flash and the Flash Player as well as the current versions of Director and the Shockwave Player.

Note: The Macromedia Director MX release did not involve a major player version update and therefore the content it produces is playable within Shockwave Player version 8.5. However it's important to note that to use LocalConnection objects, or any other Flash Player 6 functionality, the user will require the Flash Asset Xtra as it has been shipped in the Director MX and later releases. Therefore developers using this functionality in Director MX need to ensure an appropriate version of the Xtra is available by making use of the Xtra’s auto-downloading mechanism in the Shockwave Player.

LocalConnection objects are simple script-based objects that are created to allow inter-movie communication for files all running on a single client machine. The object allows you to define callback functions to handle a pair of pre-defined events in addition to allowing you to specify callback functions for custom events, which can then be triggered by sending messages between movies. The act of sending a message involves three pieces of information: the name of the intended recipient LocalConnection object, the name of the event to be triggered in the receiving object, and a string containing the message contents. When the recipient object detects the incoming message, it first has an opportunity to check the domain of the sending LocalConnection object thus allowing the ability to limit communication to specific domains. If the receiving client accepts the incoming message, the appropriate event is generated using the event name provided as part of the message itself. If a callback function for that event has been defined, that function is called and the actual message contents are passed to it, which can then be processed as needed.

There are a few important bits of information to remember when working with LocalConnection objects:

  • They only allow communication between movies and/or projectors that are all running on the same client machine. LocalConnection objects do not use outbound communications, nor do they offer the ability to establish outbound communications to other computers.
  • They allow communication between any two or more pieces of Director and/or Macromedia Flash content. This includes all environments (authoring, projectors, and browser playback).
  • Each LocalConnection object must use a unique name when preparing itself to send/receive messages.
  • Messages are to specific individual LocalConnection objects only. There is no group or batch messaging built-in. You must write code to handle that.
  • In Director and Shockwave Player, support for LocalConnection objects is provided through the Flash Asset Xtra and therefore the Flash Asset Xtra must be present to use this functionality.
  • In Director and Shockwave Player, there are two ways of creating LocalConnection objects—as global objects or as Flash sprite-associated objects. Both options provide identical functionality, and the only difference in syntax between the two occurs when creating the LocalConnection object itself.

So the basic structure and usage model of LocalConnection objects is rather clear—you create an instance of the object in each movie or projector, and instructions can be sent between client movies as needed. To help clarify any remaining questions about LocalConnection objects and to see them in action, I'll now discuss how to implement these objects in the context of the provided example files. These files are rather simple in that they allow two, and only two, separate movies to "chat" with each other. That is, they send and display simple text messages to each other. While this isn't the most interesting example to look at (who chats with oneself?), it should prove to illustrate the capabilities of LocalConnection objects.