1 Reply Latest reply on Feb 20, 2012 10:24 PM by subtlefly72

    make drag and drop work on a check answers button..

    subtlefly72 Level 1

      Hi crew, I ve got a drag and drop code working, but what I really want to do is have a check answers button that tells the user, you have none correct, or two correct or all wrong...

      I have one target area, and 3 correct answers (out of 7) so I would like to let the user put as many ansers on the target as they want and then check if they have any correct, also a reset code would be nice to put everything back where it started...

      I tried to break my code up but the events then went mad,

      Here is what i have so far, it works instantly and lets crrect answers stay and incorrect bounce back..  It's not a deal breaker, but, Any help would be greatly apprecated!!  I love you guys:)

       

      stop();

      yes1.visible=false;

      allcorrect.visible=false;

      doit.text="drag over the words that mean Vision";

      var count:Number=0;

      var correct:Number=0;

      function checkcount(){

                if(count==3){

                          allcorrect.visible=true;

                          yes1.visible=true;

                          doit.text="";

                }

      }

       

       

       

       

       

       

       

       

       

       

      stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseA);

       

       

      //2.

      function mouseA(event:MouseEvent) {

      if(mouseX>=125)

      masker.gotoAndStop(1);

       

       

      }

       

       

       

      stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseB);

       

       

      //2.

      function mouseB(event:MouseEvent) {

      if(mouseX<=19)

      masker.gotoAndStop(2);

       

       

      }

      var startX:Number;

      var startY:Number;

       

       

       

       

       

       

       

       

       

       

      this.ans1.addEventListener(MouseEvent.MOUSE_DOWN, pickMe);

      this.ans1.addEventListener(MouseEvent.MOUSE_UP,dropMe);

      function pickMe(event:MouseEvent):void {

          event.target.startDrag();

                startX = event.target.x;

          startY = event.target.y;

      }

      function dropMe(event:MouseEvent):void {

          event.target.stopDrag();

                var myTargetName:String = "ans1" + event.target.name;

      if (event.target.dropTarget != null && event.target.dropTarget.parent == target1){

       

       

                event.target.x = startX;

          event.target.y = startY;

      }

      }

       

       

      this.ans1.buttonMode = true;

       

       

       

       

      this.ans2.addEventListener(MouseEvent.MOUSE_DOWN, pickMe1);

      this.ans2.addEventListener(MouseEvent.MOUSE_UP,dropMe1);

      function pickMe1(event:MouseEvent):void {

          event.target.startDrag();

                startX = event.target.x;

          startY = event.target.y;

      }

      function dropMe1(event:MouseEvent):void {

          event.target.stopDrag();

                var myTargetName:String = "ans2" + event.target.name;

      if (event.target.dropTarget != null && event.target.dropTarget.parent == target1){

              event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickMe1);

              event.target.removeEventListener(MouseEvent.MOUSE_UP, dropMe1);

              event.target.buttonMode = false;

              event.target.x = target1.x;

              event.target.y = target1.y;

       

                          count=count+1;

                          checkcount();

       

      }else{

                event.target.x = startX;

          event.target.y = startY;

      }

      }

       

       

      this.ans2.buttonMode = true;

      this.ans3.addEventListener(MouseEvent.MOUSE_DOWN, pickMe2);

      this.ans3.addEventListener(MouseEvent.MOUSE_UP,dropMe2);

      function pickMe2(event:MouseEvent):void {

          event.target.startDrag();

                startX = event.target.x;

          startY = event.target.y;

      }

      function dropMe2(event:MouseEvent):void {

          event.target.stopDrag();

                var myTargetName:String = "ans3" + event.target.name;

      if (event.target.dropTarget != null && event.target.dropTarget.parent == target1){

             

       

       

                event.target.x = startX;

          event.target.y = startY;

      }

      }

       

       

      this.ans3.buttonMode = true;

      this.ans4.addEventListener(MouseEvent.MOUSE_DOWN, pickMe3);

      this.ans4.addEventListener(MouseEvent.MOUSE_UP,dropMe3);

      function pickMe3(event:MouseEvent):void {

          event.target.startDrag();

                startX = event.target.x;

          startY = event.target.y;

      }

      function dropMe3(event:MouseEvent):void {

          event.target.stopDrag();

                var myTargetName:String = "ans4" + event.target.name;

      if (event.target.dropTarget != null && event.target.dropTarget.parent == target1){

              event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickMe3);

              event.target.removeEventListener(MouseEvent.MOUSE_UP, dropMe3);

              event.target.buttonMode = false;

              event.target.x = target1.x;

              event.target.y = target1.y+50;

       

                          count=count+1;

                          checkcount();

       

      }else{

                event.target.x = startX;

          event.target.y = startY;

      }

      }

       

       

      this.ans4.buttonMode = true;

      this.ans5.addEventListener(MouseEvent.MOUSE_DOWN, pickMe4);

      this.ans5.addEventListener(MouseEvent.MOUSE_UP,dropMe4);

      function pickMe4(event:MouseEvent):void {

          event.target.startDrag();

                startX = event.target.x;

          startY = event.target.y;

      }

      function dropMe4(event:MouseEvent):void {

          event.target.stopDrag();

                var myTargetName:String = "ans5" + event.target.name;

      if (event.target.dropTarget != null && event.target.dropTarget.parent == target1){

       

       

                event.target.x = startX;

          event.target.y = startY;

      }

      }

       

       

      this.ans5.buttonMode = true;

       

       

      this.ans6.addEventListener(MouseEvent.MOUSE_DOWN, pickMe5);

      this.ans6.addEventListener(MouseEvent.MOUSE_UP,dropMe5);

      function pickMe5(event:MouseEvent):void {

          event.target.startDrag();

                startX = event.target.x;

          startY = event.target.y;

      }

      function dropMe5(event:MouseEvent):void {

          event.target.stopDrag();

                var myTargetName:String = "ans6" + event.target.name;

      if (event.target.dropTarget != null && event.target.dropTarget.parent == target1){

              event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickMe);

              event.target.removeEventListener(MouseEvent.MOUSE_UP, dropMe);

              event.target.buttonMode = false;

              event.target.x = target1.x;

              event.target.y = target1.y+100;

       

                          count=count+1;

                          checkcount();

       

      }else{

                event.target.x = startX;

          event.target.y = startY;

      }

      }

       

       

      this.ans6.buttonMode = true;

       

       

       

       

      this.ans7.addEventListener(MouseEvent.MOUSE_DOWN, pickMe6);

      this.ans7.addEventListener(MouseEvent.MOUSE_UP,dropMe6);

      function pickMe6(event:MouseEvent):void {

          event.target.startDrag();

                startX = event.target.x;

          startY = event.target.y;

      }

      function dropMe6(event:MouseEvent):void {

          event.target.stopDrag();

                var myTargetName:String = "ans7" + event.target.name;

      if (event.target.dropTarget != null && event.target.dropTarget.parent == target1){

             

       

       

                event.target.x = startX;

          event.target.y = startY;

      }

      }

       

       

      this.ans7.buttonMode = true;

        • 1. Re: make drag and drop work on a check answers button..
          subtlefly72 Level 1

          Hey I just found another problem with the code the way I have it written and that is if someone was to drag an incorrect answer on top of an already in place correct answer it wont work as it is blocking the target, so I thought I just wanted to imporve my code but it actually is broken...

          how can I make a movieclip "invisible" i.e. you can sense and click through it, but still be able to see it?- is this even possible?  Any other ideas?

          Cheers

          sub