use
case '1':
instead of
case 1:
or convert the keychain.text to an integer first
edit: it also looks like you are assigning an int 0 to keychain.text instead of to priceK like you wanted
hi i tried to change IF statement to Switch in Flash CS3 (ActionScript 3.0)
these are the codes:
/////////////// the IF statement works, and i already block the codes, i just copy here in case you guys might want to look at it/////////////////////////////////////////
if (keychain.text=='1') {
priceK=5;
} else if (keychain.text=='2') {
priceK=10;
} else if (keychain.text=='3') {
priceK=15;
} else if (keychain.text=='4') {
priceK=20;
} else if (keychain.text=='5') {
priceK=25;
} else {
priceK=0;
}
////////////////////////////////////////////////////////////////////
switch (keychain.text) {
case 1: priceK = 5;
break;
case 2: priceK = 10;
break;
case 3: priceK = 15;
break;
case 4: priceK = 20;
break;
case 5: priceK = 25;
break;
default: keychain.text = 0;
}
keychainPrice = Number(keychain.text) * priceK;
//////////////////////////////////////////////////////////////////////////////////////
the error was:
Description :1067: Implicit coercion of a value of type int to an unrelated type String.
Source: default: keychain.text = 0;