7 Replies Latest reply on Dec 5, 2009 7:58 PM by acoquinar

    Need a way to confirm changes !

    acoquinar

      This should be a very common need !

       

      I have a viewstack that holds many Cancas defined as custom components.

       

      Each of those canvas contain various controls that the user can manipulate.

       

      If the user, using the navigation control, switches from one view to another, i must be able to ask him, before the current view gets replaced by the viewstack, if he want his modifications to be applied.

       

      I don't know if there is an event that could do the job and which component would send that event... I am looking for something like this.addEventListener ("Event.aboutToBeRemoved", "aboutToBeRemovedHandler()").

        • 1. Re: Need a way to confirm changes !
          iamfuric

          What is the navigation control you are using ?

          How dou you swicth views in view stack ?

          • 2. Re: Need a way to confirm changes !
            Phoenix_Guru Level 1

            I am sure that you would have to use the Hide event

            for doing the check. For calculating whether any changes were made, a ChangeWatcher may be a probable solution for you.

             

            Thanks,

            Saurabh

            • 3. Re: Need a way to confirm changes !
              acoquinar Level 1

              The navigation is done with a series of linkButtons contained in 5 canvas under an accordion control.

               

              Thanks for the answers posted so far... it gives me reasons to hope !!

              • 4. Re: Need a way to confirm changes !
                iamfuric Level 2

                Here is the idea :

                1. Add Mouse.click event  listener for you navigator in CAPTURING !!!! phase

                2. in event listener :

                     a. clone event to clonedEvent variable

                     b. call stopImmediatePropogation on original event

                     c. show "Are you sure" dialog

                     d. on OK dispatch clonedEvent on clonedEvent.target.

                 

                Hope this will help

                • 5. Re: Need a way to confirm changes !
                  acoquinar Level 1

                  Thanks iamfuric, i was already thinking about doing just that... the problem is that i must access the flag inside the custom component that reveals if something was changed by the user... that flag is set to True when something actually needs to be saved.

                   

                  The navigator is inside the main application mxml file... how could he get access to this variable flag ?... Custom component aren't class ... at least i don't think they can act as such...

                   

                  Am i missing something here ?

                  • 6. Re: Need a way to confirm changes !
                    iamfuric Level 2

                    Custom component is indeed class.

                    You can cast viewStack.selecteChild to your custom class and access your class variable.

                    But I would recommend to decople navigator's logic from "view" logic, say, using an interface:

                     

                    interface MyInterface{

                         function wasChange():Boolean

                    }

                    MyCustomView.mxml:

                     

                    <mx:Box implements="mypackage.MyInterface">

                    <Script>

                         public function wasChange():Boolean{

                              return logic....

                         }

                    </Script>

                     

                    </mx:Box>

                     

                    in navigator:

                    onClick(){

                         if (viewStack.selectedChild as MyInterface).wasChange(){

                              ..clone event and ......see previous reply

                         }

                    }

                    • 7. Re: Need a way to confirm changes !
                      acoquinar Level 1

                      WOW thanks iamfuric.

                       

                      This is exactly what i thought would be have been incredible if it was to be missing from the flex framework.

                       

                      thanks again !