This loop is running and your timer callback function has not yet set the Boolean to true
while (counter<1000) { if (generalFlag==true) { trace("hello"); counter++; } } And then it get in the infinite loop Best regards, Cor van Dooren www.codobyte.com ------------------------------------------------------------------ "There are only 10 types of people in the world: Those who understand binary and those who don’t." -----Original Message----- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of nasim hhhhh Sent: maandag 29 augustus 2011 20:29 To: Flash Coders List Subject: RE: [Flashcoders] loop and Timer problem????????? in main i call testhalgheh(); so inside it timer will start it stuck in loop untill it get true in logic I think when the timer start it shouldnt related to thing so during loop the timer event should work and code if(generalFlag==true) { trace("hello") counter+=1; } should work but the test show the flag doest get true why is that the timer shoudl work independently --- On Mon, 8/29/11, Cor <c...@chello.nl> wrote: From: Cor <c...@chello.nl> Subject: RE: [Flashcoders] loop and Timer problem????????? To: "'Flash Coders List'" <flashcoders@chattyfig.figleaf.com> Date: Monday, August 29, 2011, 2:01 PM 1. You call the function but your timer does not exist 2 your Boolean never get true so your loop in infinite. Try this: var forsate,generalFlag:Boolean; var counter:int=0; var generalTimer:Timer=new Timer(10); testhalgheh(); function generalfunc(e:TimerEvent=null):void { generalFlag=true; //trace( " generalFlag " + generalFlag) } function testhalgheh():void { generalTimer.addEventListener(TimerEvent.TIMER,generalfunc); generalTimer.start(); while (counter<1000) { //if (generalFlag==true) { trace("hello"); counter+=1; //} } } Best regards, Cor van Dooren www.codobyte.com ------------------------------------------------------------------ "There are only 10 types of people in the world: Those who understand binary and those who don’t." -----Original Message----- From: flashcoders-boun...@chattyfig.figleaf.com [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of nasim hhhhh Sent: maandag 29 augustus 2011 19:55 To: Flashcoders@chattyfig.figleaf.com Subject: [Flashcoders] loop and Timer problem????????? what is the problem ? how Timer work that the loop stuck in the program???????????? I cant understand the loop and Timer increase cpu usage?????? var forsate,generalFlag :Boolean; var counter:int; var generalTimer:Timer = new Timer(1); testhalgheh() generalTimer.addEventListener(TimerEvent.TIMER,generalfunc); function generalfunc(e:TimerEvent=null):void { generalFlag=true; //trace( " generalFlag " + generalFlag) } function testhalgheh():void { generalTimer.start(); while(counter<1000) { if(generalFlag==true) { trace("hello") counter+=1; } } } _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders