2 Replies Latest reply on Sep 27, 2010 8:57 AM by LuisRM

    Making a movie stop/fade out at a certain frame

    LuisRM Level 1

      I'm looking for some help with the following code. I'm using the code and assets from this page.

      http://www.kirupa.com/developer/flash8/snow.htm

      I'm creating ads for websites and they don't allow continual  animation after 3 loops. With some help, I added to the above code to make it fade at the end. I think I'm close, but it doesn't seem to fade away as I had hoped, it just keeps  falling.

       

      Am I missing some code that I need to replace?

      Do I need to put a frame # somewhere when I  want it to fade?

      Does the last part of the code go on a frame at the  end?

      The snow just keeps falling even though it's reached the last frame. What do I add to make it stop?

       

      I appreciate the help!

       

      Here is the code. The link above will show you exactly the type of animation I'm looking at. I added the fade part after "init ( );"

       

      init = function () {
          width = 300;
          // pixels 
          height = 250;
          // pixels 
          max_snowsize = 10;
          // pixels 
          snowflakes = 50;
          // quantity 
          for (i=0; i<snowflakes; i++) {
              t = attachMovie("snow", "snow"+i, i);
              t._alpha = 20+Math.random()*60;
              t._x = -(width/2)+Math.random()*(1.5*width);
              t._y = -(height/2)+Math.random()*(1.5*height);
              t._xscale = t._yscale=50+Math.random()*(max_snowsize*10);
              t.k = 1+Math.random()*2;
              t.wind = -1.5+Math.random()*(1.4*3);
              t.onEnterFrame = mover;
          }
      };
      mover = function() {
          this._y += this.k;
          this._x += this.wind;
          if (this._y>height+10) {
              this._y = -20;
          }
          if (this._x>width+20) {
              this._x = -(width/2)+Math.random()*(1.5*width);
              this._y = -20;
          } else if (this._x<-20) {
              this._x = -(width/2)+Math.random()*(1.5*width);
              this._y = -20;
          }
      }
      init();
      
      function fadeOutAllSnow():Void {
          this.onEnterFrame = function() {
              if (snow._alpha>0) {
                  // 10 is the fade speed
                  snow._alpha -= 10;
              } else if (snow._alpha<=0) {
                  // we remove the cont_mc once its faded out
                  removeMovieClip("snow");
                  delete this.onEnterFrame;
              }
          };
      }
        • 1. Re: Making a movie stop/fade out at a certain frame
          kglad Adobe Community Professional & MVP

          at some point you need to delete all those t.onEnterFrame methods.

          • 2. Re: Making a movie stop/fade out at a certain frame
            LuisRM Level 1

            I tried to cobble two different codes together before and it obviously wasn't working, but I'm better now since the code is from one source. I've attached the fla file for viewing. I'm just stuck as to how to fade the snow out by the last frame. I put a stop so it doesn't loop, but I just can't seem to figure out how to make that snow fade out properly at the last frame.

             

            http://www.mediafire.com/file/c3jl881lc0203fa/snow_test.zip

             

            [AS]stop();

             

            // Width of area

             

            var wNum:Number = Stage.width;

             

            // Height of area

             

            var hNum:Number = Stage.height;

             

            // Max size of item

             

            var maxSize:Number = 5;

             

            // Number of items

             

            var flakesNum:Number = 150;

             

            // Area outside of 0,0,wNum,hNum before reset

             

            var buffNum:Number = 30;

             

            var i:Number = 0;

             

            var t:MovieClip;

             

            // container MC

             

            var cont_mc:MovieClip;

             

            //

             

            // Make it snow, confetti, whatever baby!

             

            startSnow();

             

            //

             

            function startSnow():Void {

             

                // Make a MovieClip so we can Attach the snow into a container MC

             

                cont_mc = this.createEmptyMovieClip("cont_mc", 1);

             

                cont_mc._alpha = 0;

             

                for (i=0; i<flakesNum; i++) {

             

                    // Attach items into cont_mc

             

                    t = cont_mc.attachMovie("snow", "snow"+i, i);

             

                    t._alpha = 20+Math.random()*60;

             

                    t._x = -(wNum/2)+Math.random()*(1.5*wNum);

             

                    t._y = -(hNum/2)+Math.random()*(1.5*hNum);

             

                    t._xscale = t._yscale=50+Math.random()*(maxSize*10);

             

                    t.k = 1+Math.random()*2;

             

                    t.wind = -1.5+Math.random()*(1.4*3);

             

                    t.onEnterFrame = moveSnow;

             

                }

             

                this.onEnterFrame = function() {

             

                    if (cont_mc._alpha<100) {

             

                        // 10 is the fade speed

             

                        cont_mc._alpha += 5;

             

                    } else if (cont_mc._alpha>=100) {

             

                        delete this.onEnterFrame;

             

                    }

             

                };

             

            }

             

            //

             

            function moveSnow():Void {

             

                // Added fade as it falls

             

                if (this._alpha>0) {

             

                    // .1 is the fade speed

             

                    this._alpha -= .1;

             

                }

             

                this._y += this.k;

             

                this._x += this.wind;

             

                if (this._y>hNum+buffNum) {

             

                    this._y = -buffNum;

             

                    // reset alpha once outside area

             

                    this._alpha = 20+Math.random()*60;

             

                }

             

                if (this._x>wNum+buffNum) {

             

                    this._x = -(wNum/2)+Math.random()*(1.5*wNum);

             

                    this._y = -buffNum;

             

                    // reset alpha once outside area

             

                    this._alpha = 20+Math.random()*60;

             

                } else if (this._x<-buffNum) {

             

                    this._x = -(wNum/2)+Math.random()*(1.5*wNum);

             

                    this._y = -buffNum;

             

                    // reset alpha once outside area

             

                    this._alpha = 20+Math.random()*60;

             

                }

             

            }

             

            // Fade Out, then remove

             

            function fadeOutAllSnow():Void {

             

                this.onEnterFrame = function() {

             

                    if (cont_mc._alpha>0) {

             

                        // 10 is the fade speed

             

                        cont_mc._alpha -= 10;

             

                    } else if (cont_mc._alpha<=0) {

             

                        // we remove the cont_mc once its faded out

             

                        removeMovieClip("cont_mc");

             

                        delete this.onEnterFrame;

             

                    }

             

                };

             

            }[/AS]

             

            Again, I'm super new at code and have been trying to get the basics down at lynda.com, but it is tough. :confused:

             

            I really appreciate it!