2 Replies Latest reply on Aug 24, 2009 9:01 PM by shaylee tan

    Matching game for flex

    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();"/>

        • 1. Re: Matching game for flex
          babo_ya Level 3

          Bad idea..

          why would you want to compare two images?

          you just need to create VO or object and pass in the url and if the url matches then .. there you go..

           

          hope this helps,

           

          BaBo,

          • 2. Re: Matching game for flex
            shaylee tan Level 1

            Because i need to store those images in an array.The image path for the images is stored in an xml file.I want to know how to compare the cards(i mean the images). Something like if-else statement. If image1 is clicked and image2 is clicked, then this is wrong.So the cards will flipped back Because it is two different images. If both images is the same,both images will stay open. I am stuck in this and i am in serious help. Hope someone can assist and clarify me doubts. Thanks for the help.

             

             

            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);

            }