1 Reply Latest reply on Aug 17, 2006 7:13 AM by peterent

    Suspend execution till an event is triggered ?

      Hello all,

      We are trying to migrate an application written in a procedural language (=not based on events) to Flex and ActionScript.
      For the moment everything is OK, except an issue we have which may force us to rewrite the biggest part of the app :

      In our current version of the application, the code looks like this :
      MyCustomer = OpenWindow("SelCust")
      ProcessOrder("MyCustomer") //Inside this function, a Window is opened and closed

      With Flex & AS3, we use the PopupManager class to open a Modal Window. The problem is that the code continues to execute without waiting for the window to be closed... So we are looking for a way to suspend the execution of our code. We tryied to use a global variable like this :
      WindowOpen = true;
      mx.managers.PopUpManager.createPopUp(CurWin, TitleWindow, true, obj); //Inside this Window the WindowOpen variable is set to false when the window is closed

      while (WindowOpen)
      //Wait till the Window is closed
      ... code continues
      The problem is that the application hangs in the While() loop and we have to kill the process :-(

      So here are our questions :
      - Is there a way to suspend the execution of a as3 code till an event is triggered ?
      - Is there a call we could do in the While() loop to avoid the hang of the app (like Windows' message queue functions) ?
      - Would someone have an idea that would allow us to convert our current procedural code into Flex&AS3 without rewriting the hundreds of procedures in "event" mode ?

      Thank you in advance for your help and advices.

      PS : Please forgive my bad english :-(
        • 1. Re: Suspend execution till an event is triggered ?
          peterent Level 2
          You cannot suspend execution of the Flash Player or it will hang as you have seen. You are kind of butting heads with the two paradigms. Our "modal" pop-up simply means that the user cannot interact with the rest of the application, but it does indeed continue to run (this allows the Flash Player to update the display should you drag the dialog box around, or allow data to be received from remote services, etc.).

          You may not have a big re-write here. Try something like this:

          OLD CODE

          popup the dialog();
          ... code continues

          NEW CODE
          popup the dialog();
          add event listener for "close" event on the popup
          exit the function

          in the "close" event handler, execute the "code continues" part now that the dialog has been closed.