Listing 1
-- (movie script)
Global text_so
on StartMovie me
the keyUpScript = "textChanged"
member("DirTypingStage").text = " "
end
on textChanged me
if (the key) = Return then member("DirTypingStage").text = ""
text_so.data.textValue = member("DirTypingStage").text
end
Listing 2
-- flash sprite's script (behavior script)
property pSprite
property pNetConn
global text_so
on beginSprite me
-- initialize a sprite reference
pSprite = sprite("myFlashSpriteName")
end
on exitFrame (me)
-- initiate the connection if necessary
if voidP(pNetConn) then
me.initiateConnection()
end if
end exitFrame
on initiateConnection (me)
-- create a new NetConnection object
pNetConn = pSprite.newObject("NetConnection")
-- declare an onStatus callback handler
pSprite.setCallback(pNetConn,"onStatus",#myOnStatus,me)
-- connect the object to the server
pNetConn.connect("rtmp://localhost/dir_text/Room01")
-- get shared object from flash object
tSharedObject = pSprite.getVariable("SharedObject", false)
text_so = tSharedObject.getRemote("sharedtext", pNetConn.uri, false)
text_so.connect(pNetConn)
-- declare an onSync callback handler
pSprite.setCallback(text_so, "onSync", #syncTexts, me)
end initiateConnection
on myOnStatus (me, this, aInfo)
put "Level: " && aInfo.level && "Code:" && aInfo.code
if (aInfo.code = "NetConnection.Connect.Success") then
-- Continue
else
-- Alert Message
end if
end myOnStatus
on syncTexts(me, this, aList)
Repeat with i = 0 to (i < aList.length)
if (alist[i].name = "textValue" AND alist[i].code <> "success") then
member("DirTypingStage").text = text_so.data.textValue
exit repeat
end if
end repeat
end
on endSprite me
-- close the connection
pNetConn.Close()
end
Listing 3
-- flash sprite's script (behavior script)
property pSprite
property pNetConn
global ball_so
on beginSprite me
-- initialize a sprite reference
pSprite = sprite("myFlashSpriteName")
end
on exitframe me
-- initiate the connection if necessary
if voidP(pNetConn) then
me.initiateConnection()
end if
end
on initiateConnection (me)
-- create a new NetConnection object
pNetConn = pSprite.newObject("NetConnection")
-- declare an onStatus callback handler
pSprite.setCallback(pNetConn,"onStatus",#myOnStatus,me)
-- connect the object to the server
pNetConn.connect("rtmp://localhost/dir_sharedball/Room01")
-- get shared object from flash object
tSharedObject = pSprite.getVariable("SharedObject", FALSE)
ball_so = tSharedObject.getRemote("position", pNetConn.uri, false)
ball_so.connect(pNetConn)
-- declare an onSync callback handler
pSprite.setCallback(ball_so, "onSync", #syncball, me)
end initiateConnection
on myOnStatus me, this, aArg2
put "Level: " && aInfo.level && "Code:" && aInfo.code
if (aInfo.code = "NetConnection.Connect.Success") then
-- Continue
else
-- Alert Message
end if
end myOnStatus
on syncball(me, this, aList)
Sprite("Ball").LocH = ball_so.data.x
Sprite("Ball").LocV = ball_so.data.y
end
on EndSprite me
-- close the connection
pNetConn.Close()
end
Listing 4
-- ball sprite's script (behavior script)
global isMouseDown
on MouseDown me
isMouseDown = True
end
on MouseUp me
isMouseDown = False
end
Listing 5
-- (frame script)
global ball_so
global isMouseDown
on exitFrame me
if isMouseDown then
ball_so.data.x = sprite("Ball").LocH
ball_so.data.y = sprite("Ball").LocV
end if
if Sprite("Ball").rect[1] <= 0 then
Sprite("Ball").LocH = Sprite("Ball").LocH + 50
end if
if Sprite("Ball").rect[2] <= 0 then
Sprite("Ball").LocV = Sprite("Ball").LocV + 50
end if
if Sprite("Ball").rect[3] >= 640 then
Sprite("Ball").LocH = Sprite("Ball").LocH - 50
end if
if Sprite("Ball").rect[4] >= 480 then
Sprite("Ball").LocV = Sprite("Ball").LocV - 50
end if
go to the frame
end