如何在Flash指定的秒数运行一系列的价值? [英] How to run a range of value in specified seconds in Flash?

查看:100
本文介绍了如何在Flash指定的秒数运行一系列的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在规定时间更新值的范围?我是新来的Flash的ActionScript 3。

How do I update a range of values in a specified time? I am new to Flash ActionScript 3.

假设我希望用户看到的值从0到90的4秒,我怎么做,在Flash AS3?这是我的尝试至今:

Assume I want the user to see values from 0 to 90 in 4 seconds, how do I do that in Flash AS3? This is my attempt so far:

var valueRange:Number = 90; //90 different values
var myTimer:Timer = new Timer(1000,valueRange); //should repeat valueRange times
myTimer.addEventListener(TimerEvent.TIMER, rangeFunction); //function
myTimer.start();

function rangeFunction(event:TimerEvent):void {
myText_txt.text = String((-1)+myTimer.currentCount);
}

有关每一秒,该值将​​被更新使得它90秒长。

For every second, the value will be updated making it 90 seconds long.

请好心帮忙,因为这是我的动画基本需求。

Please kindly help, as this is fundamental need for my animations.

推荐答案

您需要扩展自己的价值观一个范围映射到另一个。

You need to scale your values to map one range to the other.

从0到90的4秒,你就会有每秒90/4或22.5值。所以,在你的计时器的每一个刻度,你会由22.5增加从0到去90在4秒。

To go from 0 to 90 in 4 seconds, you'll have 90 / 4 or 22.5 values per second. So on every tick of your timer, you'd increment by 22.5 to go from 0 to 90 in 4 seconds.

这可能看起来并不好,我猜你会preFER看到数字飞逝而过。实现这一点可以使用较小的定时更新间隔的一种方法,说100毫秒,而不是更新每秒一次。由于100毫秒意味着0.1秒,你就会有2.25每100ms的增量值。

This probably doesn't look as good as I'm guessing you'd prefer to see the numbers whiz by. One method of making this happen can be to use a smaller timer update interval, say 100ms instead of updating once every second. Since 100ms means 0.1 second, you'd have an increment value of 2.25 every 100ms.

您可以一路走下来,并制定出一个区间值足够小,你可以加1,但有非常小的区间值可能不是一个定时器件好事。

You could go all the way down and work out an interval value small enough that you can increment by 1, but having really small interval values may not be a good thing for a Timer.

这篇关于如何在Flash指定的秒数运行一系列的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