Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

adding and subtracting from a number within a text box AS3

Guest
Jan 27, 2011 Jan 27, 2011

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

TOPICS
ActionScript
993
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 27, 2011 Jan 27, 2011

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

parseInt(creditBlack.text)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 27, 2011 Jan 27, 2011
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines