package {
import flash.display.*;
import flash.events.*;
import flash.text.*;
public class CheckBox extends Sprite {
private var label:TextField; // The checkbox's text label
private var icon:CheckBoxIcon; // The checkbox's graphical icon
private var checked:Boolean; // Flag indicating whether the
// checkbox is currently checked
public function CheckBox (msg:String) {
checked = false;
icon = new CheckBoxIcon( );
label = new TextField( );
label.text = msg;
label.autoSize = TextFieldAutoSize.LEFT;
label.selectable = false;
label.x = icon.x + icon.width + 5;
addChild(icon);
addChild(label);
addEventListener(MouseEvent.CLICK, clickListener);
}
private function clickListener (e:MouseEvent):void {
if (checked) {
icon.uncheck( );
checked = false;
} else {
icon.check( );
checked = true;
}
}
}
}
class CheckBoxIcon extends flash.display.Sprite {
public function CheckBoxIcon ( ) {
uncheck( );
}
public function check ( ):void {
graphics.clear( );
graphics.lineStyle(1);
graphics.beginFill(0xFFFFFF);
graphics.drawRect(0, 0, 15, 15);
graphics.endFill( );
graphics.lineTo(15, 15);
graphics.moveTo(0, 15);
graphics.lineTo(15, 0);
}
public function uncheck ( ):void {
graphics.clear( );
graphics.lineStyle(1);
graphics.beginFill(0xFFFFFF);
graphics.drawRect(0, 0, 15, 15);
}
}
}
|