Java Reference
In-Depth Information
Listing 12.8
Fader.fx - timeline
var
timeline
= Timeline {
keyFrames: [
KeyFrame {
time: 0s
values: [
opacity => 0,
scale => startScale,
]
action: function() {
if(not show) { visible = false; }
}
},
KeyFrame {
time: duration
values: [
opacity => 1.0 tween interpolator,
scale => endScale tween interpolator,
]
},
]
};
The fade function merely controls the playing of the timeline based on the
options chosen. If the fade type is either
IN
or
BOTH
and
show
is set to true, then
the timeline will play forward from the start. On the other hand, if the fade type
is
OUT
or
BOTH
and
show
is set to false, the timeline will play in reverse from the
end. Listing 12.9 illustrates how to control the fade animation.
Listing 12.9
Fader.fx - fade
function fade() {
if(show and (type == FadeType.IN or
type == FadeType.BOTH )) {
timeline.rate = 1.0; // play forward
// start from beginning
timeline.playFromStart();
}else if( not show and ( type == FadeType.OUT or
type == FadeType.BOTH ) ) {
timeline.rate = -1.0; // play in reverse
timeline.time = duration; // start at end
timeline.play();
}
}
Search WWH ::
Custom Search