I’m using two ComboBox to let user to choose two numbers, after that, they just press GO and will see the answer.
My question is “Can I get the answer directly after user choose their numbers from the ComboBox and no need to pressing the go button?”
Below are the code I use and I attach my SWF file! Please help and Thanks a lot!
import flash.events.Event;
//Uncomment the following line if create runtime ComboBox
//import fl.controls.ComboBox;
//Add Items to ComboBox
box1Combo.prompt = "Please select a number";
box1Combo.addItem( {label: "1" } );
box1Combo.addItem( {label: "2" } );
box1Combo.addItem( {label: "3" } );
box1Combo.addItem( {label: "4" } );
box1Combo.addItem( {label: "5" } );
//Add CHANGE event listener to ComboBox
//Whenever the index of Combox CHANGE, function fruitSelect will be called
box1Combo.addEventListener(Event.CHANGE, numberSelect1);
function numberSelect1(event:Event){
//Display the Index of ComboBox
// ComboIndex_txt.text = event.target.selectedIndex;
//Display the Label of ComboBox
ComboLabel_txt1.text = event.target.value;
}
//Uncomment the following line if create runtime ComboBox
//import fl.controls.ComboBox;
//Add Items to ComboBox
box2Combo.prompt = "Please select a number";
box2Combo.addItem( {label: "1" } );
box2Combo.addItem( {label: "2" } );
box2Combo.addItem( {label: "3" } );
box2Combo.addItem( {label: "4" } );
box2Combo.addItem( {label: "5" } );
//Add CHANGE event listener to ComboBox
//Whenever the index of Combox CHANGE, function fruitSelect will be called
box2Combo.addEventListener(Event.CHANGE, numberSelect2);
function numberSelect2(event:Event){
//Display the Index of ComboBox
// ComboIndex_txt.text = event.target.selectedIndex;
//Display the Label of ComboBox
ComboLabel_txt2.text = event.target.value;
}
go_btn1.addEventListener(MouseEvent.CLICK, answer1);
// This will set the compiler
// waiting for a mouse click
// on our button
function answer1 (event:Event):void
{
// Let's find out what is on our screen!
var number1:Number = Number(ComboLabel_txt1.text);
// This will find out what is on the Amount Box
// and convert it to a value
var number2:Number= Number(ComboLabel_txt2.text);
// Since we are looking for a percentage
// we are dividing the value by 100
var answer1:Number = number1+ number2;
// Now let's put the result
// in the Dynamic Text Box
// The Value has to become a string
Total_txt1.text = String(answer1);
//Thanks for Watching!!
}