title: Flex: Popup Window - Get [ok] or [cancel]
body: <p>I've done a lot of C# programming with both Winforms and WPF. I'm working on a Flex/Air app now for cross platform support. But this is my first flex project, so I'm learning as I go.</p>
  
  <p>I've got a window that I want to popup, that the user will fill out a form, then hit OK or CANCEL. I set it up the same way I would've in C#, but it doesn't work, and I can't really see a way to make it do what I want.</p>
  
  <p>EDIT:
  So I'm trying events now, the events just don't seem to be handled...</p>
  
  <p>EDIT again:
  Oh, It's because the popup manager seems to create a new instance of the Form object, rather than using the one I created already.</p>
  
  <p>so in the showWindow method, I put in this code rather than the popup manager:</p>
  
  <pre><code>parent.addChild(this);
  </code></pre>
  
  <p>then I remove it when I close it. The only problem is, it doesn't disable the rest of the parent like the popup manager does. Any suggestions on that?</p>
  
  <p>PARENT:</p>
  
  <pre><code>private function btnAdd_Clicked():void
  {               
          var form:Form = new Form();
          form.addEventListener(CloseEvent.CLOSE, onFormClosed, false, 0, true);
  
          recipeForm.showWindow(this);
  }
  
  private function onFormClosed(e:CloseEvent):void
  {
      //none of these Alerts are ever shown. I also tried breakpoints in debug to try an follow the code, with no luck
      Alert.show("Closed");
      if(e.detail == Alert.OK)
      {
          Alert.show("OK");
      }
      else if(e.detail == Alert.CANCEL)
      {
          Alert.show("Cancel");
      }
  }
  </code></pre>
  
  <p>CHILD:</p>
  
  <pre><code>private function btnCancel_Clicked():void
  {
      okClicked = false;
      closeWindow();
  }
  
  public function closeWindow():void
  {
      var e:CloseEvent = new CloseEvent(CloseEvent.CLOSE);
      e.detail = okClicked ? Alert.OK : Alert.CANCEL;
      dispatchEvent(e);
      PopUpManager.removePopUp(this);
  }
  
  public function showWindow(parent:WindowedApplication):void
  {
      var window:IFlexDisplayObject = PopUpManager.createPopUp(parent, RecipeForm, true);
      PopUpManager.centerPopUp(window);
  }
  </code></pre>