in a part of a flash application I use two buttons to increase or decrease a particular number to which a limit is set. I added some correction options to that, like when you select that number and enter a "NaN", after pressing a button it should be corrected to "1", or if you enter a higher number than the limit, it should be decreased to the limit.
But the problem is: when the limit is set to a number higher that 9 (say 20), and you enter a number lower than 9, it acts as if it were a "higher than the limit" number. The other problem is when I enter a big number and press one of the buttons, sometimes it really increases/decreases the number once, although it is far higher than the limit. Only when I press the button once again, it changes the number to the limit!!
Here is the code to the ">" button:
Code:
on (release) {
if (isNan(_root.mynumber)) {
_root.mynumber = 1;
} else if (_root.mynumber>_root.lastnumber) {
_root.mynumber = _root.lastnumber;
} else {
if (_root.mynumber<_root.lastnumber) {
_root.mynumber++;
}
}
}
and for the "<" one:
Code:
on (release) {
if (isNan(_root.mynumber)) {
_root.mynumber = 1;
} else if (_root.mynumber>_root.lastnumber) {
_root.mynumber = _root.lastnumber;
} else {
if (_root.mynumber>1) {
_root.mynumber--;
}
}
}
I found out that the error occurs only when I enter a single-digit number which is greater than the leftmost figure of the limit number. e.g.: the limit (_root.lastnumber) is set to 462, and 5 is entered (between the buttons: _root.mynumber). In this case seems flash to assume 5 greater than 462, because "5" is bigger than "4"... !
Hi.....
Here you go.....this should do it.......
I was going to add the ....isNaN...function to the limit number
(_root.lastnumber).... as well, in case a letter is accidentally typed but i thought you might not need that....anyway..hope this helps
stop();
_root.mynumber = 0;
_root.lastnumber = 0;
onEnterFrame = function () {
if (_root.mynumber>_root.lastnumber) {
_root.mynumber = _root.lastnumber;
}
}
//all the other stuff you have on the mc actions
and change the vars on the text fields to mynumber and lastnumber rather than _root.mynumber and _root.lastnumber
then take all the code off the mcs except for the onpress functions (or you can even just make them buttons)
if you're still having problems reply back and i'll post the fla i tested on (which works 100%)
thank you very very much for your kind help, now it works!
but I'm still curious why does flash do so..., as it makes the same error with moagrius' solution; I set the limit number to 54, and as soon as I type "8" in "mynumber", it goes to 54!
However, once again a flasher's (nominee's) life was saved!!!
(3 "ear training" programs for musicians)
(load an exercise from the tab bar (select exercise nr. and press "Übung laden"), and after you have heared it, you can enter the notes, and let the program tell you which are correct/false [except gs-intr]) (the "check" button is the one right to "play")