Skip to main content
Participating Frequently
December 28, 2011
Question

how to assign the htmltext in radiobutton label using as3

  • December 28, 2011
  • 1 reply
  • 1689 views

how to assign the htmltext in radiobutton label using as3

This topic has been closed for replies.

1 reply

Kenneth Kawamoto
Community Expert
Community Expert
December 29, 2011

You can override the component classes to force the label takes HTML, but the easiest way would be to use your own TextField as label.

--

Kenneth Kawamoto

http://www.materiaprima.co.uk/

Participating Frequently
December 31, 2011

hi,

i try to override method

package
{
import fl.controls.RadioButton;

public class MyRadioButton extends RadioButton
{
  public function MyRadioButton()
  {
   super();
   
  }

  override public function set label(value:String):void {
        _label = value;
        //textField.htmlText = _label;                               // But Dynamic value not work fine
       

         textField.htmlText ="<b>InfoWave</b>";      // Static value work fine
    }

}
}

Kenneth Kawamoto
Community Expert
Community Expert
December 31, 2011

You're on the right track but it requires more work to override label function - see LabelButton class draw() for example.

I personally can't be bothered to override so many functions My approach is therefore ignore built-in label and create my own. e.g.

package {

    import fl.controls.RadioButton;

    import flash.text.TextField;

    public class MyRadioButton extends RadioButton {

        private var _tf:TextField;

        public function MyRadioButton(){

            super();

        }

        public function set myLabel(value:String):void {

            label = "";

            if(_tf == null){

                _tf = new TextField();

                with(_tf){

                    x = 25;

                    y = 4;

                    autoSize = "left";

                }

                addChild(_tf);

            }

            _tf.htmlText = value;

        }

    }

}

Then to set the label do:

myRadioButton.myLabel = "<font color='#cc0000'>InfoWave</font>";

This way you can do whatever you like with the label.

--

Kenneth Kawamoto

http://www.materiaprima.co.uk/