10 Replies Latest reply on Jul 31, 2009 3:48 PM by Zolotoj

    Alert class

    Zolotoj Level 3

      Is there anything available in that class that I could use to carry over without showing it to the user? Something like an error number.

      Should I simply subclass it and add a property?

       

      Thanks

        • 1. Re: Alert class
          Gregory Lafrance Level 6

          What do you mean by carry over without showing the user?

           

          Will be alert display to the user?

          • 2. Re: Alert class
            Zolotoj Level 3

            I meant, a property that can be used to carry some hidden to a user information, a message number for instance. But I guess I need to subclass it and add a custom property to it.

            • 3. Re: Alert class
              Gregory Lafrance Level 6

              I would just use a TitleWindow as a popup.

               

              http://livedocs.adobe.com/flex/3/html/help.html?content=layouts_12.html

               

              If you do this, remember to use PopUpManager.centerPopUp(this) to center the popup, and PopUpManager.removePopUp(this) to remove it.

               

              In that case "this" means the popup. If you create the popup somewhere else and display it, "this" in those method calls would be the instance of the popup, but you usually call those methods within the popup instance.

               

              If this post answers your question or helps, please mark it as such.

              1 person found this helpful
              • 4. Re: Alert class
                Zolotoj Level 3

                Ok, I am trying to create a custom Alert class:

                package modulecode
                {
                     import mx.controls.Alert;
                     
                     public class customAlert extends Alert
                     {
                          public var messageNumber:int = 0;
                          public function customAlert()
                          {
                               super();
                          }
                     }
                }
                

                Somewhere in app:

                var ca:customAlert = new customAlert();
                ca = Alert.show(message, "Warning!", Alert.OK|Alert.CANCEL, parent, Object(parent)[callbackFunction], null);
                ca.messageNumber = messageNumber;        
                PopUpManager.centerPopUp(ca);
                

                does not work.

                Implicit coercion of a value with static type mx.controls:Alert to a possibly unrelated type modulecode:customAlert.

                Is it possible to make it work?

                • 5. Re: Alert class
                  Gregory Lafrance Level 6

                  Maybe:

                   

                  ca = customAlert.show(message, Warning!, Alert.OK|Alert.CANCEL, parent, Object(parent)[callbackFunction], null);

                   

                  or you may need to have a show() method in your class with the same args and pass those args to the Alert.show method.

                   

                   

                  • 6. Re: Alert class
                    Zolotoj Level 3

                    a = customAlert.show   ...

                    1. does not work. compiler says customAlert does not have show method. Strange.

                    2. customAlert with a public showAlert to mimic show:

                    public function showAlert(text:String = "", title:String = "", flags:uint = 0x4, parent:Sprite = null, 
                         closeHandler:Function = null, iconClass:Class = null, defaultButtonFlag:uint = 0x4):Alert
                    {
                    messageNumber = messageNumber;
                    return Alert.show(text, title, flags, parent, closeHandler, iconClass, defaultButtonFlag);
                    }
                    

                    but that essentially is the same as to work with native Alert. I am trying to add a custom property messageNumber

                    to the extended Alert. Because later on I want this to work:

                     public function alertClickHandler(event:CloseEvent):void 
                     {
                         event.target. messageNumber
                     }
                    

                    • 7. Re: Alert class
                      Gregory Lafrance Level 6

                      You could have a showAlert method in your class that includes an additional arg for the message number, then in that method call the super.show() method.

                       

                      If this post answered your question or helped, please mark it as such.

                      • 8. Re: Alert class
                        Ansury Level 3

                        A TitleWindow dialog really isn't so hard to use, I always use those unless I only want to do what Alert was intended for (which is configurable in the interface).

                         

                        I don't think Adobe meant for that class to be extended.  You can't even create an mxml component from Alert.  Just the fact that Alert.show is static makes it a bit of an oddball component, just a quick convenience and nothing more.  It's also interesting that they didn't extend TitleWindow to build it.

                         

                        Even if you do extend Alert, you can't call super.show() because it's static in Alert and you'd have to call Alert.show(), which is pretty much pointless.

                         

                        Don't waste your time, I think you might as well just use a TitleWindow, it's not worth tinkering with a convenience class when you could create something similar in a few minutes with the functionality you need.

                        • 9. Re: Alert class
                          Zolotoj Level 3

                          No, I tried something like this, it does not work.

                          • 10. Re: Alert class
                            Zolotoj Level 3

                            Yeah, you are right.