3 Replies Latest reply on Aug 27, 2009 7:28 AM by Rothrock

    need to stop instance of mc onEnterFrame

    justinm34

      (running CS3 and doing this in AS2)

      i have a looping animation of a ball rotating, that i need to stop rotating once it reaches a particular frame (we'll say frame 60).

      i tried putting:

      ball_mc.onEnterFrame = function() {
          ball_mc.stop();
      }

      (ball_mc is the instance name of a particular movie clip.  i do not want to reference the actual mc as i have about 10 instances of it on the timeline)

      everything is taking place on the main stage at the root level, but i can't seem to get the animation to stop.

      any help would be greatly appreciated.

      j

        • 1. Re: need to stop instance of mc onEnterFrame
          Rothrock Level 5

          Oh. So many things aren't making sense here.

           

          First what does this mean "...i do not want to reference the actual mc as i have about 10 instances of it on the timeline..."?

           

          The only way to tell a movieclip to stop is to tell it to stop, so you will have to reference it. There are many ways to do such a thing, but without knowing exactly what you are trying to accomplish (with the whole project) it is hard to give exact advice.

           

          The next thing is that I don't think onEnterFrame is what you are thinking it is. It means to repeat the code at the frame rate, it doesn't mean, "Do this when this frame is reached." If you just want to do something when you reach a frame you put a keyframe and add code like:

           

          ball.stop();

           

          All code on that frame will execute before the screen is redrawn. So I think that is what you are after.

           

          Finally, there are a couple of reasons that the code above might not stop a given movieclip.

           

          The first and most common reason would be that you have a scope problem. That that ball isn't a child of the current timeline. So if ball was actually inside another movie clip you might need to do something like

           

          theOrbs.ball.stop();

           

          Or perhaps you have mistyped or misnamed the instance. So if the instance name is Ball and you say ball.stop() it won't work because capitazliation and spelling matter.

           

          Another popular way that stop() wouldn't work is if the animation of the clip is being done by code. stop() only stops the playhead on the specified timeline. So if there is some code making the ball move stopping its timeline won't stop the code.

           

          And a similar issue to the scope and code issue is that if the animation that makes the ball move is actually provided by a movieclip nested inside of ball then ball.stop() will stop the ball's timeline, but not the independent timelines of its children.

           

          So we need to know more about how you have designed your project.

          • 2. Re: need to stop instance of mc onEnterFrame
            justinm34 Level 1

            here is how the animation is broken down:

            there are 4 different mc in the library.  each is a different color ball ('orangeball_mc', 'greenball_mc', etc).  these four movie clips each are just a 6 frame loop of the ball doing 1 clockwise rotation.  on the main (root) stage level, each of these balls are running on motion paths, and are each on the stage about 3 instances.  i have named each instances uniquely, so the first orange ball appearing on the screen's instance is 'o1_mc' ('o2_mc', etc).  when the ball has reached its destination on the motion path i need the 'orangeball_mc' for the instance of 'o1_mc' to stop looping (the ball has come to rest).  different instances of different balls are stopping at different points in the animation, thus i was trying to tell each of them to stop at different places on the timeline.

            i am not actually running the animation thru AS, just need to tell it to stop.  i get that i was incorrectly using onEnterFrame, i just can't find the syntax to tell an instance of a mc to stop (i tried both o1_mc.stop(); o1_mc.orangeball_mc.stop(); and orangeball_mc.o1_mc.stop(); as frame actions without success).

            i hope this clearly outlines exactly what i'm trying to do.  it doesnt seem like it should be terribly difficult, i'm sure i'm just missing something dumb.

            • 3. Re: need to stop instance of mc onEnterFrame
              Rothrock Level 5

              If I'm following you correctly then you will not be able to do what you want.

               

              If the only timeline inside of o1_mc is the spin, then o1_mc.stop() should stop the spinning. But if they motion guides are on the main timeline then only stopping it will stop the motion. Usually that would be with code like such:

               

              this.stop();

               

              But I'm guessing you don't want that because you want other things on the main timeline to keep animating. (BTW, don't use _root.stop() if you think that you might ever want to load a swf into another swf.)

               

              Of course if you make the balls into nested clips the spinner nested inside the motion path, then you would have to do something like:

               

              o1_mc.stop();

              o1_mc.spinnyBall.stop();

               

              Which is a hassle. You could incorporate rotation into the motion path tween so you only needed to have one clip.

               

              Am I following this correctly.

               

              BTW, sometimes when I'm having problems with a method or something I substitute a different property, just to make sure that I am scoping the object correctly. So you could try code like:

               

              o1_mc._alpha=50

              o1_mc._xscale=o1_mc._yscale=200;

               

              or something like that to make sure that you really do have the correct scope and all.