5 Replies Latest reply on Jun 24, 2009 10:43 AM by Rothrock

    Help on getTimer() function = affects the main animation...

    xxxheeroxxx Level 1

      Layers scenarios:

       

      Layer 1: pics animation

      Layer 2: text animation

      Layer 3: graph animation

      Layer 4: a movieclip()

       

      Here's goes, inside the movieclip on Layer 4 it is nested down to bubble movieclip which inside is an actionscript that animates the premade animation for the bubble just attaching those movieclips to an empty movieclip.

       

      The problem goes like this when I test the movie in the first maybe 5 or 10 seconds the animation seems just fine but after several seconds the animation becomes slower in the root timeline. It seems that getTimer() affects the animation, as far as I know getTimer() function returns the time the swf file begin playing in milliseconds. The code I was working on is based on the getTimer().

       

      What would be the work-around with this kind of scenario? I guess theres another function that works the same as getTimer that cannot affect my main animation.

       

      By the way, my animation on Layer 4 which is nested movieclip is a random bubbles with total of 200 instances.

       

      Thanks and more power to us all!

        • 1. Re: Help on getTimer() function = affects the main animation...
          DazFaz Level 1

          You might want to consider using "setInterval" for yout timer but in all honestt I think your problem might well br with trying to animate so many instances at the same time.

           

          If this is the case try ticking the "Use runtime bitmap caching" on each of the property tabs for each instance.

           

          If you want to set this using code then its "instanceName.cacheAsBitmap = true"

           

          This is just a first thought but I hope it helps.

          • 2. Re: Help on getTimer() function = affects the main animation...
            Rothrock Level 5

            Yes getTimer() returns the number of milliseconds that instance of the Flash player has been running.

             

            There is nothing in getTimer() that will slow down your file. Unless you are doing millions of calls to getTimer(), I guess....

             

            My guess is that the problem lies here, "....The code I was working on is based on the getTimer()....." The code that is based on the getTimer() is likely the problem.

             

            You will get a lot more help and people will be able to answer questions if you actually share the code that you are using.

             

            As for 200 movieclips. Depending upon what they are doing most modern systems running Flash player 9 or higher shouldn't really have a problem with that. Of course there are plenty of ways to stuff it up with even 1 clip. And I'm guessing that setInterval will probably make your situation worse.

             

            What are you actually trying to do?

            • 3. Re: Help on getTimer() function = affects the main animation...
              xxxheeroxxx Level 1

              It has different movieclips in the library float 1-3 which is nested, inside is an animation with a motion guide to an empy movieclip in which will be attached through actionscript,  2.0 version. And a bubble1_mc which is a nested movieclip called in actionscript through a linkage also with an animation inside.

               

              Thanks for the reply here's the code.

               

              ==============

              CODE

              ==============

               

              total = 200;
              level = 0;
              releaseTimes = [];
              incr = 0;
              function createInterval() {
                  for (var i = 0; i<total; i++) {
                      releaseTimes.push(500+(i*50));
                  }
              }
              function createBubble() {
                  ranFloat = "float"+random(3);
                  var float = this.attachMovie(ranFloat, "float"+level, level+1000);
                  var b = float.emptyClip.attachMovie("bubble1", "bubble1"+level, level+10000);
                  float._x = random(100)+20;
                  float._y = 10;
                  b._width = b._height=random(17)+3;
                  b._alpha = random(80)+20;
                  level++;
              }
              createInterval();
              var nextTime = releaseTimes[0];
              this.onEnterFrame = function() {
                  var time = getTimer();
                  if (nextTime<time) {
                      createBubble();
                      incr = incr + 1;
                      nextTime = releaseTimes[incr];
                  }
              };

               

              Thanks and more power to you guys!

              • 4. Re: Help on getTimer() function = affects the main animation...
                Rothrock Level 5

                I haven't abandoned you, yesterday was just a crazy day. I'm looking at this and trying to figure out what the best way to go would be.

                 

                The first thing that seems a little strange is the createInterval function. That is just creating an array of 500, 550, 600, etc. So I'm taking it that you want to show a new bubble every 50 milliseconds (or so...) is that right?

                 

                You also have a variable in there that will do this 200 times. But then you have no code that recognizes when you are done with the 200 bubbles and stops trying to attach them. So do you really want only 200 bubbles over 10 seconds and then you are done?

                 

                Then your enter frame (I'm guessing you have a frame rate of 30 fps) is going every 33 milliseconds (or so) and checking the get timer. But because nextTime might be less that time more than once you will get these conditions where it isn't actually going every 50 milliseconds and instead is going every frame.

                 

                With the alpha transparency, attaching movies, and timeline animations this actually might be too much for the player as is. But I think there are some ways to play with it that might make it work.

                 

                So what is your frame rate? If you are trying to make is smoother by giving it some really high rate like 60 or 100 that won't help and will make it worse. I would recommend 30.

                 

                How long motion guide 'tweens in the empty movieclip and are they looping?

                 

                Anyways I'm thinking about it. Give me a little longer if you can....

                • 5. Re: Help on getTimer() function = affects the main animation...
                  Rothrock Level 5

                  Okay. Here is what I came up with. I'm not sure exactly what was in your timeline animated tweens. So perhaps this isn't what you wanted at all....

                   

                  All you need is the bubble artwork (set to export as "Bubble") and this code. It is full of "magic" numbers that I just fiddled with until I thought it looked pretty on my machine.

                   

                  Some important bits are the part where when the bubble gets off the top of the screen it removes itself.

                   

                  var home:MovieClip = this;

                  var counter:Number=0;
                  var totalBubbles:Number=200;

                   

                  clearInterval(bubbleIntervalID);
                  var bubbleIntervalID=setInterval(attachBubble,150);

                   

                  function attachBubble() {
                  var curBub:MovieClip = home.attachMovie("Bubble", "bubble", 1000+counter);
                  curBub.blendMode = "hardlight";
                  curBub._y = Stage.height + 100;
                  curBub._x = (Stage.width - 50) * Math.random() + 50;
                  curBub._xscale = curBub._yscale = Math.random() * 60 + 40;
                  curBub._alpha = Math.random() * 80 + 20;

                  curBub.vy=-(Math.random()*5+1)
                  curBub.ay=-Math.random()/30

                  curBub.x0=curBub._x;
                  curBub.var1=Math.random()*100;
                  curBub.var2=Math.random()*300;
                  curBub.factor1=Math.random()/100;
                  curBub.factor2=Math.random()/200;

                  curBub.onEnterFrame = floatUp;
                  counter++
                  if(counter>totalBubbles){
                    clearInterval(bubbleIntervalID);
                  }
                  }

                   

                   

                  function floatUp() {
                  this.vy += this.ay;
                  this._y += this.vy;
                  this._x = this.x0+this.var1*Math.sin(this._y*this.factor1)+this.var2*Math.sin(this._y*this.factor2) ;

                  if(this._y<(-this._height)){
                    delete this.onEnterFrame;
                    this.removeMovieClip()
                  }
                  }