ActiveDen

Interval Help

3860 posts
  • Has been a member for 5-6 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Author had a Free File of the Month
  • Beta Tester
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
  • Referred between 200 and 499 users
flashjunkie says

Hey guys,

I have an interval and its length is changed dynamically, what i want to know is…

Is there a way to calculate the percentage of time that has elapsed whilst the interval is running.

For example if my interval is 4000 (4 seconds) and it is running and is at 1000(1 second) is there a way to find out that the percentage is 25%?

Hope this makes sence.

Jay

3 years ago
2309 posts
  • Has been a member for 4-5 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Beta Tester
  • Exclusive Author
  • Sold between 100 and 1 000 dollars
  • Bought between 1 and 9 items
  • United States
  • Referred between 10 and 49 users
theflyingtinman says
Hey guys,

I have an interval and its length is changed dynamically, what i want to know is…

Is there a way to calculate the percentage of time that has elapsed whilst the interval is running.

For example if my interval is 4000 (4 seconds) and it is running and is at 1000(1 second) is there a way to find out that the percentage is 25%?

Hope this makes sence.

Jay

Could be wrong but I’m pretty sure there is no function to query the currently elapsed time of a running interval. You would have to record the time when the interval is started then query the elapsed time when you want to calculate the percentage of the interval time elapsed.

3 years ago
6 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Sold between 1 000 and 5 000 dollars
  • Bought between 10 and 49 items
pedropoc says

I think theflyingtinman is right.

I would do something like this (just to give you an idea):

Sorry about the format, just copy and paste in flash to see formatted code.

var intervalValue = 4; var elapsedSeconds = 0;

// your interval var yourInterval = setInterval(onYourInterval, 1000*intervalValue); // seconds interval var timer = setInterval(onTimer, 1000);

function onTimer(){ // this adds 1 second to the timer every second elapsedSeconds += 1; }

function onYourInterval(){ trace(“your interval triggered.”) }

function showPercentage(){ trace( “the percentage is ”+ ((elapsedSeconds / intervalValue) * 100) + ”%” ); }

btn.onRelease = function(){ showPercentage(); }

3 years ago
3860 posts
  • Has been a member for 5-6 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Contributed a Tutorial to a Tuts+ Site
  • Contributed a Blog Post
  • Author had a Free File of the Month
  • Beta Tester
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
  • Referred between 200 and 499 users
flashjunkie says

yeah iv just been working on something very similar :D

Thanks guys.

3 years ago
1234 posts
  • Has been a member for 3-4 years
  • Exclusive Author
  • Sold between 50 000 and 100 000 dollars
  • Elite Author
  • Bought between 10 and 49 items
  • United States
  • Referred between 50 and 99 users
MBMedia says

in AS3 we have getTimer() which returns the number of elapsed milliseconds since the movie started, and I believe AS2 has it too. (just checked, it does)

So call getTimer() when you start the interval and getTimer() when you want to check it, subtract the two and bingo, elapsed time of your interval without tracking and adding it up :D

3 years ago
900 posts
  • Has been a member for 5-6 years
  • Beta Tester
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Bought between 10 and 49 items
  • Netherlands
  • Referred between 50 and 99 users
michelsteege says

in as2 and 3 there is a timer :) (don’t know much about the timer in as2 though) in 3 you can replace your interval with the timer what you also can do is start a timer when you set the interval and when it stops or changes check your timer :)

3 years ago
by
by
by
by
by