3 Replies Latest reply on Sep 5, 2007 10:51 AM by Newsgroup_User

    stopping onEnterFrame

    rhamiltonc
      Hi everyone, I'm trying to have a menu that travels through the screen horizontally; in order to do that i have a movieclip instanced texto and the following code is on the MC:

      onClipEvent (enterFrame) {
      _root.texto._x++
      }

      and in that MC (already moving) i have a button that should stop the movement when the mouse rolls over it. And continues moving on rollOut.
      The movieclip is moving constantly, but i can´t stop it (or pause it). I have tried

      on(RollOver){
      _root.texto.stop();
      }
      but it doesn´t work. I know it can´t stop because there is only one frame...
      i have tried making a loop with this code (instance._x++) on one frame and stopping it with the button, but it keeps moving.
      any ideas? Is there a way to stop a ClipEvent(enterFrame)?
      thanks
        • 1. Re: stopping onEnterFrame
          Level 7
          rhamiltonc,

          > the following code is on the MC:
          >
          > onClipEvent (enterFrame) {
          > _root.texto._x++
          > }

          Okay.

          > The movieclip is moving constantly, but i can´t stop it
          > (or pause it). I have tried
          >
          > on(RollOver){
          > _root.texto.stop();
          > }
          > but it doesn´t work.

          The MovieClip.stop() method refers to the timeline of the movie clip in
          question, and the timeline of texto is not the mechanism used to animate
          that clip. Instead, you've got an enterFrame event handler updating the
          value of texto's MovieClip._x property.

          Here's one approach. Instead of the ++ operator, which increments a
          value by one, try substituting that with the += operator which increments a
          value by whatever amount you specify. You can specify 1, which will act the
          same as ++, and then later, you can change the value to 0, which will halt
          the incrementing, even though the enterFrame handler continues to execute.

          e.g.
          // Assuming this code is attached directly to the texto clip ...
          onClipEvent (load) {
          this.increment = 1;
          }
          onClipEvent (enterFrame) {
          this._x += this.increment;
          }
          on (rollOver) {
          this.increment = 0;
          }

          Does that make sense? If the above event handlers are all attached
          directly to texto, then you don't need to reference texto's instance name:
          it's obvious to Flash from the direct attachment which clip you mean. If
          these event handlers are attached to something else, then you would, of
          course, need the texto instance name as a reference.

          > Is there a way to stop a ClipEvent(enterFrame)?

          There isn't, which is one of the unfortunately weaknesses of using the
          on() and onClipEvent() functions. If you go with the newer event handling
          approach (new as of Flash MX [aka 6]), you can indeed stop event handlers
          dynamically.

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


          David Stiller
          Co-author, Foundation Flash CS3 for Designers
          http://tinyurl.com/2k29mj
          "Luck is the residue of good design."


          • 2. Re: stopping onEnterFrame
            rhamiltonc Level 1
            solved it, changed the event, instead of using onEnterFrame I placed the code in a 2-frame loop, which I can now stop.
            • 3. Re: stopping onEnterFrame
              Level 7
              rhamiltonc,

              > solved it, changed the event, instead of using onEnterFrame I
              > placed the code in a 2-frame loop, which I can now stop.

              That would be another approach. ;) That's what's fun -- and sometimes
              frustrating -- about Flash development.


              David Stiller
              Adobe Community Expert
              Dev blog, http://www.quip.net/blog/
              "Luck is the residue of good design."