-
1. Re: count up to a particular number in Edge?
hemanth kumar r Apr 18, 2014 5:24 AM (in response to Shutterlab)Are you referring to a progress bar or just a number display?
-
2. Re: count up to a particular number in Edge?
Shutterlab Apr 18, 2014 9:30 AM (in response to hemanth kumar r)This would be a number display with a percent sign next to the numbers. For the edge of a bar graph.
-
3. Re: count up to a particular number in Edge?
hemanth kumar r Apr 18, 2014 11:55 AM (in response to Shutterlab)You can use a setinterval like in normal javascript in Animate too to create a number counter
1)Create a text fild on stage with id "Text"
2)Add the beloe code in the event after which you want the counter to start .Ex : start counting after click
var counter_delay = 200;
var max_count = 100;
var present_count = 0;
var timer = window.setInterval(stepUp,counter_delay);
function stepUp(){
present_count++;
// Change the text of an element
sym.$("Text").html(present_count);
if(present_count==max_count)
clearInterval(timer);
}
Hope this helps
-
4. Re: count up to a particular number in Edge?
Constantine J. Jul 22, 2014 11:19 AM (in response to hemanth kumar r)Thanks for the code. It works!!
How do I change the counting increment? Instead of increasing by 1, can I change it to like 5 or 10 at each increment?
-
5. Re: count up to a particular number in Edge?
Aubrey Scarza Jul 23, 2014 2:08 AM (in response to Constantine J.)where you have present_count++;
put in
present_count=(present_count+5);
worked for me.
-
6. Re: count up to a particular number in Edge?
Constantine J. Jul 23, 2014 2:56 AM (in response to Aubrey Scarza)Thanks Aubrey. It worked like a charm
But now that I can put an increment value there, there's another problem.
If i use
present_count=(present_count+5);
and
var max_count = 103;
the counter wont stop because the increment of 5 will never get a value equal to 103.
Then I tried putting (I'm not a programmer, but I think it makes sense)
if(present_count>=max_count)
I can make it stop at 105. Is there any way I can make it shows 103 as the final value?
-
7. Re: count up to a particular number in Edge?
Aubrey Scarza Jul 23, 2014 3:45 AM (in response to Constantine J.)var counter_delay = 200;
var max_count = 105;
var present_count = 0;var timer = window.setInterval(stepUp,counter_delay);
function stepUp(){
present_count=(present_count+5);
// Change the text of an element
sym.$("Text").html(present_count);
if(present_count==max_count)
{
sym.$("Text").html(103);
clearInterval(timer);
}
} -
8. Re: count up to a particular number in Edge?
Constantine J. Jul 23, 2014 4:19 AM (in response to Aubrey Scarza)Thanks Aubrey.
It's not exactly what I want because this is like forcing the counter the display a predetermined value, instead of actually counting to 103. I guess this will do for now.
Actually I've been thinking about it, and I kind of have an idea of how to do this but I can't code. Something like this:
If the present_count value is equal to max_count-10 (in this case 103-10=93), instead of using present_count=(present_count+5); , it will use present_count++; until it reach the max_count and stop.
Is this possible?
-
9. Re: count up to a particular number in Edge?
Constantine J. Jul 23, 2014 4:25 AM (in response to Constantine J.)Oh just figure out that it still create the same problem ..Silly me.
-
10. Re: count up to a particular number in Edge?
resdesign Jul 23, 2014 11:40 AM (in response to Constantine J.)Not sure what you want to do but here is a posible way:
Create a symbol with a text field
frame 1 add code:
// insert code here
if (i<103){
i++;
sym.$('Text').html(i + '%');
}
frame 2:
sym.play(0);
The other way if you are playing the timeline and want it to stop when your number reaches 103 it to use update in the timeline. I added both cases in the sample.
sample here: increment visible number.zip - Box\
-
11. Re: count up to a particular number in Edge?
krishnapritham Oct 6, 2014 8:58 AM (in response to Shutterlab)Hi there,
Thanks for the code, it works.
but to make it more interesting can the numbers count fast and then slow down exponentially to the desired number.
-
12. Re: count up to a particular number in Edge?
resdesign Oct 6, 2014 9:34 AM (in response to krishnapritham)You would probably have to do that differently for that. Let me think about it.
-
13. Re: count up to a particular number in Edge?
thatguysketch Nov 10, 2014 9:22 AM (in response to resdesign)Hey, would there be a way to restart the counter after it has reached the max_count by itself?
-
14. Re: count up to a particular number in Edge?
resdesign Nov 10, 2014 11:21 AM (in response to thatguysketch)reset the counter to 0 and then it will restart.
if (i>=103){
i=0; // resets the count to 0
}
-
15. Re: count up to a particular number in Edge?
thatguysketch Nov 10, 2014 11:35 AM (in response to resdesign)thanks, worked like a charm. Also, I was wondering if you could always keep a 3 digit hold so if it was at 1 it would say 001, or put commas when you're in the thousands.
-
16. Re: count up to a particular number in Edge?
resdesign Nov 10, 2014 11:45 AM (in response to thatguysketch)That would be more complicated but I'll try to post a sample later today.
-
17. Re: count up to a particular number in Edge?
thatguysketch Nov 10, 2014 12:36 PM (in response to resdesign)ok, thanks. I'm going to keep playing around with it.
-
18. Re: count up to a particular number in Edge?
resdesign Nov 11, 2014 9:31 AM (in response to thatguysketch)I have a counter with 3 digits working as expected. it stops at 999.
Here is the code in compositionReady- you have 3 text fields named units, tens, hundreds.
Let me know if you want the file though this is not hard to reproduce.
units = 0;
tens = 0;
hundreds = 0;
sym.$('units').html(units);
sym.$('tens').html(tens);
sym.$('hundreds').html(hundreds);
var t = setInterval(function(){myCounter()}, 10);
function myCounter() {
units++;
sym.$('units').html(units);
sym.$('tens').html(tens);
sym.$('hundreds').html(hundreds);
if(units==9){
units = 0;
tens++;
}
if(tens==9){
//units = 9;
tens = 0;
hundreds++;
}
if ( hundreds == 9){
clearInterval(t);
units = 9;
tens = 9;
hundreds =9;
sym.$('units').html(units);
sym.$('tens').html(tens);
sym.$('hundreds').html(hundreds);
}
}
-
19. Re: count up to a particular number in Edge?
resdesign Nov 11, 2014 9:30 AM (in response to thatguysketch)By the way if you want to stop the counter at a certain number change the last if statement to something like this.
// stop at 103
if (hundreds==1 && tens==0 && units==3){
clearInterval(t);
}
-
20. Re: count up to a particular number in Edge?
thatguysketch Nov 11, 2014 9:56 AM (in response to resdesign)Thanks, it works. I found out a little variation of the code:
var counter_delay = 20;
var max_count = 999;
var present_count = 489;
var timer = window.setInterval(stepUp, counter_delay);
function stepUp() {
present_count++;
// Change the text of an element
sym.$("Text").html(Array(Math.max(3 - String(present_count).length + 1, 0)).join(0) + present_count);
if (present_count >= 999) {
present_count = 0; // resets the count to 0
}
}
This will count to a specific number and also have the "0" padding.
-
21. Re: count up to a particular number in Edge?
resdesign Nov 11, 2014 10:15 AM (in response to thatguysketch)Cool! That what I always say: "There are many way to do the same thing!" Some are more efficient than others and probably yours is better.





