Java Reference
In-Depth Information
there were two time literals, 0ms , zero milliseconds, and 10s , for ten seconds. To
declare a time literal, use a number followed by a time unit. The possible units of
time are ms for milliseconds, s for seconds, m for minutes, and h for hours. The
number may be either an integer or a decimal number. For example, 1500ms is
equal to 1.5s.
You can also do arithmetic functions on time literals. For example:
println(2h + 30m + 3s + 10ms); // 9003010.0ms
println(1m - 30s);
//
30000.0ms
println(10ms * 2);
//
20.0ms
println(10ms / 2);
//
5.0ms
Duration objects are immutable, so they cannot be changed once created. In the
preceding examples, each time literal argument within the arithmetic expression
represents a distinct Duration instance and another distinct instance represents
the result.
Besides using the time literals as shown here, you can also create Duration
objects using the function valueOf() , passing in milliseconds as the parameter.
The following all equal a duration of 10 seconds:
var duration = Duration.valueOf(10000);
var duration = 10000ms;
var duration = 10s;
var duration = 0.166666m; // approximates 10 seconds
Sometimes, it is useful to declare a Duration object that can later be bound
within an expression. This is useful if you want to dynamically change the time
of the timeline. Perhaps you want to allow the user to change the animation from
5 seconds to 15 seconds. When doing this within a timeline, this duration object
is automatically bound. This is illustrated in Listing 7.2.
Listing 7.2
Duration Variable
public var duration = 10s;
var x:Number;
var y:Number;
var timeline = Timeline {
keyFrames : [
// at 0 milli seconds, set x/y to initial value
at(0ms) {
x => 0;
y => 0;
},
Search WWH ::




Custom Search