Archive for the ‘ServerSide ActionScript’ Category

Remote SharedObject 101: Take one|”sharedball”

April 12, 2007

/*
* 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