0

我在舞台上有 25 个电影剪辑,它们都可以点击和着色。如果只有 5 个特定按钮被单击和着色,我希望一个名为 text_mc 的影片剪辑变得可见 - 不多。如果用户选择的影片剪辑超过了这五个影片剪辑(甚至认为包含 5 个影片剪辑),则名为 text_mc 的影片剪辑应该保持不可见。我不能做最后一部分:如果点击了超过 5 个特定的影片剪辑,那么 text_mc 应该保持不可见。你能帮我么?这是我的代码

  stop();

  import flash.display.MovieClip;



 var sximata:MovieClip = square1;
 import flash.display.MovieClip;
 import flash.events.MouseEvent;
 import flash.geom.ColorTransform;



 text_mc.visible=false;


  square1.addEventListener(MouseEvent.CLICK, onsquare1);
  function onsquare1(e:MouseEvent):void {
sximata = square1;
  }


  square2.addEventListener(MouseEvent.CLICK, onsquare2);
  function onsquare2(e:MouseEvent):void {
sximata = square2;
  }

  square3.addEventListener(MouseEvent.CLICK, onsquare3);
  function onsquare3(e:MouseEvent):void {
sximata = square3;
  }


  square4.addEventListener(MouseEvent.CLICK, onsquare4);
  function onsquare4(e:MouseEvent):void {
sximata = square4;
   }


  square5.addEventListener(MouseEvent.CLICK, onsquare5);
  function onsquare5(e:MouseEvent):void {
sximata = square5;
   }

   square6.addEventListener(MouseEvent.CLICK, onsquare6);
   function onsquare6(e:MouseEvent):void {
sximata = square6;
      }

    square7.addEventListener(MouseEvent.CLICK, onsquare7);
    function onsquare7(e:MouseEvent):void {
sximata = square7;
     }


    square8.addEventListener(MouseEvent.CLICK, onsquare8);
     function onsquare8(e:MouseEvent):void {
sximata = square8;
square8Clicked = true;
checkButtons();


   }

   square9.addEventListener(MouseEvent.CLICK, onsquare9);
   function onsquare9(e:MouseEvent):void {
sximata = square9;
square9Clicked = true;
checkButtons();
   }


    square10.addEventListener(MouseEvent.CLICK, onsquare10);
    function onsquare10(e:MouseEvent):void {
sximata = square10;
square10Clicked = true;
checkButtons();
     }


     square11.addEventListener(MouseEvent.CLICK, onsquare11);
     function onsquare11(e:MouseEvent):void {
sximata = square11;
    }


       square12.addEventListener(MouseEvent.CLICK, onsquare12);
       function onsquare12(e:MouseEvent):void {
sximata = square12;
     }

    square13.addEventListener(MouseEvent.CLICK, onsquare13);
      function onsquare13(e:MouseEvent):void {
sximata = square13;
square13Clicked = true;
checkButtons();
    }


   square14.addEventListener(MouseEvent.CLICK, onsquare14);
   function onsquare14(e:MouseEvent):void {
sximata = square14;
square14Clicked = true;
checkButtons();
    }


     square15.addEventListener(MouseEvent.CLICK, onsquare15);
     function onsquare15(e:MouseEvent):void {
sximata = square15;
     }

    square16.addEventListener(MouseEvent.CLICK, onsquare16);
     function onsquare16(e:MouseEvent):void {
sximata = square16;
     }

   square17.addEventListener(MouseEvent.CLICK, onsquare17);
   function onsquare17(e:MouseEvent):void {
sximata = square17;
     }


    square18.addEventListener(MouseEvent.CLICK, onsquare18);
    function onsquare18(e:MouseEvent):void {
sximata = square18;
       }

    square19.addEventListener(MouseEvent.CLICK, onsquare19);
    function onsquare19(e:MouseEvent):void {
sximata = square19;
     }


     square20.addEventListener(MouseEvent.CLICK, onsquare20);
     function onsquare20(e:MouseEvent):void {
sximata = square20;
      }


     square21.addEventListener(MouseEvent.CLICK, onsquare21);
     function onsquare21(e:MouseEvent):void {
sximata = square21;
      }


    square22.addEventListener(MouseEvent.CLICK, onsquare22);
    function onsquare22(e:MouseEvent):void {
sximata = square22;
      }

    square23.addEventListener(MouseEvent.CLICK, onsquare23);
    function onsquare23(e:MouseEvent):void {
sximata = square23;
      }


    square24.addEventListener(MouseEvent.CLICK, onsquare24);
     function onsquare24(e:MouseEvent):void {
sximata = square24;
       }


     square25.addEventListener(MouseEvent.CLICK, onsquare25);
      function onsquare25(e:MouseEvent):void {
sximata = square25;
       }




    var myColorTransform:ColorTransform=transform.colorTransform;
    red_btn.addEventListener(MouseEvent.CLICK, changeColour);
    function changeColour(event:MouseEvent):void {


    myColorTransform.color=0xBD8D46;

    sximata.transform.colorTransform=myColorTransform;


   }


     resetButton.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);

     function fl_MouseClickHandler(event:MouseEvent):void
     {
    gotoAndPlay(1);
       }




   var square8Clicked:Boolean = false;
   var square9Clicked:Boolean = false;
   var square10Clicked:Boolean = false;
   var square13Clicked:Boolean = false;
   var square14Clicked:Boolean = false;


     function checkButtons():void
{
if(square8Clicked && square9Clicked && square10Clicked && square13Clicked && square14Clicked)
    {
    text_mc.visible = true;

   }
}
4

