Remote SharedObject 101: Take one|”sharedball”

/*
* The position of the sharedball can be updated by client or by other clients.
When the client updates the sharedball position, simply render and display the ball. The client also needs
to update the Model (RSO) and the Model will broadcast all the changes via “onSync” events to other clients that is connected to the Model;
The updates from other clients are accomplished by RSO “onSync” handler.
*/

var sharedBall_mc;
var nc = new NetConnection();
var rso;

nc.onStatus = function(info){
switch(info.code){
case “NetConnection.Connect.Success”:
rso = SharedObject.getRemote(“position”, nc.uri);
rso.onSync = function(list){
for(var i in list){
var info = list[i];
updateMC();
}
}
rso.connect(nc);
break;
}
}

sharedBall_mc.onPress = function(){
this.startDrag();
this.onMouseMove = function(){
updateModelBy(this);
}
};
sharedBall_mc.onRelease = sharedBall_mc.onReleaseOutside= function(){
this.stopDrag();
delete this.onMouseMove;
}
function updateModelBy(mc){
rso.data.ball_x = mc._x;
rso.data.ball_y = mc._y;
}

function updateMC(){
sharedBall_mc._x = rso.data.ball_x;
sharedBall_mc._y = rso.data.ball_y;
}

nc.connect(“rtmp:/tutorial_sharedball”, false);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: