12 Replies Latest reply on Jan 3, 2009 9:57 AM by Ned Murphy

    Button within a movieclip

    youngjon
      Hi all,

      I am relatively new to Flash and am looking for help with a file I am working on.

      I have created a movieclip of an area which is placed so that only the outer right edge is on the stage. When the mouse hovers over the area, it moves onto the stage and reveals menu options. It works beautifully as an animation, and the menu options (which have over, down, and hit states) work when not part of this movieclip, but when I place instances of the buttons within the tweened movieclip, they no longer work.

      I have been scouring the web for answers and most people say that you cannot have a rollover within a rollover as the first rollover (in my case, the movieclip) is still active.

      I have seen this work with various files in flashden for example where the menu slides out from the side and then slides back in when you 'roll off' but while you are 'rolled on' you have access to menu options which all perform their own roll on/off movies.

      Hopefully there is a simple answer!

      Thanks in advance.

      J.
        • 1. Re: Button within a movieclip
          Ned Murphy Adobe Community Professional & MVP
          It's not a simple solution, but not a difficult one either.

          You need to make the background of the movieclip be the part that has the rollover effect (make the bg an mc as well to accomplish this). And make the buttons participate in the holding of the rollout as well, otherwise, when you hover a button you unhover the background and it will rollback, probably bouncing back and forth as you hit different pieces of the overall mc.
          • 2. Re: Button within a movieclip
            youngjon Level 1
            Thanks for your response.

            Would I do this by adding an invisible button? Right now I have the following code in the Actions for the movieclip:

            on (rollOver) {
            gotoAndPlay("over");
            }
            on (rollOut) {
            gotoAndPlay("out");
            }

            It's playing labels over & out from within my movieclip.

            Not sure how to apply what you have suggested.

            J.
            • 3. Button within a movieclip
              Ned Murphy Adobe Community Professional & MVP
              You can place a button as/over the background for this control (invisible if you have a picturesque background), and the code would be...

              on (rollOver) {
              gotoAndPlay("over");
              }
              on (rollOut) {
              gotoAndPlay("out");
              }

              Note: I edited this posting, so in case you saw it with the _parent involved, I removed that because a button shouldn't need it.
              • 4. Re: Button within a movieclip
                youngjon Level 1
                Hi Ned,

                Did as you suggested and movieclip is working well with the background as the button. I can now rollover the menu option button within the movieclip, but as you said, it is now trying to roll back and bouncing back and forth. How do I make the button participate in the holding out of the rollout?

                Your help is greatly appreciated.

                J.
                • 5. Button within a movieclip
                  Ned Murphy Adobe Community Professional & MVP
                  Here's where the not simple, but not difficult part comes in...

                  But before I try to offer a solution, it'll help to know how you manage the slideout/slidein animations... are they done using Tween code or with motion tweens on a timeline?

                  Whichever approach may take some patient tweaking of the solution, but hopefully you'll get the general idea when I (or someone else who might pop in) offer one.
                  • 6. Re: Button within a movieclip
                    youngjon Level 1
                    Sorry for the delay! Had to nip out for a bit.

                    Right...I'm using a motion tween to handle the slide in/out. Not experienced enough yet to use code to handle the tween although i'm working on it....

                    I'm happy to get the .fla file to you if you require it if you need to know more.

                    Thanks..

                    J.
                    • 7. Button within a movieclip
                      Ned Murphy Adobe Community Professional & MVP
                      I had to step out for awhile too.

                      Well, I'll give you a jump start on the AS version of Tweens. Taking this approach will give you a better bit of sliding. With your gotoAndPlay(label), you'd end up having things probably still jumping around when it moves from the background to a button and vice-versa which would end up complicating the coding to avoid it.

                      Below is a link to a small sample file I made for you that you can study/utilize... it was easier than trying to explain it in this forum. It shows you a better way of coding mouse interaction stuff as well (using on(...) attached to objects is bad practice... now outlawed in AS3).

                      The way I did it has all of the code visible in the main timeline so you don't have to go digging and clicking on things to find code.

                      The menu's background is a movieclip and the menu's button is a button. I only have one button, but the more the merrier as long as they all have their own code and instance names. Though for the rollOver you could assign them all as follows:

                      btn1.onrollOver = btn2.onrollOver = btn3.onrollOver = function(){...}

                      I forget during this edit (some hours later) if I have a rollOut for the button, but since/if the background surrounds it on all sides, you can probably eliminate it... only the background would need to have that aspect covered.

                      There are two versions of the file linked below... a CS3 version and a Flash 8 version.

                      Sample Fla File - CS3
                      Sample Fla File - Flash 8

                      PS - my host's server is acting up today, so be patient.
                      • 8. Re: Button within a movieclip
                        youngjon Level 1
                        That's brilliant- thanks very much.

                        My final question is how can I edit the ease in/out aspect of the tween using code. In my original tween I amended it using the edit button in the prop inspector to create a nice elasticated feel.

                        I can see a Regular.easeInOut part of your code so I'm thinking it's got something to do with that.

                        Thanks very much for your time with this- I appreciate your help.

                        J.
                        • 9. Button within a movieclip
                          Ned Murphy Adobe Community Professional & MVP
                          You're welcome.

                          You hit the nail with "elasticated"... replace Regular with Elastic wherever it shows up and see what that gives you. I've never used it, so you may wanna do a little searching to see the available tweakings for it.
                          • 10. Re: Button within a movieclip
                            Ned Murphy Adobe Community Professional & MVP
                            One other thing that probably isn't too important, but may impact visual smoothness of the AS tweening... the second to last parameter (0.5) I used in the arguments is the time for the tween to take (the last indicates whether to use seconds (true) or frames (false)). When you roll over the bg, it starts that 0.5 second count. When the rollover hits the button, it reinstates the 0.5 second duration (I think), but has less distance to travel at that point so it might seem to slow down.

                            I just figured I'd mention this in case you feel adventurous and want to play around to see if you can figure out a way to make it adjust based on the menu current position and time remaining from that initial 0.5 second command... but save any such effort until later on.
                            • 11. Re: Button within a movieclip
                              youngjon Level 1
                              My menu works great now Ned, thanks for all your help. I'll continue to poke around in the code to see what changes I can make to the feel. I'll be sure to visit this forum again in the future.

                              J.
                              • 12. Button within a movieclip
                                Ned Murphy Adobe Community Professional & MVP
                                Depending on your intentions for working with Flash, I highly recommend you visit the forum(s) whenever you have some spare time, even if you don't have question to ask--once a day would be a good habit to get into. Just look thru the recent postings and see if anything draws your interest that you might like to learn about.

                                That's one of the main reasons I'm here (another being that as a freelancer I have plenty of spare time at times). The forums provide opportunities to deal with things that my own work doesn't. Very often when I'm trying to help someone, I'm learning new things by figuring out solutions and seeing what others contribute.