-
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?
-
Senior Member
It worked fine for me in flash. Are you loading the contents of the textfield from a file?
-
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.
-
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);
-
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);
.
-
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.
-
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);
-
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;
}
-
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.
-
The variable is defined on the first frame:
bank = 35000;
So that's not the problem if I understand you correctly.
-
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.
-
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.
-
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.
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
|