2 Replies Latest reply on Aug 24, 2009 11:22 PM by Niranjan_swain

    Comparing images(if-else statement)

    shaylee tan

      Hi! I am doing a memory game in flex.problem i faced is how to compare 2 images? I got 16 images with 8 pairs of the same. Example,if image1 is clicked and image 2 is clicked,the image will flipped back because its different. However,if image1 is clicked and another image1 is clicked,both image will stay flipped open.

       

       

      <mx:Image id="image1" x="480" y="177" width="100" height="100" source="assets/card_2.JPG" scaleContent="false" click="test.source = 'assets/torres.JPEG';setTotalClicks();"/>

      <mx:Image id="image2" x="623" y="438" width="100" height="100" source="assets/card_2.JPG" scaleContent="false" click="tests.source = 'assets/torres.JPEG';setTotalClicks();"/>

       

       

       

      What i meant for the comparing of cards is something like this(but this is a concept of what i meant)

       

      private function reveal():void
      {
          if(image1 == image1)
          {
              cardFlipped = true;
          }
          else(image1 == image2)

          {

       

           cardFlipped = false;

          }

      }

       

       

      Below is how i declare the strings(the images of the card) in array.

       

      private function Image():void {
                             
      gameArray.push("assets/pat.jpg");
      gameArray.push("assets/hunt.jpg");
      gameArray.push("assets/ger.jpg");
      gameArray.push("assets/ars.jpg");
      gameArray.push("assets/lamps.jpg");
      gameArray.push("assets/kaka.jpg");
      gameArray.push("assets/torres.jpg");
      gameArray.push("assets/vidic.jpg");

       

      gameArray.push(test.source);
      gameArray.push(tests.source);
      gameArray.push(kaka.source);
      gameArray.push(kaka1.source);
      gameArray.push(vidic.source);
      gameArray.push(vidic1.source);
      gameArray.push(gerrard.source);
      gameArray.push(gerrard1.source);
      gameArray.push(ars.source);
      gameArray.push(ars1.source);
      gameArray.push(lampard.source);
      gameArray.push(lampard1.source);
      gameArray.push(hunt.source);
      gameArray.push(hunt1.source);
      gameArray.push(pato.source);
      gameArray.push(pato1.source);

      }

        • 1. Re: Comparing images(if-else statement)
          Niranjan_swain

          hi ur question is not clear. can u explain detail it will easy to answer question.

          • 2. Re: Comparing images(if-else statement)
            shaylee tan Level 1

            Oh sry.i tell u clearer in details. i am doing a memory flipping game.Currently i am hardcoding all the image path for the images i had.

             

            <mx:Image id="test" x="480" y="177" width="100" height="100" source="assets/card_2.JPG" scaleContent="false" click="test.source = 'assets/torres.JPEG'"/>
               
            <mx:Image id="tests" x="623" y="438" width="100" height="100" source="assets/card_2.JPG" scaleContent="false" click="tests.source = 'assets/torres.JPEG'"/>

             

             

            What i need to do is to store all the images in an array.After that, i need to compare those image arrays. Because for the memory game,i must able to match all the identical pairs of cards. So my question is how am i going to match those images. When the 1st image is clicked,it flipped open. If i clicked on a 2nd image,it flipped open too. This is the tricky part. If both images are the same,it will stay open. If both images are different,both will flipped back.

             

             

             

            Is the the correct way of storing those images in an array?

             

             

            private function Image():void {
                                   
            gameArray.push("assets/pat.jpg");
            gameArray.push("assets/hunt.jpg");
            gameArray.push("assets/ger.jpg");
            gameArray.push("assets/ars.jpg");
            gameArray.push("assets/lamps.jpg");
            gameArray.push("assets/kaka.jpg");
            gameArray.push("assets/torres.jpg");
            gameArray.push("assets/vidic.jpg");

             

            gameArray.push(test.source);
            gameArray.push(tests.source);
            gameArray.push(kaka.source);
            gameArray.push(kaka1.source);
            gameArray.push(vidic.source);
            gameArray.push(vidic1.source);
            gameArray.push(gerrard.source);
            gameArray.push(gerrard1.source);
            gameArray.push(ars.source);
            gameArray.push(ars1.source);
            gameArray.push(lampard.source);
            gameArray.push(lampard1.source);
            gameArray.push(hunt.source);
            gameArray.push(hunt1.source);
            gameArray.push(pato.source);
            gameArray.push(pato1.source);

             


            }