0

我试图通过创建一个游戏来学习使用 flash cs6 的动作脚本 3,我想要的是在舞台上多次放置随机卡片,以便用户将它们添加起来并且它们消失,我让卡片出现在舞台上但得到了多个要出现的版本是我停止的地方,我只能让它们出现一次,有人知道怎么做吗?非常感谢您

stop();

var pressed_1:int =0;

var pressed_2:int =0;





 function checkTol (pressed_1,pressed_2)

{
    if (pressed_1+pressed_2 ==11)
    {
    trace("winner");
    trace(pressed_1+pressed_2);
    }
    else
    {
    trace ("loser")
    trace(pressed_1+pressed_2);
    pressed_1=0;
    pressed_2=0;
    trace("is it reset 1 to " +pressed_1);
    trace("is it reset 2 to " +pressed_2);
    trace("this is  1 now " +pressed_1);
    trace("this is  2 now " +pressed_2);
    }

}



 function click_1(Event:MouseEvent = null)
    {
        if (pressed_1==0)
            {
            pressed_1=1;
            trace("holder_1 = " + pressed_1);
            cardPrint1.removeEventListener(MouseEvent.CLICK, click_1);
            trace("button 1 disabled")
            cardPrint1.alpha =.5;
            }
        else if (pressed_2==0)
            {
            pressed_2=1;
            trace("holder_2 = " + pressed_2);
            cardPrint1.removeEventListener(MouseEvent.CLICK, click_1);
            trace("button 1 disabled")
            cardPrint1.alpha =.5;
            checkTol (pressed_1,pressed_2);

            }
    }

 function click_2(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=2;
            trace("holder_1 = " + pressed_1);
            cardPrint2.removeEventListener(MouseEvent.CLICK, click_2);
            trace("button 2 disabled");
            cardPrint2.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=2;
            trace("holder_2 = " + pressed_2);
            cardPrint2.removeEventListener(MouseEvent.CLICK, click_2);
            trace("button 2 disabled");
            cardPrint2.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }

 function click_3(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=3;
            trace("holder_1 = " + pressed_1);
            cardPrint3.removeEventListener(MouseEvent.CLICK, click_3);
            trace("button 2 disabled");
            cardPrint3.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=3;
            trace("holder_2 = " + pressed_2);
            cardPrint3.removeEventListener(MouseEvent.CLICK, click_3);
            trace("button 2 disabled");
            cardPrint3.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }


function click_4(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=4;
            trace("holder_1 = " + pressed_1);
            cardPrint4.removeEventListener(MouseEvent.CLICK, click_4);
            trace("button 2 disabled");
            cardPrint4.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=4;
            trace("holder_2 = " + pressed_2);
            cardPrint4.removeEventListener(MouseEvent.CLICK, click_4);
            trace("button 2 disabled");
            cardPrint4.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }


 function click_5(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=5;
            trace("holder_1 = " + pressed_1);
            cardPrint5.removeEventListener(MouseEvent.CLICK, click_5);
            trace("button 2 disabled");
            cardPrint5.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=5;
            trace("holder_2 = " + pressed_2);
            cardPrint5.removeEventListener(MouseEvent.CLICK, click_5);
            trace("button 2 disabled");
            cardPrint5.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }


 function click_6(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=6;
            trace("holder_1 = " + pressed_1);
            cardPrint6.removeEventListener(MouseEvent.CLICK, click_6);
            trace("button 2 disabled");
            cardPrint6.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=6;
            trace("holder_2 = " + pressed_2);
            cardPrint6.removeEventListener(MouseEvent.CLICK, click_6);
            trace("button 2 disabled");
            cardPrint6.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }


 function click_7(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=7;
            trace("holder_1 = " + pressed_1);
            cardPrint7.removeEventListener(MouseEvent.CLICK, click_7);
            trace("button 2 disabled");
            cardPrint7.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=7;
            trace("holder_2 = " + pressed_2);
            cardPrint7.removeEventListener(MouseEvent.CLICK, click_7);
            trace("button 2 disabled");
            cardPrint7.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }


 function click_8(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=8;
            trace("holder_1 = " + pressed_1);
            cardPrint8.removeEventListener(MouseEvent.CLICK, click_8);
            trace("button 2 disabled");
            cardPrint8.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=8;
            trace("holder_2 = " + pressed_2);
            cardPrint8.removeEventListener(MouseEvent.CLICK, click_8);
            trace("button 2 disabled");
            cardPrint8.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }


 function click_9(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=9;
            trace("holder_1 = " + pressed_1);
            cardPrint9.removeEventListener(MouseEvent.CLICK, click_9);
            trace("button 2 disabled");
            cardPrint9.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=9;
            trace("holder_2 = " + pressed_2);
            cardPrint9.removeEventListener(MouseEvent.CLICK, click_9);
            trace("button 2 disabled");
            cardPrint9.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }


 function click_10(Event:MouseEvent = null)
    {
        if(pressed_1==0)
        {
            pressed_1=10;
            trace("holder_1 = " + pressed_1);
            cardPrint10.removeEventListener(MouseEvent.CLICK,       click_10);
            trace("button 2 disabled");
            cardPrint10.alpha =.5;

        }
        else if (pressed_2==0 )
        {

            pressed_2=10;
            trace("holder_2 = " + pressed_2);
            cardPrint10.removeEventListener(MouseEvent.CLICK, click_10);
            trace("button 2 disabled");
            cardPrint10.alpha =.5;
            checkTol (pressed_1,pressed_2);
        }

    }



