ImageCheckbox Component
Today I had need of a checkbox that implemented an image instead of a standard textual label. For this particular case I needed to use embeded images, so this first version accepts a type of Class for the iconLabel. I simply extended Checkbox and added an image component to the view, careful to update the properties and dimensions.
Feel free to use this code in your apps. Simply provide the labelIcon and image and you should be good to go!
package
{
import mx.controls.CheckBox;
import mx.controls.Image;
public class ImageCheckbox extends CheckBox
{
private var image:Image;
private var _labelIcon:Class;
public function ImageCheckbox()
{
super();
}
override protected function createChildren():void
{
super.createChildren();
image = new Image();
this.addChild(image);
}
override protected function commitProperties():void
{
super.commitProperties();
image.source = labelIcon;
}
override protected function measure():void
{
super.measure();
image.height = image.content.height;
image.width = image.content.width;
this.height = image.height;
image.x = 16;
this.width = image.width + 16;
}
override public function set label(value:String):void
{
}
public function set labelIcon(licon:Class):void
{
_labelIcon = licon;
this.invalidateProperties();
}
public function get labelIcon():Class
{
return _labelIcon;
}
}
}
0 comments - Posted by TJ Downes at 10:43 PM - Categories:
