i'm trying to send the mouseY position with
- Code: Select all
conn.send("moveY", mouseY);
and recieve it with
- Code: Select all
connection.addMessageHandler("moveY", function(m:Message, yC:int){
p1.y = yC;
})
i set conn = connection in the handleJoin function and the problem is that i don't recieve any messages, i can see that the bandwidth is increasing when i move the cursor so i guess it's sending stuff to the server. I can see messages when someone connects and the hello message from the server etc but anything i send does not make it.
Here is the full code:
- Code: Select all
package {
import flash.display.MovieClip
import playerio.*
import flash.events.MouseEvent;
public class MyGame extends MovieClip{
var conn:Connection;
function MyGame(){
stop();
PlayerIO.connect(
stage, //Referance to stage
"my game id", //Game id (Get your own at playerio.com)
"public", //Connection id, default is public
"GuestUser", //Username
"", //User auth. Can be left blank if authentication is disabled on connection
null, //Current PartnerPay partner.
handleConnect, //Function executed on successful connect
handleError //Function executed if we recive an error
);
}
private function handleConnect(client:Client):void{
trace("Sucessfully connected to player.io");
//Set developmentsever (Comment out to connect to your server online)
client.multiplayer.developmentServer = "my ip:8184";
//Create pr join the room test
client.multiplayer.createJoinRoom(
"test", //Room id. If set to null a random roomid is used
"MyCode", //The game type started on the server
true, //Should the room be visible in the lobby?
{}, //Room data. This data is returned to lobby list. Variabels can be modifed on the server
{}, //User join data
handleJoin, //Function executed on successful joining of the room
handleError //Function executed if we got a join error
);
}
private function handleJoin(connection:Connection):void{
trace("Sucessfully connected to the multiplayer server");
gotoAndStop(2);
conn = connection;
//Add disconnect listener
connection.addDisconnectHandler(handleDisconnect);
//Add listener for messages of the type "hello"
connection.addMessageHandler("hello", function(m:Message){
trace("Recived a message with the type hello from the server");
})
//Add message listener for users joining the room
connection.addMessageHandler("UserJoined", function(m:Message, userid:uint){
trace("Player with the userid", userid, "just joined the room");
})
//Add message listener for users leaving the room
connection.addMessageHandler("UserLeft", function(m:Message, userid:uint){
trace("Player with the userid", userid, "just left the room");
})
connection.addMessageHandler("moveY", function(m:Message, yC:Number){
trace("recieved:"+m+":"+yC);
p1.y = Number(m);
})
//Listen to all messages using a private function
connection.addMessageHandler("*", handleMessages)
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveP);
}
private function moveP(Event:MouseEvent):void{
p2.y = mouseY;
conn.send("hello");
conn.send("moveY", mouseY);
}
private function handleMessages(m:Message){
trace("Recived the message", m)
}
private function handleDisconnect():void{
trace("Disconnected from server")
}
private function handleError(error:PlayerIOError):void{
trace("got",error)
gotoAndStop(3);
}
}
}
Thank you for your help, i really appreciate it!