Christian Mueller

Flex Checkbox Wordwrap

[code lang="as3"]
/**
* @author Christian Mueller
* @date 9/22/2009
* @describtion checkbox with textfield wordwrap true
*/
package components {

import flash.display.DisplayObject;
import flash.text.TextFieldAutoSize;
import mx.controls.CheckBox;
import mx.core.IUITextField;
import mx.core.UITextField;

public class MultilineCheckbox extends CheckBox {

private var multilineLabel : IUITextField;

public function MultilineCheckbox() {
super();
text = "";
}

private var _text : String;

public function set text( value:String ):void {
_text = value;
commitProperties();
}

public function get text():String {
return _text;
}

override protected function createChildren():void {
super.createChildren();

if ( multilineLabel == null ) {
multilineLabel = IUITextField( createInFontContext( UITextField ) );
multilineLabel.text = "";
multilineLabel.wordWrap = true;
multilineLabel.autoSize = TextFieldAutoSize.LEFT;
addChild( DisplayObject( multilineLabel ) );
}
}

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

if ( multilineLabel != null && textField != null ) {
multilineLabel.x = textField.x;
}
}

override protected function commitProperties():void {
super.commitProperties();

if ( multilineLabel != null ) {
multilineLabel.text = _text;
}
}

override protected function measure():void {
super.measure();
}
}
}
[/code]

Beispiel:
Get Adobe Flash player

2 Comments

  1. chris says:

    Hi Raj, you can use it like this:
    checkbox:MultilineCheckbox id="chk" label="Lorem ipsum..."
    It depends on the package you put this class in. The wordwrap will be done the class itself.

  2. Raj says:

    Could you please send me the mxml sample with the multiline checkbox?

Leave a Reply