Précédent   Forum du club des développeurs et IT Pro > Autres langages > Pascal > Flash Pascal
Flash Pascal Forum d'entraide sur la création de fichiers Flash en Object Pascal
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 30/06/2012, 12h34   #1
Archimède
Membre émérite
 
Avatar de Archimède
 
Homme anthony
Enseignant
Inscription : avril 2005
Messages : 1 027
Détails du profil
Informations personnelles :
Nom : Homme anthony
Localisation : France, Charente Maritime (Poitou Charente)

Informations professionnelles :
Activité : Enseignant
Secteur : Enseignement

Informations forums :
Inscription : avril 2005
Messages : 1 027
Points : 977
Points : 977
Par défaut Souci avec un radiobutton maison

Ci-joint :

Code :
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
 
unit URadiobutton;
 
interface
 
uses Flash8;
 
type
  TTick=class(movieclip)
   procedure circle(Cx,Cy,Radius:number);
   procedure arcto(x,y,tetai,tetaf,rayon:number);
   procedure onPress;
   procedure onEnterFrame;
   constructor Create(AOWNER:movieclip);
  end;
 
 TRadioButton=Class(movieclip)
  checked:Boolean;
  Font:TextFormat;
  Caption:TextField;
  Tick:TTick;
  constructor Create(AOWNER:movieclip;Fwidth,Fheight:number);
 end;
 
 
implementation
 
constructor TTick.create(AOWNER:movieclip);
begin
 inherited create(AOWNER,'Tick',0);
 BeginFill(clwhite);
 circle(5,5,5);
 EndFill();
 linestyle(3,$E3E3E3);
 circle(5,5,4.5);
 linestyle(1,clblack);
 arcto(5,5,50,220,5);
end;
 
