|
metadata
Dear Kongregate community.
This might seem like a stupid question, but it really isn’t. I know that integers can’t be null, but fixing it is somewhat of a problem.
Currently I’m trying to make a function that converts the numbers in a textfield to integers, which I managed to do.
Here is the code:
xtimes.addEventListener(TextEvent.TEXT\_INPUT, textInput, false, 0, true);
function textInput(event:TextEvent):void
{
if(xtimes.length = 0) {
var times = 0 ;
trace(times);
} else {
var times = int(xtimes.text) ;
trace(times);
}
}
This code fixes the error, however somehow flash removes the first number fromt the textfield
(For instance: 1 becomes 0 11 becomes 1 111 becomes 11 etc.)
Any help would be appreciated.
P.S. I wish to thank the people that helped me out before, I managed to fix it by not using the point.touch listener but a regular mouse.click listener. I suppose that’ll have to do for now…
|
|
metadata
Try changing
if(xtimes.length = 0) {
to
if(xtimes.length == 0) {
|
|
metadata
^ +1, OP should know that a single equation always means assignment, and will even compile, effectively truncating xtimes.
|
|
metadata
I’m afraid that didn’t cut it. Still the same.
Thanks for the help anyway :3
|
|
metadata
Maybe because time is instantiated within each of the conditional outcomes? also try using the parseInt function.
|
|
metadata
> *Originally posted by **[Senekis](/forums/4/topics/296988?page=1#posts-6360464):***
>
> I took a look at your script and `xtimes` isn’t declared anywhere, but since it compiles, I’m gonna guess you’re using CS or some similar thing.
>
> Also, `TextEvent.TEXT_INPUT` is useless here, since it’s dispatched before the value is modified. Use `Event.CHANGE` instead.
>
> Finally, don’t cast to `int`; use `parseInt()`.
Please stop making threads if you aren’t going to follow the given advice.
You had pretty much the same problem some time ago, I gave you all the answers and now you come with pretty much the same script and wonder why it doesn’t work.
You should learn the basics of the language before trying anything else.
|