The SharedBall sample creates a temporary remote shared object. It's similar to a multiplayer game. When one user moves the ball, it moves for all other users.
RootInstall/applications/SharedBall
Be sure to look at the SharedBall.as sample file. These steps present only highlights.
public class SharedBall extends MovieClip {...}
The class must extend MovieClip, because the sharedBall symbol in the FLA file is a Movie Clip symbol.
public function SharedBall()
{
nc = new NetConnection();
addEventListeners();
nc.connect("rtmp://localhost/SharedBall");
}
private function addEventListeners() {
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
// sharedBall is defined in the FLA file
sharedBall.addEventListener(MouseEvent.MOUSE_DOWN, pickup);
sharedBall.addEventListener(MouseEvent.MOUSE_UP, place);
sharedBall.addEventListener(MouseEvent.MOUSE_MOVE, moveIt);
}
switch (event.info.code)
{
case "NetConnection.Connect.Success":
trace("Congratulations! you're connected");
so = SharedObject.getRemote("ballPosition", nc.uri, false);
so.connect(nc);
so.addEventListener(SyncEvent.SYNC, syncHandler);
break;
...
}
function moveIt( event:MouseEvent ):void {
if( so != null )
{
so.setProperty("x", sharedBall.x);
so.setProperty("y", sharedBall.y);
}
}
When the remote shared object is updated, it dispatches a sync event.
private function syncHandler(event:SyncEvent):void {
sharedBall.x = so.data.x;
sharedBall.y = so.data.y;
}
You can read the value of so.data, even though you can't write to it.