constructor TRadioButton.Create(AOWNER:movieclip;Fwidth,Fheight:number);
begin
 inherited Create(AOWNER,'Radiobutton',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:='RadioButton';
 Checked:=false;
end;
 
procedure TTick.onPress;
begin
  TRadioButton(_parent).Checked:=true;
end;
 
Procedure TTick.circle(Cx,Cy,Radius:number);
var a,b,R: number;
begin
  R:=Radius;
  a:= R * 0.414213562;
  b:= R * 0.707106781;
  moveTo(Cx+R,Cy);
  CurveTo(Cx+ R, Cy+-a, Cx+b,Cy -b);
  CurveTo(Cx+ a,Cy-R,Cx,Cy -r);
  CurveTo(Cx-a,Cy -R,Cx-b,Cy -b);
  CurveTo(Cx-R, Cy-a,Cx-R,Cy);
  CurveTo(Cx-R,Cy+a,Cx-b,Cy+b);
  CurveTo(Cx-a,Cy +R,Cx,Cy+r);
  CurveTo(Cx+a,Cy +R,Cx+b,Cy+b);
  CurveTo(Cx+R,Cy+a,Cx+R,Cy);
end;
 
Procedure TTick.onEnterFrame;
begin
 if TRadioButton(_parent).checked then
 begin
  linestyle(1,clblack);
  BeginFill(clBlack);
  circle(5,5,1.5);
 end else
 begin
  BeginFill(clWhite);
  linestyle(1,clwhite);
  circle(5,5,1.5);
 end;
end;
 
procedure TTick.arcto(x,y,tetai,tetaf,rayon:number);
var  lineangle,contdist,Endx,Endy,contx,conty:number;
     i:integer;
begin
  tetai:=tetai*math.pi/180;
  tetaf  :=tetaf*math.pi/ 180;
  lineangle:=(tetaf-tetai)/8;
  contdist:=rayon/cos(lineangle/2);
  moveto(x+rayon*cos(tetai),y-rayon*sin(tetai));
  for i:= 1 to 8 do
  begin
   endx:=x+rayon*cos(tetai+i*lineangle);
   endy:=y-rayon*sin(tetai+i*lineangle);
   contx:=x+contdist*cos(tetai+i*lineangle-lineangle/2);
   conty:=y-contdist*sin(tetai+i*lineangle-lineangle/2);
   curveto( contx,conty,endx,endy);
  end;
end;
 
end.
program :

Code :
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
 
program Project3;
 
{$FRAME_WIDTH 550}
{$FRAME_HEIGHT 400}
{$FRAME_RATE 32}
{$BACKGROUND $f0f0f0}
 
uses
  Flash8,URadiobutton;
type
 
   Essai=class(movieClip)
     radio,radio2:TRadioButton;
     Field:TextField;
     MyFont:Textformat;
     Procedure onEnterFrame;
     Constructor Create;
   end;
 
Constructor Essai.Create;
begin
 inherited create(nil,'essai',0);
 radio:=TRadioButton.create(self,100,20);
 with radio do
 begin
  _x:=100;
  _y:=100;
  caption.text:='Affichage n°1';
 end;
 
 radio2:=TRadioButton.create(self,100,20);
 with radio2 do
 begin
  _x:=100;
  _y:=120;
  caption.text:='Affichage n°2';
 end;
 
  MyFont:= TextFormat.Create('Arial', 25, $000000,true,false,false);
  Field :=TextField.Create(self, '',2, 10,150,450,40);
  Field.setNewTextFormat(MyFont);
end;
 
Procedure Essai.onEnterFrame;
begin
 if radio.checked then
 begin
   radio2.checked:=false;
   Field.text:="j'ai pressé sur le premier radiobutton";
 end else 
 if radio2.checked then
 begin
   radio.checked:=false;
   Field.text:="j'ai pressé sur le second radiobutton";
 end;
end;
 
begin
 essai.create;
end.
ça vient peut-être de TRadioButton(_parent) ?
__________________
Citation:
tout développeur plongé dans son code subit une poussée d'urticaire de bas en haut égale au poids du volume d'unités qu'il ajoute.
Archimède est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/06/2012, 20h33   #2
Paul TOTH
Expert Confirmé Sénior
 
Avatar de Paul TOTH
 
Homme Paul TOTH
Freelance
Inscription : novembre 2002
Messages : 4 405
Détails du profil
Informations personnelles :
Nom : Homme Paul TOTH
Âge : 43
Localisation : Réunion

Informations professionnelles :
Activité : Freelance
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : novembre 2002
Messages : 4 405
Points : 10 756
Points : 10 756
Hello,

au lieu de redessiner le Tick à chaque frame tu peux ajouter un checked local au tick
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
Procedure TTick.onEnterFrame;
begin
// pas de changement
 if checked = TRadioButton(_parent).checked then
   exit;
// l'état à changé
 checked := not checked;
 if checked then
 begin
  linestyle(1,clblack);
  BeginFill(clBlack);
  circle(5,5,1.5);
 end else
 begin
  BeginFill(clWhite);
  linestyle(1,clwhite);
  circle(5,5,1.5);
 end;
end;
ensuite le problème vient de ce que essai.onEnterFrame teste en premier si le premier bouton est checked...ce qui est toujours le cas une fois qu'on a cliqué dessus, du coup radio2 ne le reste pas

il faudrait là encore garder un état dans essai pour savoir si l'état a changé ou pas.
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
Procedure Essai.onEnterFrame;
begin
 if radio.checked and (current <> 1) then
 begin
   current := 1;
   radio2.checked:=false;
   Field.text:="j'ai pressé sur le premier radiobutton";
 end else
 if radio2.checked and (current <> 2) then
 begin
   current := 2;
   radio.checked:=false;
   Field.text:="j'ai pressé sur le second radiobutton";
 end;
end;
__________________
Developpez.com: Mes articles, forum FlashPascal
Entreprise: Execute SARL
Produits : UPnP, RemoteOffice, FlashPascal
Embarcadero : Ile de la Réunion, Dephi, C++Builder, RADPHP...TVA à 8,5%
Paul TOTH est déconnecté   Envoyer un message privé Réponse avec citation 20
Vieux 01/07/2012, 10h56   #3
Archimède
Membre émérite
 
Avatar de Archimède
 
Homme anthony
Enseignant
Inscription : avril 2005
Messages : 1 027
Détails du profil
Informations personnelles :
Nom : Homme anthony
Localisation : France, Charente Maritime (Poitou Charente)

Informations professionnelles :
Activité : Enseignant
Secteur : Enseignement

Informations forums :
Inscription : avril 2005
Messages : 1 027
Points : 977
Points : 977
Bien vu
merci, je pensais que ce serait très simple à réaliser mais la stringgrid qui parait plus conséquente présentera moins de contraintes...
un tableau à deux dimensions de TextField..., en plus on a la bordure des textfields pour faire la grille.

ci-joint ta rectif avec le code complet :

Code :
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 URadiobutton;
 
interface
 
uses Flash8;
 
type
  TTick=class(movieclip)
   checked:Boolean;
   procedure circle(Cx,Cy,Radius:number);
   procedure arcto(x,y,tetai,tetaf,rayon:number);
   procedure onPress;
   procedure onEnterFrame;
   constructor Create(AOWNER:movieclip);
  end;
 
 TRadioButton=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);
 BeginFill(clwhite);
 circle(5,5,5);
 EndFill();
 linestyle(3,$E3E3E3);
 circle(5,5,4.5);
 linestyle(1,clblack);
 arcto(5,5,50,220,5);
 checked:=false;
end;
 
