[COLOR=red]MORE HELP NEEDED DOWN BELOW! <3[/COLOR]
Hello everyone, this is my first post on the Kirupa Forum, but won’t by my last. I’m new to scripting languages but as an aspiring graphic designer I am trying to learn flash. I’m sure this will all be very easy for most of you to fix.
Anyway, I’m trying to make a second counter that updates every second in the output window and I am pretty ■■■■ close but I can’t seem to get this to work! I need it to count up from 1 infinitely.
I made this model but it doesn’t work because the loop always resets the variable onTimer to 1 then add’s 1 making the output say, “2, 2, 2, 2, 2, 2, etc”
[COLOR=dimgray]var timer:Timer = new Timer(1000);[/COLOR]
[COLOR=dimgray]timer.addEventListener(TimerEvent.TIMER, onTimer);[/COLOR]
[COLOR=dimgray]timer.start();[/COLOR]
[COLOR=dimgray]function onTimer(e:TimerEvent):void [/COLOR]
[COLOR=dimgray]{[/COLOR]
[COLOR=dimgray]var now:Number = (1); now++; [/COLOR]
[COLOR=dimgray]trace(now);[/COLOR]
[COLOR=dimgray]}[/COLOR]
[COLOR=dimgray][COLOR=black]I know[/COLOR] [/COLOR]I need to create the now variable outside the onTimer because this is accessed every second. So I tried this but it doesn’t work and I’m starting to get really confused.
[COLOR=dimgray]var timer:Timer = new Timer(1000);[/COLOR]
[COLOR=dimgray]timer.addEventListener(TimerEvent.TIMER, onTimer);[/COLOR]
[COLOR=dimgray]timer.start();[/COLOR]
[COLOR=dimgray]function onTimer(e:TimerEvent):void [/COLOR]
[COLOR=dimgray]{[/COLOR]
[COLOR=dimgray]var then:Number = (0);[/COLOR]
[COLOR=dimgray]then.addEventListener(TimerEvent.TIMER, addTo);[/COLOR]
[COLOR=dimgray]}[/COLOR]
[COLOR=dimgray]function addTo(e:TimerEvent):void[/COLOR]
[COLOR=dimgray]{[/COLOR]
[COLOR=dimgray]var now:Number = then++;[/COLOR]
[COLOR=dimgray]trace(now)[/COLOR]
[COLOR=dimgray]}[/COLOR]
Thanks for your help!