《Flash Lite 2.x ActionScript 语言参考》 |
|
|
|
| ActionScript 语言元素 > 全局函数 > Number 函数 | |||
Number(expression) : Number
将参数 expression 转换为数字,并返回下面列表中说明的值:
true 时,返回值为 1;当 expression 为 false 时,返回值为 0。NaN,则返回值为 NaN。undefined,则返回值如下所示:在为 Flash Player 6 或更低版本发布的文件中,结果为 0。在为 Flash Player 7 或更高版本发布的文件中,结果为 NaN。expression:Object ― 要转换为数字的表达式。以 0x 开头的数字或字符串被解释为十六进制值。以 0 开头的数字或字符串被解释为八进制值。
Number ― 一个数字或 NaN(非数字)。
在下面的示例中,将在运行时在舞台上创建一个文本字段:
this.createTextField("counter_txt", this.getNextHighestDepth(), 0, 0, 100, 22);
counter_txt.autoSize = true;
counter_txt.text = 0;
function incrementInterval():Void {
var counter:Number = counter_txt.text;
// Without the Number() function, Flash would concatenate the value instead
// of adding values. You could also use "counter_txt.text++;"
counter_txt.text = Number(counter) + 1;
}
var intervalID:Number = setInterval(incrementInterval, 1000);
NaN 常数, Number, parseInt 函数, parseFloat 函数
|
|
|
|