1 package flare.animate.interpolate
3 import flare.util.Arrays;
6 * Interpolator for numeric <code>Array</code> values. Each value
7 * contained in the array should be a numeric (<code>Number</code> or
8 * <code>int</code>) value.
10 public class ArrayInterpolator extends Interpolator
12 private var _start:Array;
13 private var _end:Array;
14 private var _cur:Array;
17 * Creates a new ArrayInterpolator.
18 * @param target the object whose property is being interpolated
19 * @param property the property to interpolate
20 * @param start the starting array of values to interpolate from
21 * @param end the target array to interpolate to. This should be an
22 * array of numerical values.
24 public function ArrayInterpolator(target:Object, property:String,
25 start:Object, end:Object)
27 super(target, property, start, end);
31 * Initializes this interpolator.
32 * @param start the starting value of the interpolation
33 * @param end the target value of the interpolation
35 protected override function init(start:Object, end:Object) : void
37 _start = start as Array;
40 if (!_end) throw new Error("Target array is null!");
41 if (!_start) _start = Arrays.copy(_end);
42 if (_start.length != _end.length)
43 throw new Error("Array dimensions don't match");
45 if (_cur == null || _cur == _start || _cur == _end) {
46 _cur = Arrays.copy(_start);
48 _cur = Arrays.copy(_start, _cur);
53 * Calculate and set an interpolated property value.
54 * @param f the interpolation fraction (typically between 0 and 1)
56 public override function interpolate(f:Number) : void
58 for (var i:uint=0; i<_cur.length; ++i) {
59 _cur[i] = _start[i] + f*(_end[i] - _start[i]);
61 _prop.setValue(_target, _cur);
64 } // end of class ArrayInterpolator