Using the Flash local connection object
195
The callback handler could look like the following:
on dirOnStatusHandler (me, aInfoObject)
if (aInfoObject[#level] = "error") then
member("chat input").text = "Error sending last message."
end if
end
Using the Flash local connection object
Flash includes an object type called local connection. The Flash local connection object can be
very useful for allowing separate movies on the same computer to connect to and communicate
with each other. Because the local connection object is a Flash object supported in Director, it can
allow communication between separate Flash content, Director movies, or combinations of the
two. You can use the messaging capability of the local connection object for simple tasks such as
exchanging sprite property data, or for more complex ones such as exchanging chat messages
when used in conjunction with the Flash Communication Server. For more information, see
“Using Flash Communication Server MX 2004” on page 198
.
To use the local connection object, you can either create a global local connection object or
associate the object with a Flash sprite in the Score. Once you have created the object, you can
control it entirely through script. The following are examples of a script that is attached to a Flash
sprite in channel 1 of the Score. The script contains a
beginSprite
handler and other handlers
that manage the local connection object.
Initialize properties
The first thing to do is declare some properties that you will use throughout the local connection
script to store references to the local connection object and 2 connections, one outgoing and
one incoming.
•
The property
pCon_name
stores the name of an outgoing connection
•
The property
pOtherCon_name
stores the name of an incoming connection
•
The property
pLocalCon
stores a reference to the local connection object
The beginning of the script might look like this, including the start of the
beginSprite
handler:
property pCon_name
property pOtherCon_name
property pLocalCon
on beginSprite (me)
pCon_name = "userA"
pOtherCon_name = "userB"
Creating the local connection object
The next step is to create a new local connection object. Once the object is created, you can use
the
setCallback()
method to set up handlers to respond to the events that the local connection
object generates. You can then also use the methods of the local connection object to connect to
other movies and send messages.
•
To create the new local connection object, use the
newObject()
method:
pLocalConn = sprite(1).newObject("LocalConnection")
This script assigns the property
pLocalConn
to be a reference to the newly created object.
Summary of Contents for DIRECTOR MX 2004-USING DIRECTOR
Page 1: ...DIRECTOR MX 2004 Using Director...
Page 16: ...16 Chapter 1 Introduction...
Page 82: ...82 Chapter 3 Sprites...
Page 98: ...98 Chapter 4 Animation...
Page 134: ...134 Chapter 5 Bitmaps...
Page 242: ...242 Chapter 10 Sound and Synchronization...
Page 274: ...274 Chapter 11 Using Digital Video...
Page 290: ...290 Chapter 12 Behaviors...
Page 302: ...302 Chapter 13 Navigation and User Interaction...
Page 334: ...334 Chapter 15 The 3D Cast Member 3D Text and 3D Behaviors...
Page 392: ...392 Chapter 16 Working with Models and Model Resources...
Page 418: ...418 Chapter 18 Movies in a Window...
Page 446: ...446 Chapter 22 Managing and Testing Director Projects...