AS3如何控制对等实例swf中的movieclip?

时间:2012-12-21 18:12:53

标签: actionscript-3 flash p2p netconnection

我在Flash CS6中使用netconnection和netgroup创建了一个应用程序。我正在尝试构建一个简单的2人多人游戏。当连接2个两个玩家时,我想在swf的一个实例中隐藏一个movieclip而不是另一个。怎么做的?

这是一个回合制游戏,所以当玩家1轮到玩家时,2必须无法点击按钮(所以我想隐藏它),反之亦然。

1 个答案:

答案 0 :(得分:0)

我认为它现在正在运作。在移动函数中,我添加了ok_mc.visible = false,它隐藏了“本地”实例中的mc,并在netstatus事件中隐藏了ok_mc.visible = true。喜欢这个

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;
}
}

似乎有效。现在我只需要弄清楚在第一个实例中在init中显示它。有没有办法计算组成员和/或循环它们?

相关问题