User Guide
Using Flash and Other Interactive Media Types 307
Setting up callbacks
The next step is to set up callback handlers with the
setCallback() command. You should set
up a callback for each event you expect the object to generate. Local connection objects generate
onStatus and allowDomain events, as well as an event for each incoming message received.
These incoming message events are named by the string that is passed as the subject, or first
parameter, of the message.
To set up each callback, use the
setCallback() command and include the name of the local
connection object, the name of the event to respond to, the Lingo handler name, and the Lingo
script object that contains the handler as arguments with the command.
To set up localConnection callbacks:
1 Set up the onStatus callback. An onStatus event is generated each time a message is sent
by the local connection object and contains information about the success or failure of the
send operation.
sprite(1).setCallback(pLocalConn, "onStatus", #myOnStatus, me)
This Lingo statement sets a callback for the event named onStatus generated by the object
pLocalConn. The Lingo handler name is myOnStatus and the Lingo script object that
contains it is the same script object that contains this
setCallback() command, referred to as
me. Note the quotes around the event name and the pound sign (#) preceding the handler
name. The pound sign converts the handler name to a symbol.
The actual callback handlers, such as the
myOnStatus handler, are illustrated later in
this section.
2 Set up the allowDomain callback. An allowDomain event is generated each time the local
connection object receives an incoming message.
sprite(1).setCallback(pLocalConn, "allowDomain", #myAllowDomain, me)
In this case, the event name is AllowDomain and the handler name is myAllowDomain.
If the myAllowDomain handler determines that the message is coming from an allowed
domain, an event named with the message subject is generated. When a movie is running from
a user’s computer and not in a browser, the domain is
localHost. When the movie is running
in a browser, the domain is determined by the server that hosts the movie, such as
macromedia.com. For more information about allowing domains, see the Flash
Communication Server MX documentation.
3 Set up the callback for these user-defined messages. Decide what string you want to use as your
message subjects, so that you know what the event name will be. In the following example, the
user-defined message subject and event name are
incomingMessage:
sprite(1).setCallback(pLocalConn, "incomingMessage", #myIncomingMessage, me)