constructor TRadioButton.Create(AOWNER:movieclip);
begin
 inherited Create(AOWNER,'Radiobutton',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:='RadioButton';
 Checked:=false;
end;
 
procedure TTick.onPress;
begin
  TRadioButton(_parent).Checked:=true;
end;
 
Procedure TTick.circle(Cx,Cy,Radius:number);
var a,b,R: number;
begin
  R:=Radius;
  a:= R * 0.414213562;
  b:= R * 0.707106781;
  moveTo(Cx+R,Cy);
  CurveTo(Cx+ R, Cy+-a, Cx+b,Cy -b);
  CurveTo(Cx+ a,Cy-R,Cx,Cy -r);
  CurveTo(Cx-a,Cy -R,Cx-b,Cy -b);
  CurveTo(Cx-R, Cy-a,Cx-R,Cy);
  CurveTo(Cx-R,Cy+a,Cx-b,Cy+b);
  CurveTo(Cx-a,Cy +R,Cx,Cy+r);
  CurveTo(Cx+a,Cy +R,Cx+b,Cy+b);
  CurveTo(Cx+R,Cy+a,Cx+R,Cy);
end;
 
 Procedure TTick.onEnterFrame;
begin
// pas de changement
 if checked = TRadioButton(_parent).checked then
   exit;
// l'état à changé
 checked := not checked;
 if checked then
 begin
  linestyle(1,clblack);
  BeginFill(clBlack);
  circle(5,5,1.5);
 end else
 begin
  BeginFill(clWhite);
  linestyle(1,clwhite);
  circle(5,5,1.5);
 end;
end;
 
procedure TTick.arcto(x,y,tetai,tetaf,rayon:number);
var  lineangle,contdist,Endx,Endy,contx,conty:number;
     i:integer;
begin
  tetai:=tetai*math.pi/180;
  tetaf  :=tetaf*math.pi/ 180;
  lineangle:=(tetaf-tetai)/8;
  contdist:=rayon/cos(lineangle/2);
  moveto(x+rayon*cos(tetai),y-rayon*sin(tetai));
  for i:= 1 to 8 do
  begin
   endx:=x+rayon*cos(tetai+i*lineangle);
   endy:=y-rayon*sin(tetai+i*lineangle);
   contx:=x+contdist*cos(tetai+i*lineangle-lineangle/2);
   conty:=y-contdist*sin(tetai+i*lineangle-lineangle/2);
   curveto( contx,conty,endx,endy);
  end;
end;
 
end.

Code :
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
 
program PRadioButton;
 
{$FRAME_WIDTH 550}
{$FRAME_HEIGHT 400}
{$FRAME_RATE 32}
{$BACKGROUND $f0f0f0}
 
uses
  Flash8,URadiobutton;
type
 
   Essai=class(movieClip)
     current:number;
     radio,radio2:TRadioButton;
     Field:TextField;
     MyFont:Textformat;
     Procedure onEnterFrame;
     Constructor Create;
   end;
 
Constructor Essai.Create;
begin
 inherited create(nil,'essai',0);
 radio:=TRadioButton.create(self);
 with radio do
 begin
  _x:=100;
  _y:=100;
  caption.text:='Affichage n°1';
 end;
 
 radio2:=TRadioButton.create(self);
 with radio2 do
 begin
  _x:=100;
  _y:=120;
  caption.text:='Affichage n°2';
 end;
 
  MyFont:= TextFormat.Create('Arial', 25, $000000,true,false,false);
  Field :=TextField.Create(self, '',2, 10,150,450,40);
  Field.setNewTextFormat(MyFont);
  current:=0;
end;
 
Procedure Essai.onEnterFrame;
begin
if radio.checked and (current <> 1) then
 begin
   current := 1;
   radio2.checked:=false;
   Field.text:="j'ai pressé sur le premier radiobutton";
 end else
 if radio2.checked and (current <> 2) then
 begin
   current := 2;
   radio.checked:=false;
   Field.text:="j'ai pressé sur le second radiobutton";
 end;
end;
 
begin
 essai.create;
end.
__________________
Citation:
tout développeur plongé dans son code subit une poussée d'urticaire de bas en haut égale au poids du volume d'unités qu'il ajoute.
Archimède est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 01/07/2012, 12h41   #4
Roland Chastain
Membre Expert
 
Homme Roland Chastain
Inscription : décembre 2011
Messages : 687
Détails du profil
Informations personnelles :
Nom : Homme Roland Chastain
Âge : 39
Localisation : Mali

Informations professionnelles :
Secteur : Enseignement

Informations forums :
Inscription : décembre 2011
Messages : 687
Points : 1 002
Points : 1 002
Beau travail, confrère.
__________________
L'Art est long et le Temps est court.
Roland Chastain est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/07/2012, 13h53   #5
Archimède
Membre émérite
 
Avatar de Archimède
 
Homme anthony
Enseignant
Inscription : avril 2005
Messages : 1 027
Détails du profil
Informations personnelles :
Nom : Homme anthony
Localisation : France, Charente Maritime (Poitou Charente)

Informations professionnelles :
Activité : Enseignant
Secteur : Enseignement

Informations forums :
Inscription : avril 2005
Messages : 1 027
Points : 977
Points : 977
Hello,
merci, confrère mais j'ai été un peu aidé...Le fait d'avoir séparer le program de l'unité m'a fait oublier le conflit évident sur le checked.
__________________
Citation:
tout développeur plongé dans son code subit une poussée d'urticaire de bas en haut égale au poids du volume d'unités qu'il ajoute.
Archimède est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 01h07.


 
 
 
 
Partenaires

Hébergement Web