如何提高或在AS3与条件减小显示数字变量? [英] How to raise or decrease a display number variable in AS3 with a condition ?
问题描述
我有,在我的Toolbar.as类,一个简单的变量(4位数字)显示在一个动态文本框,这样的:
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 ?
有关为例,我有,在我Puzzle.as类:
For exemple, I've got, in my Puzzle.as class :
if (inv.containsItem("rock")) {
toolbar.useText.text = "String(number)" - 100;
}
但它不工作(我知道,我必须要改变的字符串(数字) - 100,但前人的精力是什么我把
But it doesn't work (I know that I have to change the "String(number)" - 100 but what sould I put ?
THX!
推荐答案
我相信你正在尝试做的:字符串(数字 - 100);
I believe you are attempting to do: String(number - 100);
在被称为包装或浇铸,你是铸造数变量,操作 - 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 );
这蒙上当前文本到数
,减去100,然后将其转换回字符串
This casts the current text to a Number
, subtracts 100, then casts it back to a String
这篇关于如何提高或在AS3与条件减小显示数字变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!