4 Replies Latest reply on Oct 24, 2011 11:51 AM by Zolotoj

    Alert Box question

    Zolotoj Level 3

      Is it possible to add a button to an Alert box's title bar or at least make it respond to a click?

       

      Thanks

        • 1. Re: Alert Box question
          highlightscript Level 1

          Yes you can. Alert comes from Panel (mx.controls.Panel). So check the properties and methods for Panel

          • 2. Re: Alert Box question
            Zolotoj Level 3

            Is there a chance you could show some code, please?

            • 3. Re: Alert Box question
              Zolotoj Level 3

              Here is some fragments of code I got so far:

              package

              {

                  import flash.events.MouseEvent;

                  import flash.utils.describeType;

               

                  import mx.containers.VBox;

                  import mx.controls.Alert;

                  import mx.controls.Button;

                  import mx.core.LayoutContainer;

                  import mx.utils.*;

               

                  import spark.skins.spark.TitleWindowCloseButtonSkin;

               

                  public class AlertEx extends Alert

                  {

                      private var _titleBtn:Button=new Button();

                      private var _titleSparkBtn:TitleWindowCloseButtonSkin=new TitleWindowCloseButtonSkin();

                      public function AlertEx()

                      {

                          super();

                          this.addEventListener("click", onClick);

                          this.text = "Test";

                          this.title = "Error";           

                      }

                      override protected function createChildren():void

                      {

                          super.createChildren();

                          _titleSparkBtn.addEventListener("click", onClick);

                          titleBar.addChild(_titleSparkBtn);

                      }       

                      private function onClick(event:MouseEvent):void

                      {

                          trace(event.target);

                      }

                      override protected function updateDisplayList (unscaledWidth:Number, unscaledHeight:Number):void{

               

                          super.updateDisplayList(unscaledWidth, unscaledHeight);

                          _titleBtn.move(100, 2);

               

               

                      }

                  }

              }

              The result basically looks like this:

              alert.png

              While I do have a close button here but I can't find a way of positioning it to the right corner. Any idea?

               

              Thanks

              • 4. Re: Alert Box question
                Zolotoj Level 3

                I got it, nevermind.