2 回答 2

0

如果单击任何其他方块,您可以为每个其他函数添加一个布尔变量,该变量变为真。例如:

var isClicked:Boolean = false;
square1.addEventListener(MouseEvent.CLICK, onsquare1);
function onsquare1(e:MouseEvent):void {
    sximata = square1;
    isClicked = true;
}

然后在您的检查按钮功能中,检查“isClicked”是否仍然为假:

function checkButtons():void
{
    if(!isClicked && square8Clicked && square9Clicked && square10Clicked && square13Clicked && square14Clicked)
    {
        text_mc.visible = true;

    }
}
于 2013-07-23T21:10:35.050 回答
0

我的解决方案如下。它基于计算用户可以单击的每种类型的 MovieClip 收到的点击次数。代码的相关部分将在onClick()andcheckClickCounts()方法中。

首先,您会看到,在该buildMCs()方法中,我只是创建了一堆 MovieClip 并将它们以网格的形式放置在舞台上。我已经做到了,您提到的“特定”MC 是网格每一行上的第一个项目。对于每个“特定”的 MC,我添加了一个属性:isSpecial:Boolean并将其设置为 true。稍后,当单击 MC 时,该OnClick()方法将检查 MC 是否特殊,并将增加相关的单击计数属性。然后,checkClickCounts()被调用。如果统计了 5 次好的点击和 0 次的坏点击,那么我们就让用户知道。这是您显示文本字段的地方。(在我的例子中,我只是在屏幕上画了一个大的红色矩形。

我在这里演示的另一个建议是避免重复鼠标单击代码。如果您查看构造函数,您会看到我使用了这一行:

this.addEventListener(MouseEvent.CLICK, onClick);

这告诉主舞台精灵听所有的鼠标点击,甚至是发生在其中的 MovieClips 的那些。在该onClick()方法中,我检查单击的项目(事件的目标)是否是 MovieClip。如果是,那么我会进行额外的检查以查看点击的 MC 是否是我想要的。通过这样做,我能够编写一次处理鼠标单击的代码,现在如果我需要更改某些内容,我只需要执行一次,而不是 25 次。节省了我的时间,但也减少了代码出错的可能性,因为如果需要进行更改,我不太可能错过某些内容。

package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.MouseEvent;

public class Clicky extends Sprite
{
    public function Clicky()
    {
        this.buildMCs();

        this.addEventListener(MouseEvent.CLICK, onClick);
    }

    private function buildMCs ():void
    {
        var rows:int = 5;
        var cols:int = 5;

        var boxSize:int = 10;

        for (var r:int = 0; r < rows; r++)
        {
            for (var c:int = 0; c < cols; c++)
            {
                var newMC:MovieClip = new MovieClip();
                newMC.graphics.lineStyle(0, 0x00ff00);

                // want to mark the "specific" movieclips
                if (c == 0)
                {
                    newMC.graphics.beginFill(0x0000ff);

                    // just something that makes this MC unique... ideally
                    // this would be not a MovieClip, but a class that defines
                    // actual properties worth checking for
                    newMC.isSpecial = true;
                }
                else
                {
                    newMC.graphics.beginFill(0x00ff00);
                }
                newMC.graphics.drawRect(0, 0, boxSize, boxSize);

                this.addChild(newMC);

                newMC.x = (c * boxSize);
                newMC.y = (r * boxSize);
            }
        }
    }

    private function onClick (e:MouseEvent):void
    {
        if (e.target is MovieClip)
        {
            var mc:MovieClip = e.target as MovieClip;
            mc.alpha = .25;

            // disable the clicking for the clicked item
            mc.mouseEnabled = false;

            if (mc.isSpecial)
            {
                _specialClicks++;
            }
            else
            {
                _badClicks++;
            }

            this.checkClickCounts();
        }
    }

    private var _specialClicks:int = 0;
    private var _badClicks:int = 0;
    private function checkClickCounts ():void
    {
        if (_specialClicks == 5 && _badClicks == 0)
        {
            // do your thing - show the text_mc, play a sound, award a prize, etc.
            this.graphics.beginFill(0xff0000);
            this.graphics.drawRect(0, 0, 1000, 1000);
        }
    }
}
}
于 2013-07-23T22:29:53.853 回答