/src/com/greensock/easing/EaseLookup.as

https://bitbucket.org/HopeSky/mars_nd2d · ActionScript · 69 lines · 36 code · 7 blank · 26 comment · 3 complexity · 072476078d8386e8e6a7d412be2b5db2 MD5 · raw file

  1. package 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. * Finds the easing function associated with a particular name (String), like "strongEaseOut". This can be useful when
  16. * loading in XML data that comes in as Strings but needs to be translated to native function references. You can pass in
  17. * 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>
  18. * EaseLookup.find("Strong.easeOut") <br />
  19. * EaseLookup.find("strongEaseOut") <br />
  20. * EaseLookup.find("strongeaseout") <br /><br /></code>
  21. *
  22. * You can translate Strings directly when tweening, like this: <br /><code>
  23. * TweenLite.to(mc, 1, {x:100, ease:EaseLookup.find(myString)});<br /><br /></code>
  24. *
  25. * @param name The name of the easing function, with or without the period and case insensitive (i.e. "Strong.easeOut" or "strongEaseOut")
  26. * @return The easing function associated with the name
  27. */
  28. public static function find(name:String):Function {
  29. if (_lookup == null) {
  30. buildLookup();
  31. }
  32. return _lookup[name.toLowerCase()];
  33. }
  34. /** @private **/
  35. private static function buildLookup():void {
  36. _lookup = {};
  37. addInOut(Back, ["back"]);
  38. addInOut(Bounce, ["bounce"]);
  39. addInOut(Circ, ["circ", "circular"]);
  40. addInOut(Cubic, ["cubic"]);
  41. addInOut(Elastic, ["elastic"]);
  42. addInOut(Expo, ["expo", "exponential"]);
  43. addInOut(Linear, ["linear"]);
  44. addInOut(Quad, ["quad", "quadratic"]);
  45. addInOut(Quart, ["quart","quartic"]);
  46. addInOut(Quint, ["quint", "quintic", "strong"]);
  47. addInOut(Sine, ["sine"]);
  48. _lookup["linear.easenone"] = _lookup["lineareasenone"] = Linear.easeNone;
  49. }
  50. /** @private **/
  51. private static function addInOut(easeClass:Class, names:Array):void {
  52. var name:String;
  53. var i:int = names.length;
  54. while (i-- > 0) {
  55. name = names[i].toLowerCase();
  56. _lookup[name + ".easein"] = _lookup[name + "easein"] = easeClass.easeIn;
  57. _lookup[name + ".easeout"] = _lookup[name + "easeout"] = easeClass.easeOut;
  58. _lookup[name + ".easeinout"] = _lookup[name + "easeinout"] = easeClass.easeInOut;
  59. }
  60. }
  61. }
  62. }