IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Flash Pascal Discussion :

Souci avec un radiobutton maison


Sujet :

Flash Pascal

  1. #1
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut Souci avec un radiobutton maison
    Ci-joint :

    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
     
    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 : 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
     
    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) ?

  2. #2
    Expert éminent sénior
    Avatar de Paul TOTH
    Homme Profil pro
    Freelance
    Inscrit en
    Novembre 2002
    Messages
    8 964
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

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

    Informations forums :
    Inscription : Novembre 2002
    Messages : 8 964
    Points : 28 430
    Points
    28 430
    Par défaut
    Hello,

    au lieu de redessiner le Tick à chaque frame tu peux ajouter un checked local au tick
    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
     
    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 : 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
     
    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
    Le Store Excute Store

  3. #3
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    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 : 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
     
    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 : 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
     
    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.

  4. #4
    Rédacteur/Modérateur

    Avatar de Roland Chastain
    Homme Profil pro
    Enseignant
    Inscrit en
    Décembre 2011
    Messages
    4 070
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Décembre 2011
    Messages : 4 070
    Points : 15 454
    Points
    15 454
    Billets dans le blog
    9
    Par défaut
    Beau travail, confrère.
    Mon site personnel consacré à MSEide+MSEgui : msegui.net

  5. #5
    Membre chevronné
    Avatar de Archimède
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2005
    Messages
    1 644
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 58
    Localisation : France, Charente Maritime (Poitou Charente)

    Informations professionnelles :
    Activité : Enseignant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2005
    Messages : 1 644
    Points : 1 975
    Points
    1 975
    Par défaut
    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.

Discussions similaires

  1. soucis avec checkButton et RadioButton
    Par Ruyneau dans le forum Tkinter
    Réponses: 2
    Dernier message: 26/02/2012, 21h03
  2. [RegEx] souci avec <li> et <ul> avec un bbcode maison
    Par Atomicfryer dans le forum Langage
    Réponses: 3
    Dernier message: 24/03/2011, 22h26
  3. quelques soucis avec word 2000
    Par ramchou dans le forum Word
    Réponses: 3
    Dernier message: 06/09/2004, 18h13
  4. [DEBUTANT] petits soucis avec un prgm de chat
    Par LechucK dans le forum MFC
    Réponses: 8
    Dernier message: 19/01/2004, 16h52
  5. Réponses: 4
    Dernier message: 16/02/2003, 12h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo