Solved

Fast, smooth, 'counter' function?

Posted on 2004-03-24
7
182 Views
Last Modified: 2010-04-03
I would like a function that, when called, counts smoothly from 0-100 in, say, 300 milliseconds.

I will use the counter value to control the alpha property of an mc.

What is the best way to do this?
0
Comment
Question by:SandyCooke
  • 3
  • 2
  • 2
7 Comments
 
LVL 4

Expert Comment

by:RedLava
ID: 10673146
Hi SandyCooke

The best option to get a smooth count is to use setInterval().

== Demo ==

To test this demo create a textbox with an instance name of 'counter' on the main timeline.

Also add the following actionscript to the main timeline:

  function incCounter() {
    counter.text++
   if (counter.text == 100) clearInterval(counterID);  // Stop counter at 100.
  }

Then create a button with an instance name of 'startButton' that will call the following actionscript from the main timeline:

  startButton.onRelease = function () {
    counter.text = 0; // Start counter from 0.
    counterID = setInterval(incCounter, 300); // 300 millisecond interval.
  };

Good luck

RedLava
0
 
LVL 2

Author Comment

by:SandyCooke
ID: 10689228
Hi RedLava

Rather than count from 0-100 in 300 milliseconds, does this technique not just increase the value of counter.text every 300 milliseconds?

I do get the necessary result if I set the frame-rate of the movie to 100+ fps and reduce the interval to -10, but surely this is bad practice?

Or is there no other way?
0
 
LVL 9

Expert Comment

by:krishnaprathab
ID: 10706140
Just change the code to :

startButton.onRelease = function () {
    counter.text = 0; // Start counter from 0.
    counterID = setInterval(incCounter, 3000);
};

- KP
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 
LVL 2

Author Comment

by:SandyCooke
ID: 10709911
Hi krishnaprathab, hi RedLava

Rather than count from 0-100 in 300 milliseconds, does this technique not just increase the value of counter.text every 300(0) milliseconds?

I do get the necessary result if I set the frame-rate of the movie to 100+ fps and reduce the interval to less than 10 milliseconds, but surely this is bad practice?

Or is there no other way?
0
 
LVL 4

Accepted Solution

by:
RedLava earned 250 total points
ID: 10709964
Hi SandyCooke,

counter.text can be any variable. I only used a text item to display it.

It can be just a variable named "theCounter" or whatever.

To get it to count 0-100 in 300 milliseconds you need to set the interval value to (300/100) => 3.

e.g

  startButton.onRelease = function () {
    counter.text = 0; // Start counter from 0.
    counterID = setInterval(incCounter, 3); // 3 millisecond interval.
  };

If you alter your frame rate this may cause other issues with the running of your movie.

Hope this helps,

RedLava
0
 
LVL 2

Author Comment

by:SandyCooke
ID: 10713346
>> To get it to count 0-100 in 300 milliseconds you need to set the interval value to (300/100) => 3
0
 
LVL 9

Expert Comment

by:krishnaprathab
ID: 10868859
No Assist :(
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question