10 Replies Latest reply on Jun 17, 2009 10:17 AM by chewbears

    Ending an animation with code

    chewbears Level 1

      I am now working on an intro and found this very neat animation on a tutorial website : see below :  The problem is I don't know how to stop it.  See I want when it finishes the 20 circles its randomly generating to end so that I can start my site.  I have not figured out how to do this.  Any ideas???

       

       

       

       

       

      this.createEmptyMovieClip("maskMC",5);

       

      maskee.cacheAsBitmap = true;
      maskMC.cacheAsBitmap = true;

       

      maskee.setMask(maskMC

       

      var i:Number = 0;

       

      maskMC.onEnterFrame = function() {

       

      if (i < 20) {
        obj = this.attachMovie("gradient_mask","mask_circle" + i,10 + i);
        obj._x = Math.random()*Stage.width;
        obj._y = Math.random()*Stage.height;
        i++;
      }
      };
      stop();

        • 1. Re: Ending an animation with code
          Ned Murphy Adobe Community Professional & MVP

          Put an else section on that conditional

           

          maskMC.onEnterFrame = function() {

           

          if (i < 20) {
            obj = this.attachMovie("gradient_mask","mask_circle" + i,10 + i);
            obj._x = Math.random()*Stage.width;
            obj._y = Math.random()*Stage.height;
            i++;
          } else {

               // do whatever you need to do

          }
          };

          • 2. Re: Ending an animation with code
            Rothrock Level 5

            And unless you need to generate 20 new circles 30 times a second (or whatever your frame rate is) then you don't need to put this in an onEnterFrame handler.

             

            In fact I'm guessing that you want to generate 20 new circles and then move them around or something?

             

            In that case you would just do this:

             

            stop();

            for(var i=0;i<20;i++){
              obj = maskMC.attachMovie("gradient_mask","mask_circle" + i,10 + i);
              obj._x = Math.random()*Stage.width;
              obj._y = Math.random()*Stage.height;
              i++;
            }

             

             

            maskMC.onEnterFrame=function(){

            // whatever code you wanted to happen at your frame rate.

            }

            • 3. Re: Ending an animation with code
              chewbears Level 1

              Thanks for the replies, but maybe my issue is something else.  As when I do Rocks suggestion and go to the start of my page (first page after the animation the alpha becomes black and just covers the screen.  So what I want is when the random mask makes my mainpage appear I want it to stop and then move to the next frame.  Right now it stops but the page changes the alpha to black so I get a black screen.

              • 4. Re: Ending an animation with code
                Rothrock Level 5

                Not really sure what you mean. Alpha is a measure of transparency so there is no black in regards to alpha. Only transparent or not transparent. In any event I don't see any alpha in this code so that must be elsewhere.

                 

                The next thing is that you are talking about a mask, but I don't see any mask here. So what are you masking?

                 

                Also you talk about "pages" but flash doesn't have any pages. There are only frames and movieclips and a bunch of other things, but no pages. So what do you mean there?

                 

                Also you talk about moving to the next frame, but there is no code here for that. In fact there is a stop() which prevents the playhead from moving to the next frame.

                 

                So I guess the question is, "What are you trying to do?"

                 

                PS: I made a mistake in my code. You will only get 10 circles because I left the i++ at the end of the loop there. Take that last line of code out if you want 20 instead of 10.

                • 5. Re: Ending an animation with code
                  Rothrock Level 5

                  Oh I do see the mask code! D'uh. It is in the original post. Sorry. I was looking at Ned's version.

                   

                  Are you trying to have a circle mask a bit of your clip and then after a bit of time have another circle appear and so on?

                   

                  That would be very different. So ignore what I said before. I think this is what you want:

                   

                  stop();
                  this.createEmptyMovieClip("maskMC",5);


                  maskee.cacheAsBitmap = true;
                  maskMC.cacheAsBitmap = true;


                  maskee.setMask(maskMC);
                  var i:Number = 0;


                  maskMC.onEnterFrame = function() {
                  if (i < 20) {
                    obj = this.attachMovie("gradientMask", "mask_circle" + i, 10 + i);
                    obj._x = Math.random() * Stage.width;
                    obj._y = Math.random() * Stage.height;
                    i++;
                  } else {
                    delete maskMC.onEnterFrame;
                    nextFrame();
                  }
                  };

                   

                  Each frame a new gradient circle would be added tot he masking clip and reveal a bit more of the maskee. Once 20 of these circles have been attached the onEnterframe will stop and the main timeline will go to the next frame.

                   

                  Is that what you were trying to do, before I "helped"?

                  • 6. Re: Ending an animation with code
                    chewbears Level 1

                    Have a meeting but will try it when I get back

                     

                    Seems like what I want as the mask needs to go at some point after its loaded, so I will try the delete command when I get back to my desk

                     

                    Thanks

                    • 7. Re: Ending an animation with code
                      chewbears Level 1

                      I think the problem is that this animation is on the main timeline.  Now basically nothing happens as I think its just loading the next frame rather then playing the animation.  The animation is on the root so I think the bit of code you posted is killing the animation before it can load.  Any other thoughts?

                       

                      I am looking for some bit of code the recognizes the circles have been drawn and at that moment the page is displayed so remove the mask and move to the next frame.

                       

                      EDIT : To make things easier I would also take a bit of code in the root that just deletes the mask at a certain point in the timeline.  Because as soon as I move in the timeline the mask just shows up black hence a black screen.

                      • 8. Re: Ending an animation with code
                        chewbears Level 1

                        Fearing I may have to give up on this animation style for an intro.

                        • 9. Re: Ending an animation with code
                          Rothrock Level 5

                          I'm confused what you mean. For me this stops on a frame, masks a circle every 1/30 of a second, when it has done that 20 times it moves to the next frame.

                           

                          What problem are you having?

                           

                          Do you mean that the maskee clip isn't playing properly?

                          • 10. Re: Ending an animation with code
                            chewbears Level 1

                            Rock,

                             

                            It basically doesn't wait for the circles to be drawn when I am working from the Root.  It works fine anywhere else.  But since it doesn't like the stage size when I move it in somewhere I am just scrapping the idea.  I will hand it to you, it does work but just not from the root timeline.  THank you for your assistance.