function - Flex 4 timers keep Firing -


i'm trying create simple flex4 project involves timers trigger other functions.

i don't have experience action script , less timer events.

here bit of code seems working part lines i'm adding total score (score = score +1;) seems keep adding , adding when test application. think because timers keep firing function i'm not sure.

            private var score:int = 0;          private function submit():void {             this.currentstate = 'loading';             var timer:timer = new timer(2200);             timer.addeventlistener(timerevent.timer, removeloading);             timer.start();         }          private function removeloading(event:timerevent):void{             removeloading.play();             var timer1:timer = new timer(1000);             timer1.addeventlistener(timerevent.timer, viewresults);             timer1.start();             this.currentstate = 'results';         }          private function viewresults(event:timerevent):void{              if (q1_t.selected == true){                 answer1m.text = 'you answer question correctly.';                 score = score +1;              } else {                 answer1m.text ='the correct answer was: '+ q1_t.label;             }              if (q2_f.selected == true){                 answer2m.text = 'you answer question correctly.';                 score = score +1;              } else {                 answer2m.text ='the correct answer was: '+ q2_f.label;             }              finalscore.text = score.tostring();         } 

so did bit more research , turns out hadn't included second timer parameter.

the second parameter number of times timerevent.timer event dispatched before stopping. if set second parameter 0 (zero) or omitted completely, timer run forever (or until called stop() method on timer instance.

since want run event once need add 1.

from this:

var timer:timer = new timer(2200); 

to this:

var timer:timer = new timer(2200,1); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -