?
Solved

Fast, smooth, 'counter' function?

Posted on 2004-03-24
7
Medium Priority
?
188 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

770 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