Chapter 11
308
Writing callback handlers
Now the callbacks are set up. In order for them to work, however, you must write the callback
handlers themselves. While the
setCallback()
commands are all inside a
beginSprite
handler
in this example, the callback handlers must be outside the
beginSprite
handler because they are
handlers by themselves. In this example, the callback handlers are located in the same Lingo script
attached to the Flash sprite, just after the
beginSprite
handler.
The
onStatus
event is generated each time the local connection object sends an outgoing
message. The
myOnStatus
handler might look like this:
on myOnStatus (me, aInfoObject)
if (aInfoObject[#level] = "error") then
member("chat input").text = "Error sending last message."
else
member("chat output").text = member("chat output").text & RETURN & \
member("chat input").text
end if
end myOnStatus
Two arguments are passed with the
onStatus
event by the local connection object. The
me
argument tells Lingo that the event was generated on the same Lingo script object that contains
the
myOnStatus
handler. The
aInfoObject
argument contains a Flash array object containing
information about the status of the message sending operation. The handler checks to see if the
aInfoObject
argument contains an error. In this example, if there is an error, an error message is
displayed in a chat input field. If no error occurs, a text output field is updated with the contents
of the chat input field. For more information about the Flash
infoObject
, see the Flash
Communication Server MX documentation.
The
allowDomain
event is generated each time the local connection object receives an incoming
message. This provides an opportunity for the
myAllowDomain
callback handler to determine
whether the message is coming from a trusted domain. The
myAllowDomain
callback handler
must return
TRUE
in order for the incoming message to be processed.
The
myAllowDomain
handler might look like this:
on myAllowDomain (me, aSendingDomain)
if aSendingDomain = "myDomain.com" then
return TRUE
else
member("chat output").text = & RETURN & "Message received from \
unapproved domain."
return FALSE
end if
end myAllowDomain
The handler checks that the domain is the one that is expected, and returns TRUE if it is. If the
message comes from another domain, the return value is FALSE.
Once the
allowDomain
callback has returned
TRUE
, the local connection object forwards the
incoming message to the callback handler set up for the event. In this example, the subject of the
message is
incomingMessage
and the callback handler is
myIncomingMessage
.
The
myIncomingMessage
handler might look like the following:
on myIncomingMessage (me, aObject, aMessage)
member("chat output").text = & RETURN & aMessage
end myIncomingMessage
This handler simply appends the incoming message
aMessage
to the end of a chat output field.
Summary of Contents for DIRECTOR MX-USING DIRECTOR MX
Page 1: ...Using Director MX Macromedia Director MX...
Page 12: ...Contents 12...
Page 156: ...Chapter 4 156...
Page 202: ...Chapter 6 202...
Page 244: ...Chapter 7 244...
Page 292: ...Chapter 10 292...
Page 330: ...Chapter 12 330...
Page 356: ...Chapter 13 356...
Page 372: ...Chapter 14 372...
Page 442: ...Chapter 16 442...
Page 472: ...Chapter 18 472...
Page 520: ...Chapter 19 520...
Page 536: ...Chapter 20 536...
Page 562: ...Chapter 23 562...
Page 566: ...Chapter 24 566...
Page 602: ...Chapter 27 602...