1

I've made a app using netconnection and netgroup in Flash CS6. I'm trying to build a simple 2-player multiplayer game. When 2 two players are connected I would like to hide a movieclip in one of the instances of the swf but not the other. How is that done?

It's a turn-based game so when player 1 takes his turn player 2 must not be able to click a button (so I want to hide it) and vice-versa.

hh_s
  • 33
  • 7
  • if you're using a netconnection - why wouldn't you just put logic in the app to allow for showing/hiding objects based on whose turn it is. A simple boolean should suffice. When a player moves, sends call to the other player and tells them it's their turn, and not updating the screen until they've moved – Gone3d Dec 21 '12 at 19:47
  • That's what I'm trying to do. My problem is that when I hide a movieclip it gets hidden in both player windows. Even if I don't post anything. – hh_s Dec 21 '12 at 20:32
  • You might have to show some code here. – Gone3d Dec 21 '12 at 20:36
  • I've used this link to get started: [link](http://indigo-entertainment.com/blogs/view/6/26). `function netStatus(event:NetStatusEvent):void{ switch(event.info.code){ case "NetConnection.Connect.Success": setupGroup(); break; case "NetGroup.Connect.Success": // Do nothing break; case "NetGroup.Posting.Notify": mc.x = event.info.message.x; mc.y = event.info.message.y; //this must be visible in the active players game and hidden in the other ok_mc.visible=false; break; case "NetGroup.Neighbor.Connect": break; } }` – hh_s Dec 21 '12 at 21:03
  • 3
    Simply when your game starts take a variable and assign the current Player's ID to it and share that variable across the peers, and put condition on that variable, so: if(myPlayer ==currentPlayer){//addListeners}else{//removeListeners}, and when the first Players turn is over assign the 2nd Player's ID to the currentPlayer variable and this will go on until you meet a game Over condition. – yawar Dec 21 '12 at 21:06
  • I can't get it to work. I've tried making the player variables and made a simple alpha 0/1 on a movieclip but it doesn't work everytime. I've posted the fla here: [link](http://goo.gl/FL9pV). Open 2 swf's to test. When the mc is dropped in one swf it must hide the OK mc and show it in the other swf and vice versa – hh_s Dec 21 '12 at 23:19

1 Answers1

0

I think it's working now. In the move function I added ok_mc.visible=false which hides the mc in the "local" instance and the put ok_mc.visible=true in the netstatus event. Like this

function drop(e:MouseEvent):void {
this.stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveMe);
// Save the current movieclip position
var obj:Object = {};
obj.x = mc.x ;
obj.y = mc.y ;
obj.activePlayer=players[aktiv-1]
ok_mc.visible=false;

// Set the peerID to a group address suitable for use with the sendToNearest() method.
obj.sender = group.convertPeerIDToGroupAddress(nc.nearID);
obj.id = new Date().time;
// Sends a message to all members of a group.
group.post(obj);
}

function netStatus(event:NetStatusEvent):void{
switch(event.info.code){
    case "NetGroup.Posting.Notify":

        mc.x = event.info.message.x;
        mc.y = event.info.message.y;
        ok_mc.visible=true;
    break;
}
}

It seems to work. Now I just have to figure out to show it at init in the first instance. Is there a way to count groupmembers and/or loop through them?

hh_s
  • 33
  • 7