source: Collectif_Otra/global.reflet-web.net/lib/reflet_swf_dependances/fl/motion/FunctionEase.as @ 2824

Last change on this file since 2824 was 2824, checked in by kent1, 10 years ago

Les librairies qui sont dans Flash CS4

  • Property svn:executable set to *
File size: 5.0 KB
Line 
1// Copyright © 2007. Adobe Systems Incorporated. All Rights Reserved.
2package fl.motion
3{
4import flash.utils.*;
5
6/**
7 * The FunctionEase class allows custom interpolation functions to be used with
8 * the fl.motion framework in place of other interpolations like SimpleEase and CustomEase.
9 * The fl.motion framework includes several easing functions in the fl.motion.easing package.
10 *   
11 * @playerversion Flash 9.0.28.0
12 * @langversion 3.0
13 * @keyword Ease, Copy Motion as ActionScript   
14 * @includeExample examples\FunctionEaseExample.as -noswf
15 * @see ../../motionXSD.html Motion XML Elements
16 * @see fl.motion.easing
17 */ 
18public class FunctionEase implements ITween
19{
20    /**
21     * @private
22     */
23        private var _functionName:String = '';
24
25    /**
26     * The fully qualified name of an easing function, such as <code>fl.motion.easing.Bounce.easeOut()</code>.
27     * The function must be a method of a class (Bounce, Cubic, Elastic, another class).
28     * If Flash Player cannot find the class, an exception is thrown.
29     * @playerversion Flash 9.0.28.0
30     * @langversion 3.0
31     * @keyword Easing, Copy Motion as ActionScript   
32     * @see fl.motion.easing
33     */
34        public function get functionName():String
35        {
36                return this._functionName;
37        }
38
39    /**
40     * @private (setter)
41     */
42        public function set functionName(newName:String):void
43        { 
44                var parts:Array = newName.split('.');
45                var methodName:String = parts.pop();
46                var className:String = parts.join('.');
47                // This will generate an exception if the class cannot be found.
48                var theClass:Class = getDefinitionByName(className) as Class;
49                if (theClass[methodName] is Function)
50                {
51                        this.easingFunction = theClass[methodName];
52                        this._functionName = newName;
53                }                       
54        }
55
56
57
58    /**
59     * A reference to a function with a <code>(t, b, c, d)</code> signature like
60     * the methods in the fl.motion.easing classes.
61     * @playerversion Flash 9.0.28.0
62     * @langversion 3.0
63     * @keyword Easing, Copy Motion as ActionScript   
64     * @see fl.motion.easing     
65     */
66        public var easingFunction:Function = null;
67
68        /**
69         * An optional array of values to be passed to the easing function as additional arguments.
70     * @playerversion Flash 9.0.28.0
71     * @langversion 3.0
72     * @keyword Easing, Copy Motion as ActionScript   
73         */
74        public var parameters:Array = null;
75
76    /**
77     * @private
78     */
79        private var _target:String = '';
80
81    /**
82     * The name of the animation property to target.
83     * @playerversion Flash 9.0.28.0
84     * @langversion 3.0
85     * @keyword Easing, Copy Motion as ActionScript   
86     * @see fl.motion.ITween#target
87     */
88        public function get target():String
89        {
90                return this._target;
91        }
92
93    /**
94     * @private (setter)
95     */
96        public function set target(value:String):void
97        {
98                this._target = value;
99        }
100
101
102
103    /**
104     * Constructor for FunctionEase instances.
105     *
106     * @param xml An optional E4X XML instance.
107     * @playerversion Flash 9.0.28.0
108     * @langversion 3.0
109     * @keyword Easing, Copy Motion as ActionScript 
110     * @see ../../motionXSD.html Motion XML Elements
111     */
112        function FunctionEase(xml:XML=null)
113        {
114                this.parseXML(xml);
115        }
116
117
118
119    /**
120     * @private
121     */ 
122        private function parseXML(xml:XML=null):FunctionEase
123        {
124                if (!xml) return this;
125               
126                if (xml.@functionName.length())
127                        this.functionName = xml.@functionName;
128                if (xml.@target.length())
129                        this.target = xml.@target;
130                return this;
131        }
132
133
134
135    /**
136     * Calculates an interpolated value for a numerical property of animation,
137     * using the specified easing function.
138     * If the <code>parameters</code> array has been set beforehand,
139     * those values will be passed to the easing function in addition to the
140     * time, begin, change, and duration values.
141     *
142     * @param time The time value, which must lie between <code>0</code> and <code>duration</code>, inclusive.
143     * You can choose any unit (for example, frames, seconds, milliseconds),
144     * but your choice must match the <code>duration</code> unit.
145         *
146     * @param begin The value of the animation property at the start of the tween, when time is 0.
147     *
148     * @param change The change in the value of the animation property over the course of the tween.
149     * The value can be positive or negative. For example, if an object rotates from 90 to 60 degrees, the <code>change</code> is -30.
150     *
151     * @param duration The length of time for the tween. Must be greater than zero.
152     * You can choose any unit (for example, frames, seconds, milliseconds),
153     * but your choice must match the <code>time</code> unit.
154     *
155     * @return The interpolated value at the specified time.
156     * @playerversion Flash 9.0.28.0
157     * @langversion 3.0
158     * @keyword Easing, Copy Motion as ActionScript   
159     */
160        public function getValue(time:Number, begin:Number, change:Number, duration:Number):Number
161        {
162                if (this.parameters is Array)
163                {
164                        var args:Array = [time, begin, change, duration].concat(this.parameters);
165                        return this.easingFunction.apply(null, args);
166                }
167               
168                return this.easingFunction(time, begin, change, duration);
169        }
170
171       
172}
173}
Note: See TracBrowser for help on using the repository browser.