How to raise or decrease a display number variable in AS3 with a condition?

泄露秘密 提交于 2019-12-13 04:22:10

问题


I've got, in my Toolbar.as class, a simple variable (4-digit number) displayed in a dynamic text box, like that :

var number = 9999; 
useText.text = String(number); 
trace(number);

In my puzzle class I have a condition and I would like to decrease the number if it's true. How can I do that ?

For exemple, I've got, in my Puzzle.as class :

if (inv.containsItem("rock")) {
    toolbar.useText.text = "String(number)" - 100;
    }

But it doesn't work (I know that I have to change the "String(number)" - 100 but what should I put ?

Thx !!!


回答1:


I believe you are attempting to do: String(number - 100);

The is called a wrapper or casting, you are casting the number variable with the operation of - 100 to a String.

If you want to grab the current text in your field and use that:

useText.text = String( Number( useText.text ) - 100 );

This casts the current text to a Number, subtracts 100, then casts it back to a String




回答2:


You have to take the value of toolbar.useText.text, parse it to int, subtract 100 and assign to toolbar.useText.text.



来源:https://stackoverflow.com/questions/21339052/how-to-raise-or-decrease-a-display-number-variable-in-as3-with-a-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!