Problem using the List Box component Flash Pro CS6 and AS3
Hi all. I am making an application to convert from one unit to another. I am using the List Box component. The user has to enter the input value in an input text field, select the unit which has to be converted from the list box and the result is displayed in the result text field. The problem is this: when an input value has been entered in the input field and the result for a given unit has been calculated, changing the input value and clicking on the same label item does not reflect the new result. Another unit has to be selected and then one has to go back to the unit for which the input has to be converted. I have attached screenshots (for converting Deciliters to Centiliters) here under to illustrate my explanation:



What line of code should I use or add to my code to solve this problem? The AS3 code I wrote is shown here under. I am new to AS3, so please bear with me. I am using Adobe Flash Pro CS6 on a 32-bit Windows-7 machine.
stop();
//The Text Boxes
var txtBox:TextFormat=new TextFormat();
txtBox.size = 16;
txtBox.color = 0x000000;
txtBox.font = "futura lt bt";
numIn.setStyle("textFormat",txtBox);
numOut.setStyle("textFormat",txtBox);
//The List Boxes
listBox.height = 160;
listBox.width = 160;
listBox.addItem({label: "Deciliters to Centiliters"});
listBox.addItem({label: "Deciliters to Liters"});
listBox.addItem({label: "Degrees to Circumferences"});
listBox.addItem({label: "Degrees to Grades"});
listBox.addItem({label: "Degrees to Minutes"});
listBox.addItem({label: "Degrees to Quadrants"});
listBox.addItem({label: "Degrees to Radians"});
listBox.addItem({label: "Degrees to Seconds"});
//The List Box Functions
//First box
listBox.addEventListener(Event.CHANGE, dCalFn);
function dCalFn (event:Event):void
{
var ni:Number=Number(numIn.text);
var no:Number=Number(numOut.text);
if (ni>=0)
{
switch (listBox.selectedItem.label)
{
case ("Deciliters to Centiliters"):
{
no = Math.round((ni*10)*1000)/1000;
break;
}
case ("Deciliters to Liters"):
{
no = Math.round((ni*0.1)*1000)/1000;
break;
}
case ("Degrees to Circumferences"):
{
no = Math.round((ni*0.0027778)*1000)/1000;
break;
}
case ("Degrees to Grades"):
{
no = Math.round((ni*1.1111111)*1000)/1000;
break;
}
case ("Degrees to Minutes"):
{
no = Math.round((ni*60)*1000)/1000;
break;
}
case ("Degrees to Quadrants"):
{
no = Math.round((ni*0.0111111)*1000)/1000;
break;
}
case ("Degrees to Radians"):
{
no = Math.round((ni*0.0174533)*1000)/1000;
break;
}
case ("Degrees to Seconds"):
{
no = Math.round((ni*3600)*1000)/1000;
break;
}
}
textOut.text = ("Converted\n"+listBox.selectedItem.label);
numOut.text=String(no);
}
if (numIn.text == String(""))
{
textOut.text = ("No conversion");
numOut.text = String("No Value");
}
}