12 Replies Latest reply on Aug 31, 2010 2:49 PM by kglad

    Button that cycles through images

    Intricasm

      I was wondering how I could make a button (that is an image itself) that, when pressed, will cycle through other images.

       

      As an example... say The first picture is a cat, you click it, it changes into a dog, you click it again, it changes into a monkey, etc. It would eventually go back to the cat picture.

       

      I've attempted doing this but am completely lost.

       

      A second question would be; How could I make it so when I push the button/click the image, a menu in the flash document pops up and allows a person to select the Image they want loaded in that position?

       

      Thanks in advance.

       

      PS: Unrelated question, really, but I was wondering how to set up a way for people to save the state of the flash document to let them share it with each other. (similar to the flash game at http://armorgames.com/play/3614/crush-the-castle called Crush The Castle. For the example, once the game loads, go to 'Build your own' then on the left side menu with the objects, it has a save and load screen where you can copy/paste a code.)

        • 1. Re: Button that cycles through images
          kglad Adobe Community Professional & MVP

          1.  add different images to frame 1, 2, 3 etc of a movieclip.  attach a stop() to frame 1.  drag the movieclip to the stage and assign an instance name (eg, mc).  you can then use actionscript to advance the movieclip's frames until the last is reached (and then return to frame 1, for example).

           

          2.  it's not clear what you want

           

          3.  load an xml file or other database data that determines the flash state.   you can code for users to save the flash state using server-side coding.

          1 person found this helpful
          • 2. Re: Button that cycles through images
            Intricasm Level 1

            1: Not to sound like a total fool, but I started learning flash about 3 days ago, not too sure what to put in the action script to make it cycle through the images. I understand the rest of it, though. Thanks for that.

             

            2: Essentially what I meant was to have the image/button there, and when you click it, a context menu would show up and let you choose the image to be loaded there. It would change the button's image into the image you choose. nto sure if that explained it any better... let me know.

             

            3: I truthfully have no idea how to do this.

             

            EDIT: On Number 2, well don't worry about that, I think it'd be much easier just to do it the first way.

            • 3. Re: Button that cycles through images
              kglad Adobe Community Professional & MVP

              1.  if you want the code given to you, you'll need to specify whether you're using as2 or as3.  if you want to learn how to use actionscript, this is about as basic as it gets and is a good task to learn.

               

              3.  you have no hope of doing yourself unless 1. is easy for you.

              1 person found this helpful
              • 4. Re: Button that cycles through images
                Intricasm Level 1

                Well I figured out how to cycle the images by using buttons. I'm not entirely positive I did it 'right' but it's what I wanted originally. (I just made each frame after the original frame keyframes and loaded a new button into each one, did I do that right?)

                 

                But I've run into a bit of a snag. I'd like to have multiples of these buttons, and they'll all do the same thing. But i've noticed that when I click one, it changes all of the buttons, not just itself. I know this is because they're on the same frames.. Do you know how I could make it so each button changes individually?

                 

                Just in case that isn't understandable, I've uploaded the swf to my website to show what I mean. http://intrisplace.com/test.html The image on the right is the one with actionscript, the one on the left doesn't have anything on it yet. I know the problem, I just don't really know a workaround.

                • 5. Re: Button that cycles through images
                  kglad Adobe Community Professional & MVP

                  show the code you're using.

                  • 6. Re: Button that cycles through images
                    Intricasm Level 1

                    Well, it's incredibly basic, but here we go.

                     

                    In frame one I have a stop(); in place. Then on every button I have:

                     

                    button_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToNextFrame);

                     

                    function fl_ClickToGoToNextFrame(event:MouseEvent):void

                    {

                    nextFrame();

                    }

                     

                    With the last button using this code to go back to the beginning:

                     

                    button_5.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_2);

                     

                    function fl_ClickToGoToAndStopAtFrame_2(event:MouseEvent):void

                    {

                    gotoAndStop(1);

                    }

                     

                     

                    Oh, i'm using AS3.

                    • 7. Re: Button that cycles through images
                      PJSB_DK Level 3

                      Hi

                       

                      But I've run into a bit of a snag. I'd like to have multiples of these buttons, and they'll all do the same thing. But i've noticed that when I click one, it changes all of the buttons, not just itself. I know this is because they're on the same frames.. Do you know how I could make it so each button changes individually?

                       

                      If you're using a single button as a base, then

                      remember to use "Duplicate symbol" on each

                      instance of the button. Otherwise a single change

                      on a button will affect all buttons.

                       

                      Procedure:

                       

                      Drag the base button onto stage..Right click it and choose "Duplicate symbol".

                      Now give the button the instance name you want.

                       

                      Best regards

                      Peter

                      • 8. Re: Button that cycles through images
                        Intricasm Level 1

                        Thanks, i'll give that a try and see if it changes. But since I have all of the buttons on the same frames, wouldn't that still change all of them anyway? Unless there's a workaround to that.

                        • 9. Re: Button that cycles through images
                          kglad Adobe Community Professional & MVP

                          that's not's how you should be creating a movieclip button that's reusable and you shouldn't follow pjsb's advice.

                           

                          here's a sample of how to create one button that you can use repeatedly:  www.kglad.com/Files/forums/Untitled-1.fla

                          • 10. Re: Button that cycles through images
                            PJSB_DK Level 3

                            Hi

                             

                            @KGlad

                             

                            that's not's how you should be creating a movieclip button that's reusable and you shouldn't follow pjsb's advice.

                             

                            Absolutely right..

                            My assumptions about the buttons was based on the example he showed at his website.

                            Clicking the buttons changed images on all buttons, hence my assumption, that he changed images

                            inside the button (basebutton), which in turn then changed all buttons..

                            Never said, that it was the right way to do it. But you learn by the mistakes you make and I would give him

                            the chance to figure it out himself before providing the complete solution.

                             

                            Who knows?? He might have come up the with the right solution himself?

                            I further assumed, that if he wanted a complete example on how to do it, he would have asked.

                            But then again...That's just me in a nutshell 

                             

                            Best regards

                            Peter

                            • 11. Re: Button that cycles through images
                              Intricasm Level 1

                              I was attempting to figure it out myself, yes, but getting an example will accomplish the same thing I guess. Gives me something to play around with and figure out. Thanks to both of you for helping me out.

                               

                              EDIT: Just took a look at it, and it should give me plenty to toy around with, thank you again, Kglad. I can see that I was WAY off.

                               

                              Message was edited by: Intricasm

                              • 12. Re: Button that cycles through images
                                kglad Adobe Community Professional & MVP

                                you're welcome.