6 Replies Latest reply on Mar 8, 2008 4:30 PM by jfizer

    Extending button and popupbutton class to use HTMLText?

    jfizer
      Second attempt at seeing if I can get some help with this. Trying to extend the button and/or popupbutton class to use HTMLText for the label. Been trying various things to no effect and am wondering if anyone has any ideas or can point me in the right direction.
        • 1. Re: Extending button and popupbutton class to use HTMLText?
          SujitG Level 2
          Button is using TextField for displaying the label and the TextField component supports htmlText property. As you are extending the Button class; modify the code to set the HTML text to the htmlText of the TextField class inside the Button.

          Hope this helps.
          • 2. Re: Extending button and popupbutton class to use HTMLText?
            jfizer Level 1
            quote:

            Originally posted by: SujitG
            Button is using TextField for displaying the label and the TextField component supports htmlText property. As you are extending the Button class; modify the code to set the HTML text to the htmlText of the TextField class inside the Button.

            Hope this helps.


            That looks promissing, however I get the error
            Error #1009: Cannot access a property or method of a null object reference. when I try to set the HTMLText in the following manor.

            package custom
            {
            import mx.controls.PopUpButton;

            public class CustomButton extends PopUpButton
            {

            public function CustomButton()
            {
            super();
            super.textField.htmlText = "<i>test</i>";
            }
            }
            }
            • 3. Re: Extending button and popupbutton class to use HTMLText?
              jfizer Level 1
              I've tried taking it a step farther with the following code, but it results in the same error when I try to set the htmlText property.

              package custom
              {
              import mx.controls.PopUpButton;
              import mx.core.UITextField;

              public class CustomButton extends PopUpButton
              {
              public function CustomButton()
              {
              super();
              //super.textField.htmlText = "<i>test</i>";
              }
              override public function set label(value:String):void
              {
              super.label = value;
              setHtmlLabel();
              }
              private function setHtmlLabel():void
              {
              var tf:UITextField = super.textField as UITextField;
              tf.htmlText = "<i>test</i>";
              }
              }
              }
              • 4. Re: Extending button and popupbutton class to use HTMLText?
                jfizer Level 1
                Its convoluted, but I got something that works. I had to add the HTMLText to a bitmap object and then apply it to the button. This is based off of a rotation button class so it includes the ability to set the button at any angle.

                NOTE: Am I the only one not seeing the attach code button on the forums?

                package custom
                {
                import mx.controls.Button;
                import mx.controls.PopUpButton;
                import flash.text.TextField;
                import flash.text.TextFieldAutoSize;
                import flash.text.AntiAliasType;
                import flash.text.TextFormat;
                import flash.display.BitmapData;
                import flash.display.Bitmap;
                import mx.core.UITextField;
                import mx.core.IUITextField;
                import mx.events.FlexEvent;
                import flash.events.MouseEvent;

                public class CustomButton extends Button
                {
                public function CustomButton()
                {
                super();
                this.addEventListener( FlexEvent.CREATION_COMPLETE, onInit );
                }
                override public function set label(value:String):void
                {
                super.label = value;
                setHtmlLabel();
                }
                private function onInit( event:FlexEvent ):void
                {
                this.label = super.label;
                }
                private function setHtmlLabel():void
                {
                var tf:IUITextField = super.textField;
                if( null == tf ) return;

                tf.htmlText = "<i>Testing</i>";

                var bmp:Bitmap;
                bmp = Bitmap( this.getChildByName( "bitmapLabel" ) );
                if( null != bmp)
                {
                bmp.bitmapData.dispose();
                this.removeChild( bmp );
                }
                var bmpData:BitmapData = new BitmapData( tf.width, tf.height, true, 0x00CCCCCC );
                bmpData.draw( tf );

                bmp = new Bitmap( bmpData, "auto", false );
                bmp.smoothing = true;
                bmp.name = "bitmapLabel";
                bmp.x = this.width/2 - tf.width/2;
                bmp.y = this.height/2 - tf.height/2;
                this.addChild( bmp );
                }
                }
                }
                • 5. Re: Extending button and popupbutton class to use HTMLText?
                  jfizer Level 1
                  Well, it works till you mouse over the button.... but its getting closer.
                  • 6. Extending button and popupbutton class to use HTMLText?
                    jfizer Level 1
                    It may be my implementation, but the method of using a bitmap doesn't seem to be working very well. Anyone have any other ideas?

                    This strikes me as something that should be far simpler then what I'm ending up with...