<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white" viewSourceURL="srcview/index.html">
<mx:Style>
RadioButton {
paddingLeft: 20;
horizontalGap: 4;
}
.QuestionVBox {
paddingBottom: 50;
}
.QuestionText {
fontWeight: bold;
}
</mx:Style>
<mx:Script>
<![CDATA[
import mx.controls.Alert;
private function checkAnswers():void {
var success:Boolean = true;
success = checkGroup(q1_group) && success;
success = checkGroup(q2_group) && success;
Alert.show("SUCCESS = " + success);
}
private function checkGroup(rbg:RadioButtonGroup):Boolean {
var rb:RadioButton;
var valid:Boolean = true;
var i:int;
if (rbg.selectedValue != true) {
valid = false;
rb = rbg.selection;
if (rb != null) {
rb.includeInLayout = false;
rb.visible = false;
}
} else {
for (i = 0; i < rbg.numRadioButtons; i++) {
rb = rbg.getRadioButtonAt(i);
if (!rb.selected) {
rb.includeInLayout = false;
rb.visible = false;
}
}
}
return valid;
}
]]>
</mx:Script>
<mx:RadioButtonGroup id="q1_group" enabled="false" />
<mx:RadioButtonGroup id="q2_group" enabled="false" />
<mx:Panel title="Subject: Periodic Table" width="100%" height="100%">
<mx:VBox styleName="QuestionVBox" width="100%">
<mx:Text styleName="QuestionText"
selectable="false"
width="100%">
<mx:text>1) Which three groups of the Periodic Table contain the most elements classified as metalloids (semimetals)?</mx:text>
</mx:Text>
<mx:RadioButton id="q1_a"
label="1, 2, and 13"
group="{q1_group}" />
<mx:RadioButton id="q1_b"
label="2, 13, and 14"
group="{q1_group}" />
<mx:RadioButton id="q1_c"
label="14, 15, and 16"
group="{q1_group}"
value="true" />
<mx:RadioButton id="q1_d"
label="16, 17, and 18"
group="{q1_group}" />
</mx:VBox>
<mx:VBox styleName="QuestionVBox" width="100%">
<mx:Text styleName="QuestionText"
selectable="false"
width="100%">
<mx:text>2) Which element has the highest first ionization energy?</mx:text>
</mx:Text>
<mx:RadioButton id="q2_a"
label="sodium"
group="{q2_group}" />
<mx:RadioButton id="q2_b"
label="aluminum"
group="{q2_group}" />
<mx:RadioButton id="q2_c"
label="calcium"
group="{q2_group}" />
<mx:RadioButton id="q2_d"
label="phosphorus"
group="{q2_group}"
value="true" />
</mx:VBox>
<mx:ControlBar horizontalAlign="right">
<mx:Button label="Check answers"
click="checkAnswers();" />
</mx:ControlBar>
</mx:Panel>
</mx:Application>