5 Replies Latest reply on Feb 29, 2012 6:59 AM by kglad

    building arrays and comparing the contents

    subtlefly72 Level 1

      Hi team,

      building a flash drag and drop activity with a check answers button, having trouble getting the arrays to compare.. here is my code (below)

      why wont my uanswer array work properly and when I compare arrays how can I get them to "match" or == if they have the same contents in different order? Does it matter?

      Also  can I get a number reutrned on how many matching items there are even if they dont completely match?

      Cheers

      sub

       

      ans1.ans1text.text="beans";

      ans2.ans1text.text="chicken";

      ans3.ans1text.text="rice";

      ans4.ans1text.text="rocks";

      ans5.ans1text.text="dirt";

      var incorrect:Number=0;

       

       

      var correct:Number=0;

       

       

      trace(getRect(target1));

       

       

       

       

      var rightanswers:Array = ["ans1, ans2, ans3"];

      for (var i:int = 0; i < rightanswers.length; i++ )

        {

         var answer:String = rightanswers[i];

        }

      var useranswers:Array;

       

        for (var j:int = 0; j < useranswers.length; j++ )

         {

          var uanswer:String = useranswers[j]

         }

       

       

       

       

       

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

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

      function pickMe1(event:MouseEvent):void {

          event.target.startDrag();

       

      }

      function dropMe1(event:MouseEvent):void {

          event.target.stopDrag();

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

      if ((event.target.hitTestObject(target1)==true)){

             

         useranswers.push("ans1");  

         trace(useranswers);

        

      }else{

                var ians1:Number = useranswers.indexOf("ans1");

                trace(ians1);

                useranswers.splice(ians1,1);

                trace(useranswers);

       

      }

      }

       

       

      this.ans1.buttonMode = true;

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

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

      function pickMe2(event:MouseEvent):void {

          event.target.startDrag();

       

      }

      function dropMe2(event:MouseEvent):void {

          event.target.stopDrag();

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

      if ((event.target.hitTestObject(target1)==true)){

             

            

            

      useranswers.push("ans2");  

         trace(useranswers);

       

      }else{

       

                var ians2:Number = useranswers.indexOf("ans2");

                trace(ians2);

                useranswers.splice(ians2,1);

                trace(useranswers);

       

      }

       

      }

       

       

      this.ans2.buttonMode = true;

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

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

      function pickMe3(event:MouseEvent):void {

          event.target.startDrag();

       

      }

      function dropMe3(event:MouseEvent):void {

          event.target.stopDrag();

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

      if ((event.target.hitTestObject(target1)==true)){

             

            

      useranswers.push("ans3");  

         trace(useranswers);

        

      }else{

       

                var ians3:Number = useranswers.indexOf("ans3");

                trace(ians3);

                useranswers.splice(ians3,1);

                trace(useranswers);               

                          

       

       

       

       

       

       

      }

       

       

      }

       

       

      this.ans3.buttonMode = true;

       

       

      checker.addEventListener(MouseEvent.CLICK, checker1);

      function checker1(event:MouseEvent){

                 trace (answer);

       

       

                  trace (uanswer);

       

      // this is where I want to get my two arrays to compare, but my uanswer array is not working

       

      }