Making a trial stop watch laptimer thingy and I am having trouble getting a zero to show up infront of my variables when the amount is less then 10. I want 1-9 to show up as 01, 02, 03...etc. I have tried using
if (var < 10){
var = "0" + var;
}
but that makes the variable become a text value instead of an integer. So when my counter adds 1 to the value I get 0111111 instead of 01, 02, 03, 04, etc.
yeah I know... I was just using it as an example. Still doens't help me. I think I need to tell flash that the variable is a number and not a text value. But if I add a zero on the front it becomes a text variable not a numerical one.
If myVar = 1, then "0" + myVar will become "01". A string.
That is what you wanted, wasn't it? However, you also want to use it as a number.
Obviously, "01" is not a number, so if you want to use it as such you have to convert it using 'Number(string)'.
If you mean 'is there any way "01" can be a number at the same time as being a string' the answer is no. You have to use that simple conversion - that's why 'Number' is there.
oh Sualdam Sometimes people just dont get you do they?
cp, you can NOT have a number with a preceeding "0". Reason being, 01 numerically is the same as 1 therefore flash treats it as a 1. Saying
myVar = 01
to flash means
myVar = 1
however, should you need that preceeding one, you would have to do so within a string.
Say for example you have a bunch of frame labels from
"frame01" to "frame20" and you need that number to keep track of them, then what you would have to do is add the "0" when you need to define the frame label and not while in the variable of the number itself.
ah cool thanks senocular it all makes sence now and I got it working. I figured I might have to do it that way but was not sure if there was some other way around it. Cheers and thanks again.