Help!: int. can't be null

6 posts

Flag Post

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 ;
} else {
var times = int(xtimes.text) ;

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 listener. I suppose that’ll have to do for now…

Flag Post

Try changing
if(xtimes.length = 0) {
if(xtimes.length == 0) {

Flag Post

^ +1, OP should know that a single equation always means assignment, and will even compile, effectively truncating xtimes.

Flag Post

I’m afraid that didn’t cut it. Still the same.
Thanks for the help anyway :3

Flag Post

Maybe because time is instantiated within each of the conditional outcomes? also try using the parseInt function.

Flag Post
Originally posted by Senekis:

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.