3 Replies Latest reply on Oct 26, 2010 12:00 PM by Uasav

    The navigateToURL influences the Alert PopUp behavior

    Uasav
      Hello all!

        Working on my project in Flex 4 Prem I've met the strange
      model of behavior when I call navigateToURL method after creating
      Alert popup window: being run the program does not wait user's mouse
      click on OK button on Alert popup. Instead it displays the popup for
      a sec and go to the next statement in source code: navigateToURL()
      function's call.
        If I comment this navigateToURL() call, the program's behave returns
      to normal as it is suppose to be: it waits until user clicks on the OK
      button on the Alert popup window. The simple model of the source code
      you can se below.
      Please, help me to understand what I've done wrong.
      Thanks a lot in advance!

      Andrey Suntsev

      The code:

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">

          <s:layout>
             <s:BasicLayout/>
          </s:layout>
        
          <fx:Script>
              <![CDATA[
             
              import mx.controls.Alert;
              import mx.core.FlexGlobals;
             
              private function show_Messages(_event:MouseEvent):void
              {
                  Alert.show("Click OK");
                  navigateToURL(new URLRequest(FlexGlobals.topLevelApplication.url), '_self');
              }
             
              ]]>
          </fx:Script>
          
          <s:Button id="submitButton"
                    label="Show message"
                    click="show_Messages(event);" />
         
      </s:Application>
        • 1. Re: The navigateToURL influences the Alert PopUp behavior
          joan_lafferty Adobe Employee

          This is actually expected behavior. It happens with any code after the Alert.show, not just navigateToURL. If you don't want that code to execute, you should move it to the click handler of the ok button for your Alert. Its impossible for us to block this behavior in Flash.

           

          Thanks,

          Joan

          • 2. Re: The navigateToURL influences the Alert PopUp behavior
            Peter deHaan Level 4

            @Uasav,

             

            Something like this should work:

             

            <?xml version="1.0" encoding="utf-8"?>
            <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark">
            
                <fx:Script>
                    <![CDATA[
                        import mx.controls.Alert;
                        import mx.core.FlexGlobals;
                        import mx.events.CloseEvent;
            
                        protected function show_Messages(evt:MouseEvent):void  {
                            Alert.show("Click OK", "", Alert.OK|Alert.CANCEL, null, alert_closeHandler);
                        }
            
                        protected function alert_closeHandler(evt:CloseEvent):void {
                            switch (evt.detail) {
                                case Alert.OK:
                                    navigateToURL(new URLRequest(FlexGlobals.topLevelApplication.url), '_self');
                                    break;
                                case Alert.CANCEL:
                                    // ignore
                                    break;
                            }
                        }
                    ]]>
                </fx:Script>
            
                <s:Button id="submitButton"
                          label="Show message"
                          click="show_Messages(event);" />
            
            </s:Application>
            

             

             

            Peter

            • 3. Re: The navigateToURL influences the Alert PopUp behavior
              Uasav Level 1

              Hello Peter,

               

                The help from you (case #181859456) was extremely helpful.

              So, I think the case is closed.

              Thanks a lot!!!

               

              Andrey Suntsev