2 Replies Latest reply on Nov 3, 2008 7:07 AM by Gregory Lafrance

    How to confirm exit from Panel?

      I would like for the user to be able to go to the top menu of my application and choose to load another panel into the main vbox of the application. But the user may have unsaved data in the current panel in the vbox before the next panel is loaded to replace it (ie: using vbox.removeChild(currentpanel) and vbox.addChild(newpanel)). So I can trap for the "remove" event of currentpanel to determine if there is unsaved data to determine if data needs to be saved. At this point I would like to use an Alert.show() to confirm exit or simply cancel exit and stay in the current panel. Unfortunately, Alert.show() won't return a value and instead makes you write an event handler to determine what the user did. But by this time, since the Alert.show() is the last line of the remove event handler, the event handler finishes executing and vbox.removeChild() also finishes executing. The event object in the remove event handler is also not canceable and thus event.prevenDefault() can not cause vbox.removeChild() from occurring.

      What's the "Flex" way of achieving the desired behavior?

        • 1. Re: How to confirm exit from Panel?
          m_hartnett Level 3
          Here is some basic logic that you might be able to use. It involves executing some other method prior to executing the method that removes the item from the vbox

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
          layout="absolute" backgroundImage="" backgroundColor="white">

          import mx.events.CloseEvent;
          import mx.controls.Alert;

          //method gets called from the menu
          private function changeItem() : void {

          if(textItem.text > "") {
          Alert.show( "Changes made .. save them. ",
          "Confirm", Alert.YES| Alert.NO,
          null, answerCallback, null, Alert.NO);


          protected function answerCallback(event:CloseEvent) : void {

          if (event.detail==Alert.YES)
          //do something here and save the data or just return


          protected function changeItemInBox() : void {
          vboxContainer.addChild(new TextInput());

          <mx:VBox height="128" width="216" x="10" y="14" id="vboxContainer">
          <mx:TextInput id="textItem"/>
          <mx:Button x="333" y="10" label="menu button" click="changeItem()"/>
          • 2. Re: How to confirm exit from Panel?
            Gregory Lafrance Level 6
            If you are using a navigation container like ViewStack or TabNavigator, etc. to allow user to switch among the "views", you can check for unsaved data in the change event handler.