]> git.mjollnir.org Git - moodle.git/blob
4370e2c7d39daaf2a0cbc30e392d7a63ad273a71
[moodle.git] /
1 package flare.animate.interpolate
2 {
3         /**
4          * Interpolator for arbitrary <code>Object</code> values. Simply swaps the
5          * initial value for the end value for interpolation fractions greater
6          * than or equal to 0.5.
7          */
8         public class ObjectInterpolator extends Interpolator
9         {
10                 private var _start:Object;
11                 private var _end:Object;
12                 
13                 /**
14                  * Creates a new ObjectInterpolator.
15                  * @param target the object whose property is being interpolated
16                  * @param property the property to interpolate
17                  * @param start the starting object value to interpolate from
18                  * @param end the target object value to interpolate to
19                  */
20                 public function ObjectInterpolator(target:Object, property:String,
21                                                    start:Object, end:Object)
22                 {
23                         super(target, property, start, end);
24                 }
25                 
26                 /**
27                  * Initializes this interpolator.
28                  * @param start the starting value of the interpolation
29                  * @param end the target value of the interpolation
30                  */
31                 protected override function init(start:Object, end:Object) : void
32                 {
33                         _start = start;
34                         _end = end;
35                 }
36                 
37                 /**
38                  * Calculate and set an interpolated property value. This method sets
39                  * the target object's property to the starting value if the
40                  * interpolation fraction is less than 0.5 and to the ending value if
41                  * the fraction is greather than or equal to 0.5.
42                  * @param f the interpolation fraction (typically between 0 and 1)
43                  */
44                 public override function interpolate(f:Number) : void
45                 {
46                         _prop.setValue(_target, f < 0.5 ? _start : _end);
47                 }
48                 
49         } // end of class ObjectInterpolator
50 }