9 Replies Latest reply on Feb 25, 2008 4:02 PM by Rothrock

    onRollOver action

    jdwild
      I have a movie clip with the instance name of 'funbutton'. When a user mouses over that mc I want it to take the user to another frame in the same main timeline. I added the following actionscript to the movieclip image:

      funbutton_mc.onRollOver = function() {
      gotoAndPlay(5);

      }

      But that doesn't work. I realize this is probably a simple thing, but I am stumped and can't find anything similar in the forums. Can someone correct this actionscript for me? And let me know if I should be saving file as AS2 or AS3.

      thanks, Julie
        • 1. Re: onRollOver action
          Rothrock Level 5
          Well the code you have shown is AS2. So unless you are getting an error you are publishing to the correct version.

          So does funbutton_mc have a frame 5? When you have an event handler defined like this it will be in the scope of the instance you attach it to. So

          myClip.onRollOver=function(){
          trace(this);
          }

          Will trace "myClip" (well actually _level0.myClip or whatever the path to that clip is!). What I'm guess you want to happen is the parent of funbutton_mc should go to frame 5? In that case:

          _parent.gotoAndPlay(5)

          should do the trick.
          • 2. Re: onRollOver action
            jdwild Level 1
            You read my mind. I want the user to be taken to frame 5 of the parent file.
            So this would be the script?

            funbutton_mc.onRollOver = function() {
            _parent.gotoAndPlay(5);

            }

            And I add this by clicking on the movie clip, not just in the frame, right?
            You gotta speak way down to me :)

            I did what I just described above and got the following errors while publishing...
            Statement must appear within on/onClipEvent handler
            • 3. Re: onRollOver action
              i_am_captivate Level 1
              Hello,

              Put that on the frame that the movieclip is on, not on the movieclip itself :)

              HTH

              Doug
              • 4. Re: onRollOver action
                jdwild Level 1
                I tried to make sense of some of the help files and noticed that I am supposed to put that script in the frame and NOT have the movie clip actually selected. So I did that and the error message does not come up when I publish. But it still does not work.
                I have a stop action in the first frame so the movie doesn't go forward. I don't want it to continue unless someone mouses over the movie clip. I've posted the fla file if you want to take a look.
                www.wilddezign.com/fun_button.fla
                tia
                • 5. Re: onRollOver action
                  Rothrock Level 5
                  Hmm. Maybe it should be

                  this._parent.gotoAndPlay(5);

                  What do you mean by, "That does not work." Believe it a lot there is generally one way something works, but many, many ways that they don't work.

                  Use your trace commands to see what is going on. So on the frame where the stop is place:

                  trace(this+" is stopped on Frame 1.");

                  Then in the onRelease handler

                  trace(this+" has just been released");

                  Then in frame 5:

                  trace(this+" made it to frame 5");

                  And so on at any place you think it would be helpful for you to know that the playhead is there or something has been clicked, etc.
                  • 6. Re: onRollOver action
                    jdwild Level 1
                    While actually trying to decypher the Help files, and thru trial and error, I came up with the following that seems to actually work.
                    So, to sum up, I have a movie clip called: funbutton_mc and I want it to play at frame 5 of my parent movie timeline when a user mouses over the movie clip. A stop action is placed in frame 1. Movie clip is in frame 1.

                    WITH FRAME 1 SELECTED, add the following script:

                    funbutton_mc.onRollOver = function() {
                    trace("funbutton_mc.onRollOver = function() {_parent.gotoAndPlay(5)};");
                    };


                    WITH MOVIE CLIP SELECTED, add the following script:

                    on (RollOver) {
                    _parent.gotoAndPlay(5);
                    }

                    my brain feels like it's going to explode now.
                    thanks for all your help Rothrock (and imjustabeginner, too)
                    PS: I believe it will be quite a bit more reading before I understand what you meant by 'trace' commands :)
                    I'll have the final file posted here to view for a short while:
                    http://www.wilddezign.com/fun_button2.html
                    • 7. Re: onRollOver action
                      Rothrock Level 5
                      While that is a working solution -- and in the end if it works that is good -- but thisisn't the best solution. The technique of selecting clips and putting the code directly on them with on(event) is a hold over from Flash 5 days and was quickly surpassed in Flash 6. If/When you start using AS3, you will find that the technique has completely gone away.

                      The problem with the old style technique is that it creates a thousand different places where your code can be and makes it difficult if you want to change it. David Stiller who is often on this site has written a great blog about it. I would recommend you read it someday -- once your brain has had a chance to recover a bit.

                      http://www.quip.net/blog/2006/flash/museum-pieces-on-and-onclipevent

                      Do you get a trace from the first bit of your code? My guess is that if you don't you are making one of the very common mistakes -- that we all make when new.

                      Have you given the funbutton_mc that name on the stage? Or is that just the name in the library? The two are very different.

                      What happens if in your on(RollOver) you add a trace statement after the gotoAndPlay:

                      trace("Clip event rolled over for: "+this);

                      What do you get in the trace window for that?
                      • 8. Re: onRollOver action
                        jdwild Level 1
                        If indeed, the code that I used is not what I should be using, why is it in my CS3 help files? It shouldn't even be there then. And after my brain is ready, I will pursue this and read that blog you mentioned and try to understand 'trace' :)
                        • 9. Re: onRollOver action
                          Rothrock Level 5
                          I only have Flash 8 at work (where I am at the moment) so I will have to check the help files when I get home. My guess is that since CS3 can still publish AS2 and the on(event) structurs is still supported by AS2. So that would be why it is in the help files.

                          And yes, the most important thing is that you solved your current problem. I just want to encourage you to think about a better way for the future. It really will help streamline your whole process eventually. Take it easy and slow when you are ready!
                          1 person found this helpful