Why RadioButton still selected?
- January 15, 2010
- 2 replies
- 519 views
When i start game again my radioButton selected. But in startProgram function i told : .selected=false;
Where the problem?
Attached .fla.
code:
import fl.controls.RadioButtonGroup;
var radioGroup1:RadioButtonGroup=new RadioButtonGroup("Coin Loss");
eagle_rb.group=radioGroup1;
tails_rb.group=radioGroup1;
var randomNumber:Number;
var points:Number=0;
function startProgram():void {
eagle_rb.visible=true;
tails_rb.visible=true;
coin_mc.visible=true;
eagle_rb.selected=false;
tails_rb.selected=false;
playAgain_btn.label="Play Again";
coinToss_btn.label="Coin Toss";
coinToss_btn.useHandCursor=true;
playAgain_btn.useHandCursor=true;
points_txt.text="0";
eagle_rb.label="Eagle";
tails_rb.label="Tails";
error_txt.text="";
playAgain_btn.visible=false;
coinToss_btn.addEventListener(MouseEvent.CLICK, checkAnswer);
playAgain_btn.visible=true;
playAgain_btn.enabled=false;
coinToss_btn.enabled=true;
points=0;
}
startProgram();
function checkAnswer(event:MouseEvent):void {
randomNumber=Math.random();
trace(randomNumber);
if (randomNumber<0.5) {
coin_mc.gotoAndStop("eagle");
} else {
coin_mc.gotoAndStop("tails");
}
if (radioGroup1.selection==null) {
error_txt.text="Need choose any answer!";
return;
} else if (radioGroup1.selection.label=="Eagle" && randomNumber<0.5) {
error_txt.text=radioGroup1.selection.label+" - correct";
points+=100;
points_txt.text=String(points);
} else if (radioGroup1.selection.label=="Eagle" && randomNumber>0.5) {
error_txt.text=radioGroup1.selection.label+" - wrong";
points-=100;
points_txt.text=String(points);
} else if (radioGroup1.selection.label=="Tails" && randomNumber>0.5) {
error_txt.text=radioGroup1.selection.label+" - correct";
points+=100;
points_txt.text=String(points);
coin_mc.gotoAndStop("tails");
} else {
error_txt.text=radioGroup1.selection.label+" - wrong";
points-=100;
points_txt.text=String(points);
}
if (points==500||points==-500) {
gameResult();
}
}
function gameResult():void {
playAgain_btn.enabled=true;
if (points==500) {
message_txt.text="You are winner! You win 500 points!";
coinToss_btn.enabled=false;
} else if (points==-500) {
message_txt.text="You are lost! You must pay 500 points;)";
coinToss_btn.enabled=false;
}
playAgain_btn.addEventListener(MouseEvent.CLICK, playAgain);
error_txt.text="";
eagle_rb.visible=false;
tails_rb.visible=false;
coin_mc.visible=false;
}
function playAgain(event:MouseEvent):void {
startProgram();
}