A Flash Developer Resource Site

Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 54

Thread: [CS3] How to add "," & "." in Dynamic Text.

  1. #21
    Member
    Join Date
    Dec 2005
    Posts
    84
    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??

  2. #22
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Flash 8 fla attached
    Attached Files Attached Files

  3. #23
    Member
    Join Date
    Dec 2005
    Posts
    84
    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?

  4. #24
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    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 "."

  5. #25
    Member
    Join Date
    Dec 2005
    Posts
    84
    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!

  6. #26
    Member
    Join Date
    Dec 2005
    Posts
    84
    bump

  7. #27
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    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 = "";

  8. #28
    Member
    Join Date
    Dec 2005
    Posts
    84
    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.

  9. #29
    Member
    Join Date
    Dec 2005
    Posts
    84
    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..

  10. #30
    Member
    Join Date
    Dec 2005
    Posts
    84
    bump

  11. #31
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    Flash does not recognise the % character as a Number
    3% = 0.003
    so you must calculate - 1000*.003

  12. #32
    Member
    Join Date
    Dec 2005
    Posts
    84
    Thank you, then what about the comma ",", i can't make it work..

    Quote 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 = "";

  13. #33
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    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 

  14. #34
    Member
    Join Date
    Dec 2005
    Posts
    84
    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.

  15. #35
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    08-28-2008, 11:09 AM POST

    remove the comma before attempting to use the number -

    num1 = num1.split(",").join("");
    num1 = Number(num1);

  16. #36
    Member
    Join Date
    Dec 2005
    Posts
    84
    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.

  17. #37
    Member
    Join Date
    Dec 2005
    Posts
    84
    Anyone can help please?

  18. #38
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    hope this file helps you on your way
    Attached Files Attached Files

  19. #39
    Member
    Join Date
    Dec 2005
    Posts
    84
    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.

  20. #40
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center