ci-joint un bouton surgissant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
117
118
119
120
121
122
123
124
125
126
127
 
program Button;
 
uses
 Flash8;
 
{$FRAME_WIDTH   500}
{$FRAME_HEIGHT  400}
{$BACKGROUND $ffffff}
 
 
Type  
 TButton = class(MovieClip)
  Bascule:Boolean;
  tx,ty:number;
  Caption: TextField;
  format1,format2: TextFormat;
  constructor Create(x,y,square:number); //position coin en haut à gauche ; square:coté du bouton carré
  procedure DrawButton(BackColor1,BackColor2:integer ;square:number);
  procedure Roundrect(x,y,w,h,radius:number);
  procedure DoKeyDown;
  procedure DoClick;
  procedure DoRoLlOver;
  procedure DoRoLlOut;
 end;
 
procedure TButton.Roundrect(x,y,w,h,radius:number);
var
 r,b:number;
begin
  r := x + w;
  b := y + h;
  moveTo(x+radius, y);
  lineTo(r-radius, y);
  CurveTo(r, y, r, y+radius);
  lineTo(r, y+h-radius);
  CurveTo(r, b, r-radius, b);
  lineTo(x+radius, b);
  CurveTo(x, b, x, b-radius);
  lineTo(x, y+radius);
  CurveTo(x, y, x+radius, y);
end;
 
 Constructor TButton.Create(x,y,square:number);
 begin
  inherited Create(nil,'button',1);
  _x:=x+square/2;
  _y:=y+square/2;
  tx:=_x;
  ty:=_y;
  Format1 := TextFormat.Create('Arial',18*square/50,$FFFBF0,true,false,false,'','','center');//size de la police en relatif police de 18 pour un bouton de 50 pixels de côté
  Format2:=TextFormat.Create();
  Format2.Underline := True;
  Caption := TextField.Create(Self, '',1,-square/2,-square/2,square,square/2);//je donne des dimensions arbitraires puisque le autosize arrive après...
  //(je suis obligé de remplir le create de caption sinon ça plante) il vaudrait mieux limiter les paramètres dans le create de flash8 et pouvoir compléter à sa guise les propriétés après...
  Caption.setNewTextFormat(Format1);
  Caption.text:='Stop';
  Caption.setTextFormat(0,1,Format2);
  caption.autosize:='center';
  //pour recentrer le titre du bouton
  caption._y:=floor(-square/2+(square-caption.textheight)/2-2); //-2 pour recentrer ? le textheight ne donne pas un résultat top !
  //à voir avec le chef s'il a la solution...
  DrawButton($183EFF,$0A1B6F,square);
  Key.addListener(self);
  Bascule:=False;
  onpress:=DoClick;
  onKeyDown:=DoKeyDown;
  onRollOver:=DoRollOver;
  onRollOut:=DoRollOut;
 end;
 
 Procedure TButton.DrawButton(BackColor1,BackColor2:integer ;square:number);
 var mx:Matrix;
 begin
  lineStyle(3,$000000);
  mx:=matrix.create();
  mx.createbox(1,1,0,0,0);
  begingradientfill('radial',[backColor1,backcolor2],[100,100],[floor(3*square/50),floor(10*square/50)],mx);
  RoundRect(-square/2,-square/2,square,square,square/10);
  endFill;
 end; 
 
Procedure TButton.doClick;
 begin
  Bascule:=not Bascule;
  if Bascule then
  begin
   Caption.setNewTextFormat(Format1);
   Caption.text:='Play';
   Caption.setTextFormat(0,1,Format2);
   // commande à mettre ici
  end
  else
  begin
   Caption.setNewTextFormat(Format1);
   Caption.text:='Stop';
   Caption.setTextFormat(0,1,Format2);
   // commande à mettre ici
  end;
 end;
 
Procedure TButton.doKeyDown;
var k:number;
begin
 k:= Key.getAscii;
 if (((k=112) or  (k=080)) and  bascule) or (((k=115) or (k=083)) and not bascule)  then doClick;
end;
 
procedure TButton.DoRoLlOver;//intéressant...
var mx,my:number;
begin
   _xscale:=170;//170%
   _yscale:=170;
   _x :=tx;
   _y :=ty;
end;
 
Procedure TButton.DoRoLlOut;// intéressant...
 begin
   _xscale:=100;//échelle normale
   _yscale:=100;
 end;
 
 
begin
 TButton.Create(200,150,100);
end.
@+

l'idée vient de là :http://www.wks.fr/Creer-un-bouton-gr...ant-a-son.html

J'ai essayé d'implanter un bouton avec button de flash8...sans succès