Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Fast, smooth, 'counter' function?

Posted on 2004-03-24
7
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

604 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