|
-
Simple Money Counter Count Up
I would like to create a simple count up banner with advancing numbers like the national debt at www.usdebtclock.org.
I want to start at $0 and end up at $1,000,000,000 in exactly two weeks.
I have some AS2 experience, but this is stumpin' me.
Any help would be so appreciated.
thanks in advance,
je
-
Senior Member
Working backwards from the total, would look something like this.
There are 336 hours in 14 days,
1,000,000,000 / 336 = 2,976,190 per hour,
2,976,190 / 60 = 49,603 per minute,
49,603 / 60 = 826.7 per second
PHP Code:
var start = 0; var setInt:Number = setInterval(addToTotal, 1); function addToTotal():Void { start = Math.round(start + 82); trace(start); }
This should work, but I'm not about to take 2 weeks to test it. I choose to use setInterval due to the fact that I'm not sure how well an onEnterFrame event would handle that long a period on any given system resouces. HTH.
Last edited by Robb@exo; 03-06-2011 at 07:36 PM.
Wile E. Coyote - "Clear as mud?"
-
Thanks, Robb@exo. That certainly makes sense. You know, it doesn't have to be exact. Just counting up at that rate will certainly work.
I added the function above to a Flash project, but how do I output the var "start" into a text box? I bet this is a pretty basic question. But I am just staring at it now and shrugging my shoulders.
Thanks again.
-
Senior Member
Just take the instance name of the textfield and add this code to the setInterval function...
PHP Code:
textfieldInstanceName.text = String(start);
Wile E. Coyote - "Clear as mud?"
-
Seriously, thanks again. I'm getting it. And it works.
Lastly, how can I set this up so it the number doesn't start over everytime the flv is launched. Not a deal breaker, but it would be cool.
Again, I do appreciate people like you who help us out without affront. It does feel like a community.
je
-
Senior Member
Not sure how that would be done... but may possibly be accomplished by using 'SharedObject'. I myself have never used it, but it enables store and retrieve data. Here are a couple of links that you can read over.
http://www.flashkit.com/tutorials/Ac...1228/index.php
http://www.actionscript.org/resource...cts/Page1.html
HTH.
Wile E. Coyote - "Clear as mud?"
-
Senior Member
Since I haven't used SharedObject before, I thought it might be a challenge to try to incorporate in this. Here's what I came up with, although the number by which the total increments by may need to change, I don't think I took into account the fps of the file which in turn would effect the rate at which the total increased. As long as the total increase by around 49000 (roughly) per minute, it should be good to go. Anyways, here's my code for using a sharedObject.
PHP Code:
var num = 0;
var shared;
var setInt:Number = setInterval(addToTotal, 1);
this.onLoad = function() {
shared = SharedObject.getLocal("total");
num = checkTotal();
total.text = String(shared.data.current);
trace(checkTotal());
}
function checkTotal() {
shared = SharedObject.getLocal("total");
if(shared.data.current == undefined) {
shared.data.current = 0;
}
shared.close();
return shared.data.current;
}
function addToTotal(nm:Number):Void {
shared = SharedObject.getLocal("total");
shared.data.current = num;
shared.close();
num = Math.round(num + 24.4);
total.text = String(num);
}
Wile E. Coyote - "Clear as mud?"
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|