Java Reference
In-Depth Information
var anim = Timeline{
repeatCount: Timeline.INDEFINITE;
autoReverse: true;
keyFrames: KeyFrame{
time: 2s
values: red => 1.0;
Listing 8-5 shows a Rectangle that has its fill property bound to the function
createLinearGradient , which is a sequence of Stops . The sequence of Stops is composed of a Stop at
offset 0.0 and the color Color.BLUE and a second stop defined by the function createStop . The function
createStop takes a color and an offset . In this case the Color passed to createStop is also defined by the
function createColor , as shown in Listing 8-3. Since LinearGradient , Stop , and Color are immutable
classes, these helper functions must be created to allow us to make new ones during the course of the
animation. Listing 8-6 shows the function createStop , and Listing 8-7 shows the function
createLinearGradient .
Listing 8-6. createStop
public function createStop(color:Color,offset:Number):Stop{
return Stop{
color: color;
offset: zeroToOne(offset)
In Listing 8-6 we see that the function createStop simply creates a new Stop from the parameters
passed in. Again, the function zeroToOne from Listing 8-4 is used to normalize the offset .
Listing 8-7. createLinearGradient+
public function createLinearGradient(stops:Stop[]):LinearGradient{
return LinearGradient{
startX: 0
endX: 1
startY: 0
endY: 0
proportional: true
stops: sortStops(stops);
Listing 8-7 shows the function createLinearGradient , which creates a LinearGradient from the
Stops passed in. The Stops are first sorted to make sure they are in the correct order. When defining an
animation where the offset values can change, it is good to know they will be sorted before being used
to create a new LinearGradient , as LinearGradient will throw an exception if the Stops are in the wrong
Search WWH ::

Custom Search