Fighting Child Sex Slavery via ActionScript
April 11, 2012 10:18 AM   Subscribe

I am creating a Flash presentation for a fundraiser combatting child sex slavery. It will show a stopwatch, and every two minutes a number will increment showing how many children have been taken. I have it all put together in Flash CS4, but am a visual design person flummoxed on making the script for incrementing the dynamic text by 1 every 120 seconds. Any actionscripters out there who can advise will be helping a fantastic cause. Thanks!
posted by Scoo to Computers & Internet (11 answers total) 1 user marked this as a favorite
 
Based on timer script from here:
http://www.ilike2flash.com/2009/07/time-delay-in-actionscript-3.html


var myDelay:Timer = new Timer(120000);
myDelay.addEventListener(TimerEvent.TIMER, inc);
myDelay.start();
var numbercount:int =0;

function inc(event:TimerEvent):void{
numbercount++;
textbox.text=numbercount;
}
posted by RobotHero at 10:40 AM on April 11, 2012


I'm assuming you're looking for something like this?

I also uploaded the source .fla and linked to it in that post. I hope it helps. It's pretty much what RobotHero has.
posted by royalsong at 10:54 AM on April 11, 2012


Response by poster: Do I give my dynamic text box the instance name textbox?

royalsong, I can't open the file... ideas?

Thanks, this will be a huge load off my mind if I can get it working.
posted by Scoo at 11:28 AM on April 11, 2012


"Do I give my dynamic text box the instance name textbox?"

Yes. Or change the code to use your instance name in place of 'textbox.'
posted by RobotHero at 11:44 AM on April 11, 2012


huh, does it give you any errors when you try? I saved it in cs4 format.. (I run cs5)

Does this one work?

If not, the code i used is below.

---------------

var totalChildren:Number = 0;
childTxt.text = String(totalChildren);

var childTimer:Timer = new Timer(120000);
childTimer.addEventListener(TimerEvent.TIMER, timerListener);

childTimer.start();

function timerListener (e:TimerEvent):void {
totalChildren++;
childTxt.text = String(totalChildren);
}

---------------

childTxt would be the textbox you want to show the count of children taken.
posted by royalsong at 12:05 PM on April 11, 2012


Response by poster: royalsong,
What's happening:
After 120 seconds number increments to 1
After another 120 seconds it toggles to 0 and then back to 1
Another 120 seconds it toggles from 0 to 1 to 2.

If I change milliseconds from 120000 to 1000 it counts off as expected.
posted by Scoo at 1:05 PM on April 11, 2012


Response by poster: Annnd now it seems to be working. Going to let it run for a while and see if any weirdness crops up. Thank you so much!
posted by Scoo at 1:17 PM on April 11, 2012


Is the timeline where you put this code a single frame or are you cycling through an animation that's 120 seconds long? (Probably a stop-watch animation?)

If you put it in an animation that's playing, it will run the code again every time it comes around to the frame with the code. If that were happening, it would explain that it resets it to 0 again, because the code sets it back to 0. And it goes up by more numbers each time, because it creates multiple Timers running simultaneously.

If that's what's going on, take your stopwatch animation and put it inside a movieclip so your main timeline can be just one frame long again.

Or, if it's really important to sync the number with the animation, you might exploit this by putting just the contents of your timer function directly in the frame. But I'll add some extra stuff because you can't set totalChildren to 0.

var totalChildren:int=int(childTxt.text);
childTxt.text = String(totalChildren+1);

Then make sure your initial text box contains a sensible number .
posted by RobotHero at 1:20 PM on April 11, 2012


Response by poster: I do have a stop watch animation (60 frames, 1 fps) as a movie clip. Code is in a single frame in it's own layer. Looks like your revision is working. Gonna let it run for a bit and see how it goes. Thanks once more, you've saved my bacon!
posted by Scoo at 1:46 PM on April 11, 2012


Response by poster: Each subsequent increment is happening a second later. 5 increments after 2 minutes 5 seconds, 6 increments 2 minutes six seconds later and so on.
posted by Scoo at 2:03 PM on April 11, 2012


Response by poster: OK going with original code is producing consistent results; Mac app and .swf differ a bit in timing, but are incrementing at the same time. Thanks again!
posted by Scoo at 2:33 PM on April 11, 2012


« Older How to decorate a new marketing department?   |   A taxing situation Newer »
This thread is closed to new comments.