Skip to main content
January 27, 2011
Question

adding and subtracting from a number within a text box AS3

  • January 27, 2011
  • 1 reply
  • 1008 views

Hi there,

I imagine this to be a simple question, but I don't seem to be able to figure it out being knee deep in code !!

I have this variable :-

var blackCredit = creditBlack.text;

When I try to add or subtract 1 from the amount in the text box, like this :-

blackCredit += 1;

and then update the text box with the new value :-

creditBlack.text = blackCredit;

It's adding the 1 to the end. i.e. 16 becomes 161, instead of 17..

Thanks for your help guys and sorry for the dumb question !!!

Martin

This topic has been closed for replies.

1 reply

Kenneth Kawamoto
Community Expert
Community Expert
January 27, 2011

You need to convert String to an integer before applying arithmetic operations, i.e.

parseInt(creditBlack.text)

January 27, 2011

great when I've created blackCredit I've simply changed it to

var blackCredit = parseInt(gamePage.blackPot.creditBlack.text);

Seems to work great.. so now to get to my next problem

Thanks for your help