
ADOBE DIRECTOR 11.0
User Guide
208
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 the following:
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 appends the incoming message
aMessage
to the end of a chat output field.
Sending messages and closing the connection
To complete your script, finish the
beginSprite
handler and write handlers for sending messages from the object
and closing the connection when you are finished using it.
•
To finish the
beginSprite
handler that already contains the
newObject()
method and all the
setCallback()
methods, add a
connect()
method. This is actually a Flash ActionScript method that you send to the local
connection object you created.
pLocalConn.connect(pCon_name)
The argument
pCon_name
gives the actual connection a name, “userA”, that was declared at the beginning of the
script.
•
To send messages, write a handler that uses the
send()
method of the local connection object:
on sendMessage (me, aMessage)
tMessage = pCon_name && ":" && aMessage
pLocalConn.send(pOtherCon_name, "incomingMessage", tMessage)
end sendMessage
The
send()
method requires three arguments: the recipient of the message, the event to be triggered when the
message is received, and the message itself.
•
To close the connection, write a handler that uses the
close()
method of the local connection object, as follows:
on closeConnection (me)
pLocalConn.close()
end closeConnection
You can call a handler from any other handler by using the following statement:
Содержание 65036570 - Director - PC
Страница 1: ...i ADOBE DIRECTOR 11 USER GUIDE...