PDA

View Full Version : If instruction


Kahlil
06-21-2002, 05:01 AM
I got a simple code taken from the Flash Actionscript (from the source) the code is very straight forward. However it doesnt execute as properly.

Program: supposed to give an string out put (message) saying if you over pay, underpay, or payd fully. So it uses an if, else, else if function.

Problem: for some strange reason that I am not able to see, the first output is wrong. This mean that if I put a smaller number the output keeps telling me that is payed in full.

----Code----
on (press) {
amountPaid = Number(paid.text);
amountOwed = Number(owed.text);
if (isNaN(amountPaid)) {
message.text = "What the **** you entered??";
} else if (amountPaid<amnountOwed) {
difference = amountOwed-amountPaid;
light.gotoAndStop("Off");
message.text = "You underpaid your bill by "+difference+"dollars.";
} else if (amountPaid>amountOwed) {
difference = amountPaid-amountOwed;
light.gotoAndStop("Hot");
message.text = "You overpaid your bill by "+difference+" dollars.";
} else {
light.gotoAndStop("On");
message.text = "You have paid your bill in full.";
}
}
on (release) {
light.gotoAndStop("Off");
message.text = "";
}

poab
06-21-2002, 10:47 AM
Hi,

I'm assuming you copy-pasted this code from your file?

If so the problem's a typo:

} else if (amountPaid<amnountOwed) {


(You have an extra 'n' in amountOwed).

cheers.

Abelius
06-21-2002, 01:45 PM
..."on (press)" and then "on (release)" ...???

Don't the tow of them counteract each other?

poab
06-21-2002, 02:09 PM
Don't the tow of them counteract each other?

-nope, because they can't happen simultaneously, either the mouse button is down or it isn't. As long as the curly brackets are in the right place (which they are) then the two don't effect each other.

I suppose it could cause a problem if you had loads of code in the on(press) because users click quite fast and Flash may not complete the code before moving to the on(release) code. Not sure about that. Anyone? Still- there's not enough code here to cause that problem I don't think.

cheers.

Kahlil
06-21-2002, 07:23 PM
Thanks it was a typo indeed, thanks for the advise. I kinda solve it after re-doing the code from scratch. I still need to develop a good sense of debugging. I guess thats why I am a newbian.

;)