how (AS Q)
- Started
- Last post
- 24 Responses
- stewart
*&@#$, i left my actionscript book at home.
is there a way to convert the content of a dynamic textfield (if it is "4" for example, to the number 4?
because i want to put that value into an if-statement like this:
textfield == 4) {
gotoAndPlay(2);
}but when i do it like this, the content of the dynamic textfield is set to "4" (!)
- SteveJobs0
Number(4)
- stewart0
that easy.
i'll give it a try.
- stewart0
nope
- stewart0
parseFloat ?
- SteveJobs0
or just check it against =="4" since that's how the textfield is probably evaluating it anyway.
- SteveJobs0
should work:
Number(txtFld.text)==Number(4)
or
txtFld.text=="4"
- stewart0
well Jobs, that's my problem.
also with if ( textfield =="4" ) the value of the textfield is set to "4" instead of comparing it...
- CyBrainX0
Try: gotoAndPlay([textfield]);
- fugged0
use parseInt()
a = "3"
b = parseFloat(a)+1;
trace(b);output: 4.
>>also with if ( textfield =="4" ) the value of the textfield is set to "4" instead of comparing it...
shouldn't be if you are using == and not =. a single = causes an assignment where == and === are for evaluating an expression.
- Kuz0
shouldn't it be
if (textfield = 4) {
gotoAndPlay(2)
}??
- fugged0
mmm. need more coffee...
in my a/b example I meant to use parseInt. not parseFloat.
sorry.
- SteveJobs0
carefull with parseInt, it will truncate your decimals.
- unfittoprint0
parseFloat dat motherfucker!%"#"#
http://www.ourfamilynet.ws/forum…
b.i.a.t.c.h
- stewart0
uh
Steve,when i trace your
Number(this.textfield.text)
it results in 0but it displays "4"
weird.
i only want to be able to change a variable in an external .txt document, to use that variable in an if statement.
- JamesEngage0
parseInt always works for me... especially if yopu're reading from a text file... and there may be a line break after the 4 ?
- SteveJobs0
yeah, parseFloat would be fine too, but i wouldn't use parseInt.
- stewart0
okay, here it is and it works.
http://pastebin.coconut.se/?id=3…thanks again!
- SteveJobs0
shorthand:
- stewart0
thanks for the shorthand Steve.
but can you please explain the last part
"?0:1"
- SteveJobs0
it's a conditional operator
if the expression before the question mark is true, then the operand to the left of the colon is evaluation. adversely, if the expression is false, then the operand to the right of the colon is evaluated.