7 Replies Latest reply on Mar 5, 2010 1:41 PM by Francisc

    Modal Alert waiting to user click

    pyso

      Hi,

      I used to programm InDesign plugins in C++. There was modal Alert with YES/NO buttons, which stops executing till user presses one of these buttons.

      Now to my question. I know that such Alert doesn't exist here in Flex. Flex shows Alert and continues with executing following code. I know there is closeHandleFunction which I should use to handle it. ActionScript is event driven language and we should use ActionScript with this respect.So my question is more hypotetical perhaps. Is hugely bad idea to create such MyAlert class which would wait in loop till user press button? You know sometimes it would be handy to have such Alert.

       

      Thanks,

      //pyso

        • 1. Re: Modal Alert waiting to user click
          Francisc Level 3

          The Alert class in Flex is modal and does prevent user interaction with the rest of the application.

          However, it does not stop code "behind" it from executing.

           

          If that is what you mean and want it to stop execution of code, you will need to stop the components that are doing something `manually`.

          Can you give examples of what you want to stop?

          • 2. Re: Modal Alert waiting to user click
            pyso Level 1

            Yes, it was what I ment.

            Example could be that I am going through all DisplayObjects placed in Canvas and checking its property and removing these objects one by one. If  object has that property set to some value, I want the user let to decide if he/she wants to remove also that object.

            In such case would be useful to have Alert which stops executing code behind.

             

            //pyso

            • 3. Re: Modal Alert waiting to user click
              Francisc Level 3

              The only way o do this is to stop execution yourself

               

              An idea that pops to mind now is that you have a global var allowExecution:Boolean=true;

               

              When you open an Alert window you set it to false.

              When you close the Alert Window, in the closeHandler function, set it to true again.

               

              In the other functions or actions in the application, do something like

              if(allowExecution) or while(allowExecution) etc.

               

              Hope this helps.

              1 person found this helpful
              • 4. Re: Modal Alert waiting to user click
                Sebastien V. Level 3

                There is probably a better way of doing this. I think spring actionscipt provides tools to do such things, and it sure would be nice to be able to do this without tricks...

                 

                Anyhow, I was thinking of another solution, something like this :

                 

                private var i:int;
                
                private function lookForDisplayObjectsToRemove():void {
                     for ( j:int = i ; i < whatEverYouIterateOn.lenght ; j++ ) {
                          if ( /* condition to remove object here */ ) {
                               i = j;
                               var popUp:YourYesOrNoPopUp; // pop your yes or no alert here
                               popUp.displayObjectToRemove = whateverYouIterateOn[j];
                               popUp.functionOnYesClick = removeDisplayObject;
                               popUp.functionOnNoClick = lookForDisplayObjectsToRemove;
                               return;
                          }
                     }
                }
                
                
                private function removeDisplayObject( object:DisplayObject ):void {
                     // remove object here
                     lookForDisplayObjectsToRemove();
                }
                
                
                • 5. Re: Modal Alert waiting to user click
                  pyso Level 1

                  yes M*A*S*H 4077,

                  that's sounds like solution but I am affraid if you use something like while(allowExecution) as you suggested, your CPU will not like it much and get crazy. But I didn't try it.

                   

                  //pyso

                  • 6. Re: Modal Alert waiting to user click
                    pyso Level 1

                    Hmm, nice and elegant solution NoNick4Me.

                    Thanks,

                    //pyso

                    • 7. Re: Modal Alert waiting to user click
                      Francisc Level 3

                      As far as I know that is how event listeners work, while loops (for example).

                       

                      That said, adding and event listener on the allowExecution var is another option.

                       

                      What is best if possible in your case is when you open the alert call some functions that stop background activity or whatever it is that you want to prevent from happening and restart them in the closeHandler.