var cardPrint1 :MovieClip = new card_1();
this.addChild(cardPrint1);
cardPrint1.x =50;
cardPrint1.y =35;
cardPrint1.addEventListener(MouseEvent.CLICK, click_1);


var cardPrint2 :MovieClip = new card_2();
this.addChild(cardPrint2);
cardPrint2.x =100;
cardPrint2.y =35;
cardPrint2.addEventListener(MouseEvent.CLICK, click_2);

var cardPrint3 :MovieClip = new card_3();
this.addChild(cardPrint3);
cardPrint3.x =150;
cardPrint3.y =35;
cardPrint3.addEventListener(MouseEvent.CLICK, click_3);

var cardPrint4 :MovieClip = new card_4();
this.addChild(cardPrint4);
cardPrint4.x =200;
cardPrint4.y =35;
cardPrint4.addEventListener(MouseEvent.CLICK, click_4);

var cardPrint5 :MovieClip = new card_5();
this.addChild(cardPrint5);
cardPrint5.x =250;
cardPrint5.y =35;
cardPrint5.addEventListener(MouseEvent.CLICK, click_5);

var cardPrint6 :MovieClip = new card_6();
this.addChild(cardPrint6);
cardPrint6.x =300;
cardPrint6.y =35;
cardPrint6.addEventListener(MouseEvent.CLICK, click_6);

var cardPrint7 :MovieClip = new card_7();
this.addChild(cardPrint7);
cardPrint7.x =350;
cardPrint7.y =35;
cardPrint7.addEventListener(MouseEvent.CLICK, click_7);

var cardPrint8 :MovieClip = new card_8();
this.addChild(cardPrint8);
cardPrint8.x =400;
cardPrint8.y =35;
cardPrint8.addEventListener(MouseEvent.CLICK, click_8);

var cardPrint9 :MovieClip = new card_9();
this.addChild(cardPrint9);
cardPrint9.x =450;
cardPrint9.y =35;
cardPrint9.addEventListener(MouseEvent.CLICK, click_9);

var cardPrint10 :MovieClip = new card_10();
this.addChild(cardPrint10);
cardPrint10.x =500;
cardPrint10.y =35;
cardPrint10.addEventListener(MouseEvent.CLICK, click_10);
4

1 回答 1

1

创建一个数组循环,在每个循环中添加一个新变量movieclip。然后将其推送到数组并通过循环调用它,myarray[i] i表示循环中使用的数字整数。

前任:

var movieclip = new MovieClip;
addChild(movieclip);
array.push(movieclip);

然后调用movieclips:

for(var i = 0; i < array.length; i ++)
{
    array[i].dosomething();
}
于 2013-05-11T23:52:30.163 回答