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 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
unit UButton;
interface
uses Flash8;
Type
TButton=class(movieclip)
private
click:Boolean;
skin1,skin2:movieclip;
w,h:number;
FText : TextField;
font:TextFormat;
procedure skin;
procedure SetCaption(value:string);
procedure onPress;override;
procedure onMouseUp;override;
public
procedure onClick;virtual;
constructor create(parent:movieclip;left,top,width:number);
property Caption:string read FText write SetCaption;
end;
implementation
constructor TButton.Create(parent:movieclip;left,top,width:number);
begin
inherited Create(parent,'button',movieclip(parent).getNextHighestDepth());
w:=width;
h:=w/3;
skin1:=movieclip.create(self,'',1);
skin2:=movieclip.create(self,'',2);
with skin1 do
begin
linestyle(1,$646464);
BeginFill($F0F0F0);
moveto(0,h);
lineto(0,0);
lineto(w,0);
linestyle(3,$646464);
lineto(w,h);
lineto(0,h);
end;
with skin2 do
begin
linestyle(2,$808080);
BeginFill($F0F0F0);
moveto(0,h);
lineto(0,0);
lineto(w,0);
lineto(w,h);
lineto(0,h);
end;
font := TextFormat.Create('arial', 14);
with font do
begin
color := clBlack;
align:='center';
end;
click:=false;
skin;
FText:=TextField.Create(self,'caption',3,0,0,w,h/2);
FText.setNewTextFormat(font);
_x:=left;
_y:=Top;
end;
procedure TButton.skin;
begin
if not click then
begin
skin1._visible:=true;
skin2._visible:=false;
end else
begin
skin1._visible:=false;
skin2._visible:=true;
end;
end;
procedure TButton.SetCaption(Value: string);
begin
with FText do
begin
Text := Value;
autosize:='center';
_y:=(h-_Height)/2;
_x:=(w-_width)/2;
end;
end;
procedure TButton.onClick;
begin
end;
procedure TButton.onPress;
begin
click:=true;
skin;
onClick;
end;
procedure TButton.onMouseUp;
begin
click:=false;
skin;
end;
end. |
Partager