Solved

Fast, smooth, 'counter' function?

Posted on 2004-03-24
7
186 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

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!

Question has a verified solution.

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

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
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…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

691 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