Java Reference
In-Depth Information
order. Listing 8-8 shows the function sortStops . It should also be noted that the LinearGradient created
has proportional set to true , making it quick to show the gradient for example purposes. A later example
will use a LinearGradient with proportional set to false . This is often desirable, as it allows you to
specify exactly which part of the shape has the gradient applied to it.
Listing 8-8. sortStops
public function sortStops(stops:Stop[]):Stop[]{
var result:Stop[] = Sequences.sort(stops, Comparator{
public override function compare(obj1:Object, obj2: Object):Integer{
var stop1 = (obj1 as Stop);
var stop2 = (obj2 as Stop);
if (stop1.offset > stop2.offset){
return 1;
} else if (stop1.offset < stop2.offset){
return -1;
} else {
return 0;
}) as Stop[];
return result
Listing 8-8 shows the function sortStops , which takes a sequence of stops and returns a sorted
Sequence . To sort the Sequence , a Comparator is passed to the static function Sequences.sort . The
Comparator simply compares the offset of the two Stops and returns an Integer value indicating if the
first Stop is greater than, equal to, or less than the second Stop . If you are familiar with the Java
Collections API you will recognize this pattern, as the class Sequences is an analog of the class
Collections .
Simple Radial
Animating a RadialGradient is similar to animating a LinearGradient . The differences are minor, but
worth exploring for completeness and to bring home how bind , combined with a function, is used to
create these effects.
Figure 8-4 shows two phases of an animation of a RadialGradient , with the Stop at 0.0 being
changed from black to yellow.
Search WWH ::

Custom Search