A Flash Developer Resource Site

Results 1 to 13 of 13

Thread: Simple dynamic text question

  1. #1

    Simple dynamic text question

    I'd like to be able to use the money symbol ($) and commas in a dynamic text field, but flash doesn't seem to allow this. Am I missing something or is there a work around?

  2. #2
    Senior Member Dricciotti's Avatar
    Join Date
    Aug 2002
    Posts
    2,988
    It worked fine for me in flash. Are you loading the contents of the textfield from a file?

  3. #3
    No, I have the dynamic text variable defined as: bank.

    In the first frame of the movie I have: bank = 35000.

    By pressing a button in the movie, 700 is subtracted from bank.

    The problem is I'd like to have: bank = $35,000 but it doesn't work with the $ and comma added.

  4. #4
    FK Newb Beater
    Join Date
    Dec 2002
    Location
    Seattle
    Posts
    676
    The problem is that you have the wrong datatype.
    bank = 35000 is a Number
    bank = $35,000 is a String

    You cannot subtract 700 from a string like you can a number.

    try this:
    code:

    bank = 35000
    bank_txt = "$"+bank.toString().substr(0, 2)+","+bank.toString().substr(2);
    trace(bank_txt);

    Just because you changed the code, doesn't mean it's yours

    Most Recent Work:
    Commercial tanning beds website

  5. #5
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    hmm, you can also either simply concatenate the string and the variable containing the value as:-
    code:

    bank = 35000;
    bank_txt = "$"+bank;
    trace(bank_txt);


    .
    -Aditya

  6. #6
    Thanks for the help so far, Sleeve & Adit_ya_sharma.

    There's still a problem with the comma (see swf file here ), it doesn't stay in the right place as the number increases/decreases. Any ideas on how to fix this?

    This is what the code looks like for the button that changes the dynamic text:
    code:
    on (press) {
    _root.miss00.gotoAndStop(2);

    bank = bank - 700;
    bank_txt = "$"+ bank.toString().substr(0, 2) + "," + bank.toString().substr(2);
    trace(bank_txt);

    spent = spent + 700;
    spent_txt = "$"+ spent.toString().substr(0, 2) + "," + spent.toString().substr(2);
    trace(spent_txt);

    miss = miss + 1;
    }

    Last edited by RNFlasher; 03-28-2005 at 03:36 AM.

  7. #7
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    Try this:-
    code:

    bank = bank - 700;
    bank_txt= "$"+bank.toString().Substr(0,bank.toString().lengt h-2)+","+bank.toString().Substr(bank.toString().leng th-2,bank.toString().length);

    -Aditya

  8. #8
    Adit_ya_sharma,

    It says "$undefine" now when the button is pressed (see swf file here ). Unfortunately, I don't know enough about strings to fix it. I imagine there's just one little thing off.

    This is what the code looks like for the button that changes the dynamic text:
    code:
    on (press) {
    _root.miss00.gotoAndStop(2);

    bank = bank - 700;
    bank_txt= "$"+bank.toString().Substr(0,bank.toString().lengt h-2)+","+bank.toString().Substr(bank.toString().leng th-2,bank.toString().length);
    trace(bank_txt);

    spent = spent + 700;
    spent_txt = "$"+ spent.toString().substr(0, 2) + "," + spent.toString().substr(2);
    trace(spent_txt);

    miss = miss + 1;
    }


  9. #9
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    Initialize the variable 'bank' with a value in the main frame or anywhere. Currently I think you've just specified the value in the text box, but the value of the variable 'bank' remains 'undefined'. Hope that helps.
    -Aditya

  10. #10
    The variable is defined on the first frame:

    bank = 35000;

    So that's not the problem if I understand you correctly.

  11. #11
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    Ah, dunno what's happening. make sure that the text boxes have the range specified with digits (0-9) and special symbols also included as (&,)checkout the attachment, it contains what you need, its in flash mx format. Check the first main frame of the movie too.
    -Aditya

  12. #12
    Oddly, it works fine for 'spent,' but returns '$undefined' for 'bank,' when published to the version 7 flash player. Published to lower versions 'bank' works fine. This isn't a problem as I'd use the lowest player version possible anyway, it's just weird.

    Thanks for all your help, Adit_ya_sharma.

  13. #13
    doItLikeThis
    Join Date
    Jan 2004
    Location
    :noitacoL
    Posts
    1,080
    Its just that flash player 7 uses Actionscript v 2.0 with different syntax, and Iam using AS 1.0, that's why the problem might be occuring, anyway, welcome.
    -Aditya

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