|
-
Hey people
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.
Any way around this???
fla is here http://www.cplicious.com/laptimer/
Chris
-
First, 'var' is a reserved word in Flash, so don't use it as a variable name - Flash doesn't like it Use myVar or something.
Use:
Code:
myVar = Number(myVar);
to get the integer back.
-
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.
Anyone know how to get around this?
-
Aaargh!
What did I just say?
If you run this code as an example:
Code:
myVar="00000001";
myVar = Number(myVar);
You agree that '00000001' is a string in this case, yes?
Well this code returns:
<debug output>
Level #0:
Variable _level0.$version = "WIN 5,0,30,0"
Variable _level0.myVar = 1
</debug output>
Now, is myVar reported back as an integer or a string in that example?
-
yeah fair enough but your missing my point
I want to display numbers 1-9 and 01 - 09 etc.
now if I do it your way they become 1-9
so how do I get a ZERO in front with out it becoming a text variable.
-
Noooo! 
I think you're missing my point.
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.
-
no your missing MY point
Just look at my fla and see if u can get it to work
I want myvar to be considered as a number not a string.
However when I use the
myvar = "0" + myvar
it becomes a string. If I use the myvar = Number(myvar) it changes from 01 to 1.... so it kills the whole putting the 0 infront of it!!
-
half as fun, double the price
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.
labelNum = 01 // reduces to 1
tempNum = (labelNum < 10) ? "0"+labelNum : labelNum
gotoAndPlay("frame" + tempNum)
Same with something like your stop watch where you may need to display it on screen with the preceeding zero
seconds = 4
secsTextField = (seconds <10) ? "0" + seconds : seconds
does that help any?
-
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.
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
|