You have to remember that flex renders according to the component lifecycle. There's a global timer that runs independent of everything else (according to the FPS the movie is playing) that more or less watches the objects in the display list and with each timer tick will re-render the objects that have been flagged as needing such. So when you say Alert.show(...), a new display object is created and stuck into the display list, but it won't be set up and shown until the next sweep of this global timer. Also, flash is not multithreaded, so your current method must finish executing before the rendering timer event method can be executed, so semaphores are not possible (you can't stay in a loop waiting for another operation to complete, it will never happen). Therefor you are forced you to rely on event listeners to interact with this object.
On Thu, Aug 27, 2009 at 4:43 AM, Nick Middleweek <[email protected]>wrote: > > > Why won't it work? I can't see why it wouldn't... I'm still learning Flex > so perhaps I've overlooked something. > > I do agree, it is bad coding but I can't see why it wouldn't work. > > The boolAlertContinue variable is in affect acting like semaphore... > > > Cheers, > Nick > > > > > 2009/8/27 Tracy Spratt <[email protected]> > > >> >> No, no, no, this will not work. You must use the event mechanism. >> >> >> >> Tracy Spratt, >> >> Lariat Services, development services available >> ------------------------------ >> >> *From:* [email protected] [mailto:[email protected]] *On >> Behalf Of *Nick Middleweek >> *Sent:* Wednesday, August 26, 2009 7:33 PM >> *To:* [email protected] >> *Subject:* Re: [Spam] [flexcoders] Question on Flex Script Execution + >> Alert.show >> >> >> >> >> >> I'm not sure if this technique is frowned upon but... >> >> >> You could have a new private var boolAlertContinue:Boolean = false; >> >> In your alertHandler function, you would set it to true... boolAlertContinue >> = true; >> >> And after the Alert.show and before the if(myAlert == 1) you need to do a >> do while loop... >> >> do { >> >> //Not sure if there's a 'dummy' command to prevent CPU hog so we'll just >> check the time... >> >> var dtmNow:Date = new Date(); >> >> } >> >> while (boolAlertContinue); >> >> >> or you could probably initialise your myAlert:int = null and in the do ... >> while loop check for (myAlert != null) >> >> >> Cheers, >> Nick >> >> >> >> 2009/8/26 Angelo Anolin <[email protected]> >> >> >> >> Hi FlexCoders, >> >> This has puzzled me a bit.. >> >> I have the following scripts in my application: >> >> private var myAlert:int; >> >> private function testFunction(evt:Event):void >> { >> Alert.show('do you want to proceed', 'Title', Alert.YES | Alert.NO, >> null, alertHandler, null, Alert.YES); >> >> if(myAlert == 1) >> { >> // Do Something here >> } >> else >> { >> // Do other thing here >> } >> } >> >> Private function alertHandler(evt:CloseEvent) >> { >> if(evt.Detail == Alert.YES) >> { >> myAlert = 1; >> } >> else >> { >> myAlert = -1; >> } >> } >> >> Now, what puzzles me is that the script after the Alert.show is triggered, >> the scripts following it are also triggered. >> >> Is there a way to ensure that the script following the Alert.show alert >> box would only be executed after the Yes or No buttons has been pressed? >> >> I won't be able to move the scripts after the Alert.show script to the >> alertHandler event since there are some objects being set / modified prior >> to the alert being called. >> >> Inputs highly appreciated. >> >> Thanks. >> >> >> > > > -- Beau D. Scott Software Engineer

