所以我正在使用flash进行纸牌游戏,而且我对Add Child有些困难。当帧首次加载时我第一次调用脚本时效果很好但是当我点击结束转弯按钮改变到第二个玩家时,转换添加子项不会产生它的动画片段。
澄清当前问题是“if(Player2FirstTurn == 1)”部分。
这是我的帧加载脚本,完美运行。
//Shuffle player 1's deck
function randomize1(a : *, b : * ):int
{
return ( Math.random() >.5 ) ? 1 : -1;
}
player1deck.sort( randomize1 );
//Shuffle player 2's deck;
player2deck.sort( randomize1 );
//Draw first four cards for player 1;
var Player1DrawCard:MovieClip = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
//Show player 1's hand on screen;
addChild(Player1Hand[0]);
Player1Hand[0].x = 250.00;
Player1Hand[0].y = 300.00;
addChild(Player1Hand[1]);
Player1Hand[1].x = 436.85;
Player1Hand[1].y = 300.00;
addChild(Player1Hand[2]);
Player1Hand[2].x = 623.70;
Player1Hand[2].y = 300.00;
addChild(Player1Hand[3]);
Player1Hand[3].x = 810.55;
Player1Hand[3].y = 300.00;
Player1Hand.pop();
Player1Hand.pop();
Player1Hand.pop();
Player1Hand.pop();
这是我的点击脚本,它不会填充错误,但数组中的动画片段不会加载到屏幕上。
EndTurn.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
if (CurrentTurn == 1)
{
if(Player1Level < 4)
{
Player1Draw = 2;
}
else if(Player1Level < 8)
{
Player1Draw = 3;
}
else if(Player1Level > 11)
{
Player1Draw = 4;
}
CurrentTurn = 2;
Player2Action = 0;
if (Player2FirstTurn == 1)
{
trace("First turn true");
//Draw first four cards for player 2;
var Player2DrawCard:MovieClip = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
trace(Player2Hand);
//Show player 2's hand on screen;
addChild(Player2Hand[0]);
Player2Hand[0].x = 250.00;
Player2Hand[0].y = 300.00;
addChild(Player2Hand[1]);
Player2Hand[1].x = 436.85;
Player2Hand[1].y = 300.00;
addChild(Player2Hand[2]);
Player2Hand[2].x = 623.70;
Player2Hand[2].y = 300.00;
addChild(Player2Hand[3]);
Player2Hand[3].x = 810.55;
Player2Hand[3].y = 300.00;
trace(Player2Hand);
Player2Hand.pop();
Player2Hand.pop();
Player2Hand.pop();
Player2Hand.pop();
Player2FirstTurn = 2;
Object(root).FieldSwapMC.gotoAndPlay(2);
Object(root).PlayerFields.gotoAndPlay(2);
}
else
{
if (player2deck.length < Player2Draw)
{
trace("Short Deck");
for (var j:int = 0; j<= Player2Discard.length; j++)
{
Player2DrawCard = Player2Discard.shift();
player2deck.push(Player2DrawCard);
}
player2deck.sort( randomize1 );
}
if (Player2Draw == 0)
{
trace("No Draw");
}
else if (Player2Draw == 1)
{
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
addChild(Player2Hand[0]);
Player2Hand[0].x = 250.00;
Player2Hand[0].y = 300.00;
Player2Hand.pop();
}
else if (Player2Draw == 2)
{
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
addChild(Player2Hand[0]);
Player2Hand[0].x = 250.00;
Player2Hand[0].y = 300.00;
addChild(Player2Hand[1]);
Player2Hand[1].x = 436.85;
Player2Hand[1].y = 300.00;
Player2Hand.pop();
Player2Hand.pop();
}
else if (Player2Draw == 3)
{
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
addChild(Player2Hand[0]);
Player2Hand[0].x = 250.00;
Player2Hand[0].y = 300.00;
addChild(Player2Hand[1]);
Player2Hand[1].x = 436.85;
Player2Hand[1].y = 300.00;
addChild(Player2Hand[2]);
Player2Hand[2].x = 623.70;
Player2Hand[2].y = 300.00;
Player2Hand.pop();
Player2Hand.pop();
Player2Hand.pop();
}
else if (Player2Draw == 4)
{
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
Player2Hand.push(Player2DrawCard);
Player2DrawCard = player2deck.shift();
addChild(Player2Hand[0]);
Player2Hand[0].x = 250.00;
Player2Hand[0].y = 300.00;
addChild(Player2Hand[1]);
Player2Hand[1].x = 436.85;
Player2Hand[1].y = 300.00;
addChild(Player2Hand[2]);
Player2Hand[2].x = 623.70;
Player2Hand[2].y = 300.00;
addChild(Player2Hand[3]);
Player2Hand[3].x = 810.55;
Player2Hand[3].y = 300.00;
Player2Hand.pop();
Player2Hand.pop();
Player2Hand.pop();
Player2Hand.pop();
}
}
Object(root).FieldSwapMC.gotoAndPlay(2);
Object(root).PlayerFields.gotoAndPlay(2);
}
else if (CurrentTurn == 2)
{
if(Player2Level < 4)
{
Player2Draw = 2;
}
else if(Player2Level < 8)
{
Player2Draw = 3;
}
else if(Player2Level > 11)
{
Player2Draw = 4;
}
CurrentTurn = 1;
Player1Action = 0;
if (Player1Draw == 0)
{
trace("No Draw");
}
else if (Player1Draw == 1)
{
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
addChild(Player1Hand[0]);
Player1Hand[0].x = 250.00;
Player1Hand[0].y = 300.00;
Player1Hand.pop();
}
else if (Player1Draw == 2)
{
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
addChild(Player1Hand[0]);
Player1Hand[0].x = 250.00;
Player1Hand[0].y = 300.00;
addChild(Player1Hand[1]);
Player1Hand[1].x = 436.85;
Player1Hand[1].y = 300.00;
Player1Hand.pop();
Player1Hand.pop();
}
else if (Player1Draw == 3)
{
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
addChild(Player1Hand[0]);
Player1Hand[0].x = 250.00;
Player1Hand[0].y = 300.00;
addChild(Player1Hand[1]);
Player1Hand[1].x = 436.85;
Player1Hand[1].y = 300.00;
addChild(Player1Hand[2]);
Player1Hand[2].x = 623.70;
Player1Hand[2].y = 300.00;
Player1Hand.pop();
Player1Hand.pop();
Player1Hand.pop();
}
else if (Player1Draw == 4)
{
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
Player1Hand.push(Player1DrawCard);
Player1DrawCard = player1deck.shift();
addChild(Player1Hand[0]);
Player1Hand[0].x = 250.00;
Player1Hand[0].y = 300.00;
addChild(Player1Hand[1]);
Player1Hand[1].x = 436.85;
Player1Hand[1].y = 300.00;
addChild(Player1Hand[2]);
Player1Hand[2].x = 623.70;
Player1Hand[2].y = 300.00;
addChild(Player1Hand[3]);
Player1Hand[3].x = 810.55;
Player1Hand[3].y = 300.00;
Player1Hand.pop();
Player1Hand.pop();
Player1Hand.pop();
Player1Hand.pop();
}
Object(root).FieldSwapMC.gotoAndPlay(13);
Object(root).PlayerFields.gotoAndPlay(13);
}
}
跟踪显示对象影片剪辑正确地位于数组中,但只是没有加载到舞台上。提前谢谢!