Coding as3 problem

All Union Platform questions, comments, feature requests, and bug reports.

Coding as3 problem

Postby JoacoSaralegui » Mon 09 Jun 2014 10:00

Hello, i have this problem: i ve design a mcPlayer class and a mcEnemy class, with their specific movieclips attached, and when i try to acces some of the attributes, they seem to be 0, but i have set them values that are diferent to 0.

Here is the code

protected function readyListener (e:ReactorEvent):void {

gameRoom = reactor.getRoomManager().createRoom("gameRoom");

gameRoom.addEventListener(RoomEvent.JOIN, joinRoomListener);

gameRoom.addEventListener(RoomEvent.ADD_OCCUPANT, addClientListener);

gameRoom.addEventListener(RoomEvent.REMOVE_OCCUPANT, removeClientListener);

gameRoom.join();

}


protected function joinRoomListener (e:RoomEvent):void {

for each (var client:IClient in gameRoom.getOccupants()) {

if(client.getClientID() != reactor.self().getClientID()){

enemy.x = Number(client.getAttribute("X_POSITION"));
enemy.y = Number(client.getAttribute("Y_POSITION"));
stage.addChild(enemy);

}
}

}
// Method invoked when a client joins the room
protected function addClientListener (e:RoomEvent):void {
//Si el cliente que entra es el mismo usuario
if (e.getClient().isSelf()) {

var player:MovieClip = new mcPlayer();
stage.addChild(player);
player.x = Math.floor(Math.random() * 550) + 0;
player.y =Math.floor(Math.random() * 400) + 0;

var self:IClient = reactor.self();
self.setAttribute("X_POSITION", String(player.x));
self.setAttribute("Y_POSITION", String(player.y));
}
else {
if (gameRoom.getSyncState() != SynchronizationState.SYNCHRONIZING) {

// Show a "guest joined" message only when the room isn't performing
// its initial occupant-list synchronization.
enemy.x = Number(e.getClient().getAttribute("X_POSITION"));
enemy.y = Number(e.getClient().getAttribute("Y_POSITION"));
stage.addChild(enemy);
nameInput.text = ("" + enemy.x+ "/" + enemy.y + "");

}
}
}
//Method invoked when a client leaves the room
protected function removeClientListener (e:RoomEvent):void{
removeChild(enemy);
}

The problem is in the second part of the addClientListener function the enemy show up on coordenates x = 0 and y= 0, instead of the coordenates that i had stablished before.

Anyone knows what should i do?
JoacoSaralegui
 
Posts: 1
Joined: Mon 09 Jun 2014 09:51

Return to Union Platform

Online

Users browsing this forum: No registered users and 9 guests