Because of the constant attack by the wiki spam bots, accounts that are created and not used will be deleted. If you are a legitimate user, and your IP was blocked, please contact any active administrator - look at Special:RecentChanges and see who is busy fighting spam.

Radio button

From SWFTools
Jump to: navigation, search

In Graphic User Interface (GUI) programming, a Radio Button is a button (with a text) that belongs to a set of other buttons, and these buttons are correlated so that at most one of them can be selected at any time.

For example, we could have five radio buttons for the selection of your favorite color:

Which is your favourite colour?
[ ] Blue
[ ] Yellow
[ ] My name is Sir Launcelot of Camelot
[ ] To seek the Holy Grail
[ ] An African or European swallow?

If this were a radio button, it would be possible to chose one, but not two, of the options. There should also be a button to finish the query, like a [ANSWER] button.

Most GUI packages have simple ways to define Radio Buttons. swfc doesn't - a set of Radio Buttons must be painfully programmed using a combination of Button, Text and, possibly, Box. Also, in order to display text, it's necessary to declare a Font.

Here is a way to implement the above query. Obviously, other solutions are possible. This solution combines basic .sc script with a minimum of action programming; action is used only to handle the mouse clicks using OnMouseClick to track variables _xmouse and _ymouse, and go to the next frame.

First, the initial screen (with the query and emptyboxes) is shown, and the script stops, waiting to the mouseclick. Mouseclicks inside the [ ] buttons will clear the other buttons. This is done by, sequentially, incluing full filled boxes and then deleting them. A mouseclick in the [ANSWER] button will be ignored if no radio button was chosen (in a decent and professional script, a huge and offensive error message should appear, telling the user that he is a newbie, moron and/or n00b), and will jump to the final frame if one of the radio buttons was chosen. It will clear everything (using del) and show a message telling if it was the right or the wrong answer.

This example is not reproducible, because it's possible that there's no file /usr/share/fonts/gnu-free/FreeSans.ttf in your computer - replace it with an existing .ttf font type (for more about this, read Font).

.flash bbox=600x700 fps=50 background=white
  .font myfont "/usr/share/fonts/gnu-free/FreeSans.ttf"
  .text query font=myfont text="What is your favourite colour?" size=50% color=black
  .text answer1 font=myfont text="Blue" size=50%  color=black
  .text answer2 font=myfont text="Yellow" size=50% color=black
  .text answer3 font=myfont text="My name is Sir Launcelot of Camelot" size=40% color=black
  .text answer4 font=myfont text="To seek the Holy Grail" size=50% color=black
  .text answer5 font=myfont text="An African or European swallow?" size=50% color=black
  .text final font=myfont text="ANSWER" color=black
  .text rightanswer font=myfont text="CORRECT" size=180% color=green
  .text wronganswer font=myfont text="WRONG" size=200% color=red

  .box emptybox1 50 50 color=black
  .box emptybox2 50 50 color=black
  .box emptybox3 50 50 color=black
  .box emptybox4 50 50 color=black
  .box emptybox5 50 50 color=black

  .box fullbox1 50 50 color=black fill
  .box fullbox2 50 50 color=black fill
  .box fullbox3 50 50 color=black fill
  .box fullbox4 50 50 color=black fill
  .box fullbox5 50 50 color=black fill

  .box finalbox 300 50 color=black

  .action:
     var answer = 0;  // nothing chosen yet
     onMouseDown = function() {
       x = _xmouse;
       y = _ymouse;
       if (x >= 0 && x <= 50) {
         if (y >= 100 && y <= 150) {
           answer = 1;
           gotoAndPlay(100);
         } else if (y >= 200 && y <= 250) {
           answer = 2;
           gotoAndPlay(200);
         } else if (y >= 300 && y <= 350) {
           answer = 3;
           gotoAndPlay(300);
         } else if (y >= 400 && y <= 450) {
           answer = 4;
           gotoAndPlay(400);
         } else if (y >= 500 && y <= 550) {
           answer = 5;
           gotoAndPlay(500);
         }
       }
       if (answer != 0 && x >= 75 && x <= 375 && y >= 600 && y <= 650) {
         if (answer == 1) {
           gotoAndPlay(600);
         } else {
           gotoAndPlay(700);
         }
       }
     };
  .end

  .frame 1
  .put query y=50
  .put answer1 x=100 y=150
  .put emptybox1 x=0 y=100
  .put answer2 x=100 y=250
  .put emptybox2 x=0 y=200
  .put answer3 x=100 y=350
  .put emptybox3 x=0 y=300
  .put answer4 x=100 y=450
  .put emptybox4 x=0 y=400
  .put answer5 x=100 y=550
  .put emptybox5 x=0 y=500
  .put finalbox x=75 y=600
  .put final x=75 y=650
  .stop

  .frame 101
  .put fullbox1 x=0 y=100
  .stop

  .frame 201
  .del fullbox1
  .put fullbox2 x=0 y=200
  .stop

  .frame 301
  .del fullbox2
  .put fullbox3 x=0 y=300
  .stop

  .frame 401
  .del fullbox3
  .put fullbox4 x=0 y=400
  .stop

  .frame 501
  .del fullbox4
  .put fullbox5 x=0 y=500
  .stop

  .frame 601
  .del fullbox5
  .del answer1
  .del answer2
  .del answer3
  .del answer4
  .del answer5
  .del emptybox1
  .del emptybox2
  .del emptybox3
  .del emptybox4
  .del emptybox5
  .del query
  .del final
  .del finalbox
  .put rightanswer x=0 y=300
  .stop

  .frame 701
  .del rightanswer
  .put wronganswer x=0 y=300
  .stop

.end
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox