PDA

View Full Version : Problem Creating Substring


writern98
03-12-2007, 01:49 AM
I'm creating a Flash-based ordering movie, and I have a combobox for the credit card number that will take numbers only, length 16 and the variable is CardNo

At the order verification frame, I want to show 12 asterisks and only the last 4 of CardNo

I'm using a variable CardNoHide = "************" + CardNo.substr(12,4);

However, this returns:

************FT">

If I change to CardNoHide = CardNo;

Then it shows the entire card number properly. It's only when I try to slice or substring that it starts giving FORMATLEADING type stuff.

Can anyone lend some advice?

Thanks in advance!
Brad

MichaelxxOA
03-12-2007, 02:01 AM
// CardNoHide = CardNo;
var CardNo = '1234567891234567';
var CardNoHide = "************" + CardNo.substring( 12, 16 );

trace( CardNoHide );


I used substring for this one, it should be pretty self-explanatory.

Michael

writern98
03-12-2007, 02:30 AM
Michael:

Now you understand my frustration...yes, in theory, this SHOULD work, and it does when you define CardNo the way in which you did.

However, I am getting my CardNo from the var field of a combobox....and this is the only thing I can think that is messing it up. This combobox has the instance name of CardNumber and the corresponding code:

CardNumber.restrict = "0-9";

This does a great job of limiting the input to digits. And once again, if I forget about hiding the last 4:

CardNoHide = CardNo;

CardNo will show up just fine (with CardNoHide as the var for a dynamic text field in the "check your order" frame).

I'm a newbie to posts, so forgive me if my syntax/approach is a little cranked.

Brad

jsonchiu
03-12-2007, 06:15 AM
use the "text" property of a text field to set or get the text string.
CardNoHide.text = "************" + CardNumber.text.substring(12, 16);