4 Replies Latest reply: Dec 1, 2014 11:41 PM by moccamaximum RSS

    How to keep an item hidden when retruning to my games home frame?

    Rackoon Community Member

      Hi I have a math game I am working on the has a home frame with 200 buttons (each button takes the player to another frame with a  math problem on it) If the player selects the correct button answer they are taken back to the home page and the original button becomes hidden, reveling the background or hidden spaceships.

       

      so far I have done most of the exercises in the classroom in a book  (original and action scrip) regardless I have been able to make several test games yet when I return to the home frame, hidden buttons come back. How do I make these stay hidden?

       

      So far I have been able to use the snippits that come with flash (go to and stop and go to and hide object)

       

      Do I need action script that says go to and delete object?

       

      Any help would be great.

        • 1. Re: How to keep an item hidden when retruning to my games home frame?
          moccamaximum Community Member

          if you are using actionscript 3:

           

          btn199.addEventListener(MouseEvent.CLICK, takeQuestion);;

           

          function takeQuestion(e:MouseEvent):void{

          e.currentTarget.visible = false;

          //hides the button

            var index:int = e.currentTarget.name.substr(3,3);

          //results in 199 in our case

          gotoAndStop(index);

          //jumps to frame 199 were the question is

          }

          • 2. Re: How to keep an item hidden when retruning to my games home frame?
            Ned Murphy CommunityMVP

            One way would be to add the button instance to an array that you loop thru every time you go back to that frame and make the buttons in the array invisible.

             

            Another way would be to have the buttons contained in an object (movieclip/sprite) that exists in all frames but is only made visible at the beginning frame.... that way you never leave the buttons behind and the ones you turn invisible inside that object will remain invisible.

            • 3. Re: How to keep an item hidden when retruning to my games home frame?
              Rackoon Community Member

              Thank you both for the help. Ned, I think I would need a lot more practice  to do what your speaking of.

               

              Hey moccamaximum, I understand most of what you typed. but I am a little fuzzy on where to stick it. I have a very basic understanding of event handlers and functions and still learning.

              As for the veritable I will need to review that part again.

               

              some guidance would be a big help;  here is one of my tests I have been working with. If I can make it work for three on the first frame then it will work for 200

               

              Home frame has button one, two, and three on it (button one takes you to frame 2)   (button two takes you to frame 3)   (button three takes you to frame 4)

               

              suppose I click on button one and I am taken to frame 2; I select the correct multi-choice button (call it button four) I am taken back to home frame 1 and button one is gone or transparent.

               

              (This is where I get stuck is when I select another button and come back to home frame transparent buttons reappear)

               

              Could you help me attach the correct action-script you gave me to the correct buttons?  Also this part confuses me       one var index:int = e.currentTarget.name.substr(3,3);

              • 4. Re: How to keep an item hidden when retruning to my games home frame?
                moccamaximum Community Member

                if a buttons name is "btn1"

                 

                var index:int = e.currentTarget.name.substr(3,1);

                 

                will get you to the "1" in "btn1" and thus telling you which Button was pressed

                 

                this is useful to let a MouseEventHandler tell where he originated

                 

                Lets say you have 3 buttons:

                 

                btn1,btn2,btn3

                 

                you can now attach a single EventListener

                 

                btn1.addEventListener(MouseEvent.CLICK, clickHandler);

                btn2.addEventListener(MouseEvent.CLICK, clickHandler);

                btn3.addEventListener(MouseEvent.CLICK, clickHandler);

                 

                and depending on which button was pressed, execute different behaviour:

                 

                function clickHandler(e:MouseEvent):void{

                e.currentTarget.visible = false;

                //hides the button

                  var index:int = e.currentTarget.name.substr(3,1);

                gotoAndStop(index);

                //jumps to frame 1 when btn1 is clicked

                //jumps to frame 2 when btn2 is clicked

                //jumps to frame 3 when btn3 is clicked

                }