1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
unit UCheckbox;
interface
uses Flash8;
Const c=10;//côté du tick
ox=5;// pour centrer par rapport au texte
oy=3;//idem
type
TTick=class(movieclip)
checked:Boolean;
procedure onPress;
procedure onEnterFrame;
constructor Create(AOWNER:movieclip);
end;
TCheckBox=Class(movieclip)
checked:Boolean;
Font:TextFormat;
Caption:TextField;
Tick:TTick;
constructor Create(AOWNER:movieclip);
end;
implementation
constructor TTick.create(AOWNER:movieclip);
begin
inherited create(AOWNER,'Tick',0); //pour la zone onPress
beginFill(clwhite); //opaquebackground ne définit pas la zone
moveto(ox-c/2,oy-c/2);
lineto(ox-c/2,oy+c/2);
lineto(ox+c/2,oy+c/2);
lineto(ox+c/2,oy-c/2);
lineto(ox-c/2,oy-c/2);
EndFill();
linestyle(1,$A1A1A1);
moveto(c/2+ox,-c/2+oy);
lineto(-c/2+ox,-c/2+oy);
lineto(-c/2+ox,c/2+oy);
linestyle(1,clwhite);
moveto(-c/2+ox,c/2+oy);
lineto(c/2+ox,c/2+oy);
lineto(c/2+ox,-c/2+oy);
linestyle(1,$696969);
moveto(9*c/20+ox,-2*c/5+oy);
lineto(-2*c/5+ox,-2*c/5+oy);
lineto(-2*c/5+ox,9*c/20+oy);
linestyle(1,$E3E3E3);
moveto(-2*c/5+ox,9*c/20+oy);
lineto(-2*c/5+ox,9*c/20+oy);
lineto(-2*c/5+ox,9*c/20+oy);
checked:=false;
end;
constructor TCheckBox.Create(AOWNER:movieclip);
begin
inherited Create(AOWNER,'CheckBox',AOWNER.getNextHighestDepth);
Tick:=TTick.Create(self);
Tick._x:=0;
Tick._y:=0;
Font := TextFormat.Create('Arial',14,ClBlack,false,false,false,'','','left');
Caption:=TextField.Create(Self, '',1,15,-6,100,20);
Caption.SetNewTextFormat(Font);
Caption.text:='CheckBox';
Checked:=false;
end;
procedure TTick.onPress;
begin
TCheckBox(_parent).Checked:=true;
end;
Procedure TTick.onEnterFrame;
begin
if checked = TCheckBox(_parent).checked then exit;
checked := not checked;
if checked then
begin
linestyle(2,clblack);
BeginFill(clBlack);
moveto(ox-c/5,oy-c/5);
lineto(ox+c/5,oy+c/5);
moveto(ox-c/5,oy+c/5);
lineto(ox+c/5,oy-c/5);
end else
begin
BeginFill(clWhite);
linestyle(2,clwhite);
moveto(ox-c/5,oy-c/5);
lineto(ox+c/5,oy+c/5);
moveto(ox-c/5,oy+c/5);
lineto(ox+c/5,oy-c/5);
end;
end;
end. |
Partager