1 Reply Latest reply on Mar 9, 2012 7:31 AM by Ned Murphy

    can you please help me improve on this code

    subtlefly72 Level 1

      Here is code for a drag and drop activituy where there are 4 questions, each question is on a separate frame of a movieclip mentorquestions.  I am trying to have the frame picked at random and then have either the yes target or the no target visible for the right answer to correspond with the question. yesplay is a little animation to let you know you got the correct answer.   My code is a bit hit and miss I think.. I am doing something (or many things) wrong

      any suggestions?

      cheers

      sub

      import flash.events.MouseEvent;

       

       

       

       

      yesplay.addEventListener(Event.ENTER_FRAME, checkit);

      function checkit (myevent:Event):void {

              if (yesplay.currentFrame == 27)

              {reset1();

              }

      }

       

       

      var incorrect:Number=0;

       

       

      var correct:Number=0;

       

       

      targetYes.visible=false;

      targetNo.visible=false;

       

       

       

       

      var Qmove:Array = [1,2,3,4];

      var b:Number=4;

      var a:Number;

      var c:Number;

      function pickquestion(){

                a=Math.floor(Math.random() * b);

                mentorquestions.gotoAndStop(Qmove[a]);

                c=Qmove[a];

                trace(c);

                setanswer();

                Qmove.splice(a,1);

                b=b-1;

       

                trace(a);

                trace(Qmove);

                trace(b);

       

      }

      pickquestion();

      function setanswer(){;

                if (c==3){

                          targetYes.visible=true;

                          targetNo.visible=false;

                }else{

                          targetYes.visible=false;

                          targetNo.visible=true;

       

                }

       

      }

       

       

       

       

      AbackBT.addEventListener(MouseEvent.CLICK, Abacker);

      function Abacker(e:MouseEvent){

                visible=false;

       

       

      }

      var Yx:Number=843;

      var Yy:Number=295;

      var Nx:Number=843;

      var Ny:Number=394;

       

       

      function reset1(){

                yes.x=Yx;

                yes.y=Yy;

                no.x=Nx;

                no.y=Ny;

                pickquestion();

      }

       

       

       

       

      var startX:Number;

      var startY:Number;

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

      this.yes.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 = "yes" + event.target.name;

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

            

          

              event.target.x = targetYes.x;

              event.target.y = targetYes.y;

                          yesplay.play();

      }else{

                event.target.x = startX;

          event.target.y = startY;

                wrongun.play();

      }

      }

       

       

      this.yes.buttonMode = true;

       

       

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

      this.no.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 = "no" + event.target.name;

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

            

           

              event.target.x = targetNo.x;

              event.target.y = targetNo.y;

                          yesplay.play();

      }else{

                event.target.x = startX;

          event.target.y = startY;

                wrongun.play();

      }

       

      }

       

       

       

       

      this.no.buttonMode = true;