/src/com/greensock/easing/EaseLookup.as
ActionScript | 69 lines | 36 code | 7 blank | 26 comment | 3 complexity | 072476078d8386e8e6a7d412be2b5db2 MD5 | raw file
1package com.greensock.easing {
2/**
3 * EaseLookup enables you to find the easing function associated with a particular name (String),
4 * like "strongEaseOut" which can be useful when loading in XML data that comes in as Strings but
5 * needs to be translated to native function references.
6 *
7 * <b>Copyright 2011, GreenSock. All rights reserved.</b> This work is subject to the terms in <a href="http://www.greensock.com/terms_of_use.html">http://www.greensock.com/terms_of_use.html</a> or for corporate Club GreenSock members, the software agreement that was issued with the corporate membership.
8 *
9 * @author Jack Doyle, jack@greensock.com
10 */
11 public class EaseLookup {
12 /** @private **/
13 private static var _lookup:Object;
14
15 /**
16 * Finds the easing function associated with a particular name (String), like "strongEaseOut". This can be useful when
17 * loading in XML data that comes in as Strings but needs to be translated to native function references. You can pass in
18 * the name with or without the period, and it is case insensitive, so any of the following will find the Strong.easeOut function: <br /><br /><code>
19 * EaseLookup.find("Strong.easeOut") <br />
20 * EaseLookup.find("strongEaseOut") <br />
21 * EaseLookup.find("strongeaseout") <br /><br /></code>
22 *
23 * You can translate Strings directly when tweening, like this: <br /><code>
24 * TweenLite.to(mc, 1, {x:100, ease:EaseLookup.find(myString)});<br /><br /></code>
25 *
26 * @param name The name of the easing function, with or without the period and case insensitive (i.e. "Strong.easeOut" or "strongEaseOut")
27 * @return The easing function associated with the name
28 */
29 public static function find(name:String):Function {
30 if (_lookup == null) {
31 buildLookup();
32 }
33 return _lookup[name.toLowerCase()];
34 }
35
36 /** @private **/
37 private static function buildLookup():void {
38 _lookup = {};
39
40 addInOut(Back, ["back"]);
41 addInOut(Bounce, ["bounce"]);
42 addInOut(Circ, ["circ", "circular"]);
43 addInOut(Cubic, ["cubic"]);
44 addInOut(Elastic, ["elastic"]);
45 addInOut(Expo, ["expo", "exponential"]);
46 addInOut(Linear, ["linear"]);
47 addInOut(Quad, ["quad", "quadratic"]);
48 addInOut(Quart, ["quart","quartic"]);
49 addInOut(Quint, ["quint", "quintic", "strong"]);
50 addInOut(Sine, ["sine"]);
51
52 _lookup["linear.easenone"] = _lookup["lineareasenone"] = Linear.easeNone;
53 }
54
55 /** @private **/
56 private static function addInOut(easeClass:Class, names:Array):void {
57 var name:String;
58 var i:int = names.length;
59 while (i-- > 0) {
60 name = names[i].toLowerCase();
61 _lookup[name + ".easein"] = _lookup[name + "easein"] = easeClass.easeIn;
62 _lookup[name + ".easeout"] = _lookup[name + "easeout"] = easeClass.easeOut;
63 _lookup[name + ".easeinout"] = _lookup[name + "easeinout"] = easeClass.easeInOut;
64 }
65 }
66
67
68 }
69}