如何提高或在AS3与条件减小显示数字变量?变量、条件、数字

由网友(风带走故事也带走你)分享简介:我有,在我的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...

我有,在我的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

阅读全文

相关推荐

最新文章