PDA

View Full Version : Combo box


cutey_kira
10-21-2006, 01:41 AM
Hey ppl,

i have a little thing in flash with 2 input txt boxes, 1 dynamic txt box and a button and when u enter 2 numbers and press the button it will add the numbers together and display in the dinamic txt box .

i have that all working now i have added a combo box with the lables "+-*/" and i want to be able to click oner of the lables so it will be able to - * / as well as + the 2 numbers together i have written my code up but i dont know how to target my combo box as i cant assight a varible name and i cant get an instance name to work.

here is my code


on (release) {

if (Combobox = ("+")) {
answer = Number(num1) + Number(num2);
}
else if (Combobox = ("-")) {
answer = Number(num1) - Number(num2);
}
else if (Combobox = ("*")) {
answer = Number(num1) * Number(num2);
}
else if (Combobox = ("/")) {
answer = Number(num1) / Number(num2);
}

}

i have used Combobox as the combo boxes instance name but no luck.

Any suggestions???

Do i have to use something like "on (Change)"

cutey_kira
10-21-2006, 02:16 AM
Hey ppl,

i have a little thing in flash with 2 input txt boxes, 1 dynamic txt box and a button and when u enter 2 numbers and press the button it will add the numbers together and display in the dinamic txt box .

i have that all working now i have added a combo box with the lables "+-*/" and i want to be able to click oner of the lables so it will be able to - * / as well as + the 2 numbers together i have written my code up but i dont know how to target my combo box as i cant assight a varible name and i cant get an instance name to work.

here is my code


on (release) {

if (Combobox = ("+")) {
answer = Number(num1) + Number(num2);
}
else if (Combobox = ("-")) {
answer = Number(num1) - Number(num2);
}
else if (Combobox = ("*")) {
answer = Number(num1) * Number(num2);
}
else if (Combobox = ("/")) {
answer = Number(num1) / Number(num2);
}

}

i have used Combobox as the combo boxes instance name but no luck.

Any suggestions???

adrian_brooks
10-23-2006, 03:19 AM
Hi,

Is this in Flash 8 or 4 MX?

If this is Flash 8, you will not be able to address the selection of the combo box just by calling out it's instance name as you have done. 'Combobox' is an object and objects have events, methods and properties.

A comparative analogy would be your car. It would be like you standing outside of your car and holding your keys out to it and wondering why it's not starting (remote starting is not permitted here):p.
This is because the car is an 'object', its color is a 'property', if it backfires when running, that is an 'event', and your ignition is the 'method' used for starting it. So, for your car to start, you have to get inside of the car 'object' and access the ignition 'method' to cause the engine running 'event' to be activated. The same applies to flash objects. You need to get inside of them to use their methods, properties or events.

Flash is extremely dedicated to object oriented programming. This is no exception.

I don't know how you populated your combo box's data and label values. If you used a key/value array to do it, then all you need to do is ask for the value by its respective key name. I'm not sure what the default key names are though if you just used the data & label editors that are built into flash.

So, in order to do what you are attempting to do, try this instead;

on (release) {
// this line creates an object reference to the selected item of your combobox object
var item_obj:Object = _root.Combobox.selectedItem;
if (item_object['keyname'] == "+") {
answer = Number(num1) + Number(num2);
}
else if (item_object['keyname'] == "-") {
answer = Number(num1) - Number(num2);
}
else if (item_object['keyname'] == "*") {
answer = Number(num1) * Number(num2);
}
else if (item_object['keyname'] == "/") {
answer = Number(num1) / Number(num2);
}

}

I know this will work if you can replace the 'keyname' strings with the actual key names that are making up your data array and your label array.

Hope this helped :)