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)
Содержание DIRECTOR MX-USING DIRECTOR MX
Страница 1: ...Using Director MX Macromedia Director MX...
Страница 12: ...Contents 12...
Страница 156: ...Chapter 4 156...
Страница 202: ...Chapter 6 202...
Страница 244: ...Chapter 7 244...
Страница 292: ...Chapter 10 292...
Страница 330: ...Chapter 12 330...
Страница 356: ...Chapter 13 356...
Страница 372: ...Chapter 14 372...
Страница 442: ...Chapter 16 442...
Страница 472: ...Chapter 18 472...
Страница 520: ...Chapter 19 520...
Страница 536: ...Chapter 20 536...
Страница 562: ...Chapter 23 562...
Страница 566: ...Chapter 24 566...
Страница 602: ...Chapter 27 602...