2

Animate CC workframeHow do i stop this program from looping? The stop(); function won't work. It is not an animation clip but a drag and drop game. Because I'm still new to AS3, I would appreciate it if someone answered my question with explanations. Thanks!

item1.objName = "circle";
item1.initX = item1.x;
item1.initY = item1.y;
item1.val = 0;

item2.objName = "rectangle";
item2.initX = item2.x;
item2.initY = item2.y;
item2.val = 0;

item3.objName = "triangle";
item3.initX = item3.x;
item3.initY = item3.y;
item3.val = 0;


bin1.shape.alpha = 0;
bin2.shape.alpha = 0;
bin3.shape.alpha = 0;

item1.buttonMode = true;
item2.buttonMode = true;
item3.buttonMode = true;

item1.addEventListener(MouseEvent.MOUSE_DOWN, mousePress);
item1.addEventListener(MouseEvent.MOUSE_UP, mouseRelease);
item2.addEventListener(MouseEvent.MOUSE_DOWN, mousePress);
item2.addEventListener(MouseEvent.MOUSE_UP, mouseRelease);
item3.addEventListener(MouseEvent.MOUSE_DOWN, mousePress);
item3.addEventListener(MouseEvent.MOUSE_UP, mouseRelease);


//Mouse Events

function mousePress(event:MouseEvent):void {
    var item:MovieClip = MovieClip(event.target);
    item.startDrag();
    item.scaleX = item.scaleY = .95;
    var topPos:uint = this.numChildren - 1;
    this.setChildIndex(item, topPos);
    ilabel.itemName_txt.text = item.objName;    
}


function mouseRelease(event:MouseEvent):void {
    var item:MovieClip = MovieClip(event.target);
    item.stopDrag();

    switch (item.objName) { 
 case "circle" : 
        if (bin1.hitTestObject(item)){ 
        updateShape(item, bin1);

        }
      else{
        ilabel.info_txt.text ="WRONG! Hint: circle";
        item.scaleX = item.scaleY = 1
        }
 break; 
 case "rectangle" : 
        if (bin2.hitTestObject(item)) {
        updateShape(item, bin2);

        }
        else{
        ilabel.info_txt.text ="WRONG! Hint: rectangle";
        item.scaleX = item.scaleY = 1
        } 
 break;
  case "triangle" : 
 if (bin3.hitTestObject(item)){ 
        updateShape(item, bin3);

    }
        else{
        ilabel.info_txt.text ="WRONG! Hint: Triangle";
        item.scaleX = item.scaleY = 1
        } 
 break;
  default :; 
    }

}
function updateShape(item:MovieClip, bin:MovieClip):void {
    ilabel.itemName_txt.text = "";
    item.scaleX = item.scaleY = 1;
    item.visible = false;
    ilabel.info_txt.text ="CORRECT! ";
    bin.shape.alpha = 1;
    item.val = 1;
    resetShapes();
}

function resetShapes(){
    if((item1.val == 1)&& (item2.val == 1) && (item3.val == 1)){

        item1.x = item1.initX;
        item1.y = item1.initY;
        item2.x = item2.initX;
        item2.y = item2.initY;
        item3.x = item3.initX;
        item3.y = item3.initY;

        bin1.shape.alpha = 0;
        bin2.shape.alpha = 0;
        bin3.shape.alpha = 0;

        item1.visible = true;
        item2.visible = true;
        item3.visible = true;

        item1.val = 0;
        item2.val = 0;
        item3.val = 0;


        }
    }

    function checkGame():void {
    if ((item1.scaleX = item1.scaleY = 1)&& (item2.scaleX = item2.scaleY = 1)&&(item3.scaleX = item3.scaleY = 1))
    {

        ilabel.info_txt.text=" Well done!";
    }



}
BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
CHIGGAJX
  • 41
  • 8
  • What do you mean "stop looping"? If you want your mouse interactions to no be registered just remove the event listeners (`item1.removeEventListener(MouseEvent.MOUSE_DOWN, mousePress); item1.removeEventListener(MouseEvent.MOUSE_UP, mouseRelease);`) when needed. – Iansen Apr 06 '16 at 09:52
  • After all the items in the game are correctly matched, the game doesn't end there but instead it restarted on its own. – CHIGGAJX Apr 07 '16 at 04:28
  • 1
    How many frames do you have? Are you writing code in the built in ActionsScript editor? Post some images of how your timeline looks.... I usually have only one frame and my scripts are in external files. – Iansen Apr 07 '16 at 07:31
  • I've edited the post and posted the image, click on the "Animate CC workframe". I only have a frame but with a few layers however only the first layer has the action codes. – CHIGGAJX Apr 08 '16 at 03:26

1 Answers1

0
    function checkGame():void {
    if ((item1.scaleX = item1.scaleY = 1)&& (item2.scaleX = item2.scaleY = 1)&&(item3.scaleX = item3.scaleY = 1))
    {
    ilabel.info_txt.text=" Well done!";
    item1.removeEventListener(MouseEvent.MOUSE_DOWN, mousePress);
    item1.removeEventListener(MouseEvent.MOUSE_UP, mouseRelease);
    item2.removeEventListener(MouseEvent.MOUSE_DOWN, mousePress);
    item2.removeEventListener(MouseEvent.MOUSE_UP, mouseRelease);
    item3.removeEventListener(MouseEvent.MOUSE_DOWN, mousePress);
    item3.removeEventListener(MouseEvent.MOUSE_UP, mouseRelease);
}

This will stop the user from being able to select anything. If you have a movie clip looping on 'item1' for example. You need to add item1.stop(); also to the checkGame function...

Good luck!

withayk
  • 134
  • 2
  • 10