RadioButtons in ActionScript

Radio Buttons allow only one in a group to be selected. Notice that there are 2 groups: vehicles and food. You can select one from each group. An array made it easier to add event listeners to all of the radio buttons.

Get Adobe Flash player

The properties for radCar are shown. Notice the groupName. It is vehicles for all of the vehicles and food for all of the food. This allos one vehicle and one food to be selected.:
properties for radCar

The code is shown below:

import flash.events.MouseEvent;
var radButtons: Array=new Array("radTrain","radCar","radBus","radPizza","radIcecream","radSushi");
var i:int=0;
for(i=0;i<radButtons.length;i++) {
	var s:String=radButtons[i];
	this[s].addEventListener(Event.CHANGE,goChoice);
}
function goChoice(e:Event):void {
	var s:String=e.target.name;
	var pic=e.target.value;
	this[pic].visible=this[s].selected;
}
Download the movie
INDEX, Introduction to Components, ComboBox: Select a Vehicle, ComboBox: Demo, ComboBox: DataBinding in ActionScript, Radio Buttons, Check Boxes, Numeric Stepper
Next lesson: Drawing in ActionScript3

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Radio Buttons