Thank you, but the code not working??
calculate_btn.onRelease = function(){
num1 = Number (test1)
num2 = Number (test2);
myNum = num1+num2;
total = format(myNum, 2 );
test1 = format(num1, 2 );
test2 = format(num2, 2 );
}
above shown is mine..
test1 = Input Text 1
test2 = Input Text 2
total = Dynamic Text
anything wrong??
FK'n_dog
Attached Files
LOL! My mistake, i thought need to paste both code, it works now, thanks you!
everytime when i type wrong in the Input/ Dynamic Text, it will appear NaN, is there a way to change it to other word?
FK'n_dog
look up Textfield.restrict in the Help Files
input textfields require instance names (t1, t2) to make this work
t1.restrict = "0-9.";
t2.restrict = "0-9.";
// fields will only accept 0 to 9 and "."
Okay, it works, can the fields accept "," too? i've failed to add, if the number with "," e.g. thousand (1,000.00), if double clicked it will appear NaN, if the number below thousand (hundred) work fine.
And how to create a button for clearing all the fields? e.g. the button at Calculator, the "C" (should be in red colour), C = Clear; Reset?
Once again, Thank you!
FK'n_dog
add "," to restrict to include it
note you cannot add with "," character
you must use string manipulation to remove "," before adding -
num1 = num1.split(",").join("");
num1 = Number(num1);
to clear any textfield , use its instance name - t1.text = "";
textfields clearing work, commas not working, maybe i did wrong
Thank you.
edited: Can i pm you? but i can't.. it saids you may be blocked?? wanted to ask you something out of this thread, thanks..
Last edited by anthemz; 08-18-2008 at 09:10 AM .
1 more thing, how to multiply with %? e.g. 1,000*3%=? if i type the 3"%" in input text, then calculate.. equal NaN. thanks..
FK'n_dog
Flash does not recognise the % character as a Number
3% = 0.003
so you must calculate - 1000*.003
Thank you, then what about the comma ",", i can't make it work..
Originally Posted by
a_modified_dog
add "," to restrict to include it
note you cannot add with "," character
you must use string manipulation to remove "," before adding -
num1 = num1.split(",").join("");
num1 = Number(num1);
to clear any textfield , use its instance name - t1.text = "";
FK'n_dog
what is it about the comma that doesn't work ?
test this in a new file -
PHP Code:
num1 = "123,456.05" ; // string from input textfield
trace ( num1 + " - " + typeof num1 ); // 123,456.05 - string
num1 = num1 . split ( "," ). join ( "" );
num1 = Number ( num1 );
trace ( num1 + " - " + typeof num1 ); // 123456.05 - number
Hi modified_dog, I need your help, back to the question again, I cant manage to calculate with "," in the input text, example if i enter..
1,000.00 + 1,000.00 =
when i press calculate it will become
N.aN + N.aN = N.aN
Is there a way to make flash read ","? (refer post #22, FK_calc.fla)
2nd question, how to change NaN to other words? e.g. Error?
Many Thanks for help.
FK'n_dog
08-28-2008, 11:09 AM POST
remove the comma before attempting to use the number -
num1 = num1.split(",").join("");
num1 = Number(num1);
Thanks for the reply.
I can't manage to do it, keep on trying.. still the same, can you show me with .fla? Sorry, I'm not very good at actionscript.
Thank you.
Anyone can help please?
FK'n_dog
hope this file helps you on your way
Attached Files
Thank you, but still cracking my head, after split your script into each buttons, do i still need to add doSplits()? cause it's not working when i press the button, still working on it..
Edited: on Text, you add it's name on Instance, eg. inp1, so = inp1.text on script? how if i add it's name on variable? do i still need to add .text behind? cause i normally use Variable instead of Instance.
Last edited by anthemz; 04-05-2009 at 12:12 PM .
FK'n_dog
variable names on TextFields are old practice (Flash 4/5)
recommended to always use instance names .
doSplits() removes the comma, allowing you to do Math with the number
it is needed if you type comma into the field
Flash cannot add/minus etc any number that contains comma.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width