hi i got a question i do not know if it will work in flash.
I know how to let flash calculate but i was wondering if it can be done else.
here's what i have.
3 textfields: firstNumber, secondNumber, Result.
At the moment i have a button that will caculate when pressed and that works, but i was wondering if it can in someway auto calculate when entered a number ??
like when i place 20 in firstNumber textfield the result is 20
and if i enter 40 in the secondNumber textfield the result textfield would show 60 right away ?! instead of using a button ?
I really don't know if its possible, i only know that i would like it to act the same way as when i would do in microsoft excel.
If you give an action to a field there it will change the result right away when new number is placed.
If you were to attach the following code to any movieclip on the stage, then the textfields would display as you wish. If you dont have a movie on stage, create a blank one.
got one small problem though... i created another fla to test it and tried to do some extra
i got 5 textfields. a,b,c,d,result
ok now a starts of at being 501
then i count b,c, d to get the result. that works...
i also want it to auto set the new total so that would be a - result is new. it does do that but then the number keeps going down to zero and then moving back up..
OK, I think the problem lies in that you have got the field 'a' being calculated by minusing the Result value from its own value in the onClipEvent(enterFrame) handler, so that is 12 times/second.
You need to calculate this value only when the Result changes... so put in a variable named oldValue, then test to see if Result==oldValue, and if not, calculate the new value of field 'a', and reset oldValue to the new value of Result.
Hope that makes sense!
Hariyemadzisawira nhaka yedu! Down the SCUD and win!
I'm too lazy to read Private Messages.
The reason for this is that I set the score to change every time that one of the fields change... so when you enter 1 in the first field, it calculates 501-1=500;
then when you enter 20 in the second filed, it first calculates
500-(2+1)=497;
and then
497-(20+1)=476;
The extra 1 in each calculation is the first field being added each time.
To avoid this, you will have to calculate only when the field's value is complete, possible using an onKillfocus for each text field. Or else, a button that can be pressed ( though thats what you originally wanted to avoid ) or a invisible button that could catch a tab or enter key-press.
Replace the if statement with this:
_root.Count1.onKillFocus = function (newFocus) {
_root.a=parseFloat(_root.a) - parseFloat(_root.result);
}
_root.Count2.onKillFocus = function (newFocus) {
_root.a=parseFloat(_root.a) - parseFloat(_root.result);
}
_root.Count3.onKillFocus = function (newFocus) {
_root.a=parseFloat(_root.a) - parseFloat(_root.result);
}
Its still not perfect, but better!
Hariyemadzisawira nhaka yedu! Down the SCUD and win!
I'm too lazy to read Private Messages.