Hi i am trying to develop a multiplayer game using the flash media server. Currently i can get multiple users to control one shared object but i need to have 2 users controlling seperate shared objects on the same stage.
Here is my code so far:
// Create a connection
netConn = new NetConnection();
netConn.connect(serverPath);
keysObject = SharedObject.getRemote(“keyboardStatus”, netConn.uri, false);
keysObject.connect(netConn);
var keyListener:Object = new Object();
Key.addListener(keyListener);
var goLeft = false;
var goRight = false;
**stop(); **
**netConn.onStatus = function(info) **
**{ **
**if (info.code == “NetConnection.Connect.Success”) **
{
trace("Sucessfully connected to server " + serverPath);
}
**else **
{
trace(“Connection to server " + serverPath + " failed”);
}
}
**keysObject.onSync = function(list) **
{
key = keysObject.data.key;
isKeyDown = keysObject.data.isKeyDown;
if (isKeyDown) //Only move it if key down.
{
switch (key) //Switch is just a fancy if - Nigel
{
case 37 : //Left arrow.
goLeft = true;
break;
case 39 : //Right arrow.
goRight = true;
break;
}
}
else
goLeft = goRight = false; //Stop stuff moving.
}
**keyListener.onKeyDown = function() **
{
var key = Key.getCode();
**keysObject.data.isKeyDown = true; **
keysObject.data.key = key;
}
**keyListener.onKeyUp = function() **
{
keysObject.data.isKeyDown = false; //Tell SO key is down.
}
**onEnterFrame = function () **
{
**if (goLeft) **
{
tt._x -= 5;
//positionObject.data.posX = tt._x; //Don’t send every frame any more.
}
**if (goRight) **
{
tt._x += 5;
//positionObject.data.posX = tt._x; //Don’t send every frame any more.
}
}
[COLOR=red]PLEASE HELP!!![/COLOR]