-
text variable set
There's a dynamic text box with the variable name "score" in the main Flash area. In a movie clip, there's a button which, when pressed, should make the score variable (which begins at 0) increase by one. So for every press, 1 becomes 2, 2 becomes 3, etc.
I have the code:
on (press) {
_root.score = _root.score+1;
}
However, this just makes the score become 11 instead of 2, 111 instead of 3, etc.
What have I done wrong in the code in order for this to happen?
Thanks for any help.
-
Child Prodigy
What you have to do is use a variable. Increment the variable by one each time, and then give the text box that variable's value like this:
Code:
on (press) {
scoreVar = scoreVar+1;
//This could also be written scoreVar += 1;
_root.score.text = scoreVar;
}
Hope that helps.
Rick
Code:
hobby = webDesign; waitYears(3);
job = webDesign; this.love(job);
-
Senior Member
Here U go!
on (press) {
_root.score = parseInt(_root.score)+1;
_trace (_root.score);
}
Dancing with dynamic
http://www.advance-media.com
-
Child Prodigy
pareInt - I've never used that function. I'm assuming that basically reads the text box and converts it to a variable, right?
Code:
hobby = webDesign; waitYears(3);
job = webDesign; this.love(job);
-
Senior Member
U need to check the FLASH help dictionary more frequently!
parseInt (also look at parseFloat) converts the string to an integer (number) value in order to be able to use it for calculation.
Best wishes
http://www.advance-media.com
-
Child Prodigy
Thanks. I'll do that.
Code:
hobby = webDesign; waitYears(3);
job = webDesign; this.love(job);
-
I dont understand, this worked for me:
on (release) {
score = ((score)+1);
}
-Nick
-
This worked for me too...
on (release) {
score = score+1;
}
Please explain.
-
Because if you refer to the original question in this thread, score in this case is a text string in a textfield, and not an integer.
If you preceded your tests with...
score = "1";
And tried...
on (release) {
score = score+1;
trace(score);
}
The answer won't be what you got!
-
My first frame had
score = 1;
My second frame has a button with:
on (release) {
score = score+1;
}
and a dynamic text field called score.
What am I not understanding....I try to learn from other peoples questions so excuse my persistance as I will excuse your curt response.
-
Ah! but your first frame had...
score = 1;
And not as I had...
score = "1";
Because as I said the variable in a textfield is a text string and not a value! So you must convert that text string into a value if you want to add the value of 1 to it.
score = "1";
trace (score + 1); // outputs "11"
score = 1;
trace (score + 1); // outputs 2
So if score is a text string as it is in this case:
score = "1";
trace (parseInt(score)+1); // now outputs 2
Curt enough for you this time?
-
Ahhhhhhhhhhhhhhh. Oui!
and no...that one wasn't curt at all.
curt
Function: adjective
Etymology: Latin curtus shortened -- more at SHEAR
Date: 1630
1 a : sparing of words : TERSE b : marked by rude or peremptory shortness : BRUSQUE
2 : shortened in linear dimension
-
Yeah! Looked it up before I posted... http://dictionary.reference.com/translate/text.html
But I really ment... "Was I rude enough for you this time?"
-
Huygens to Titan
-
-
I didn't consider you as being rude...
I understand that you are French-Canadian.
It's just your way!
Cheers!
-
I'm a Québecois first. A French-Canadian second, and a Canadian third!
-
Child Prodigy
Originally posted by Cornaglian
...so excuse my persistance as I will excuse your curt response.
LMAO! I don't see how anybody can get any kind of rude / curt vibe from anybody else unless they say something like "F*** YOU!!" or something like that, you know? I mean, this isn't face to face so I find it quite hard to read people. (Then again, I find it hard to read people anyway...)
I always try to take what I get from other people as best I can so I don't misinterpret it and upset someone for no reason.
Just some thoughts
Rick
Code:
hobby = webDesign; waitYears(3);
job = webDesign; this.love(job);
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
|