DisplayShortcuts.as 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. package caurina.transitions.properties {
  2. /**
  3. * properties.DisplayShortcuts.as
  4. * List of default special MovieClip properties (normal and splitter properties) for the Tweener class
  5. * The function names are strange/inverted because it makes for easier debugging (alphabetic order). They're only for internal use (on this class) anyways.
  6. *
  7. * @author Zeh Fernando, Nate Chatellier, Arthur Debert
  8. * @version 1.0.0
  9. */
  10. import flash.geom.Point;
  11. import flash.geom.Rectangle;
  12. import caurina.transitions.Tweener;
  13. public class DisplayShortcuts {
  14. /**
  15. * There's no constructor.
  16. */
  17. public function DisplayShortcuts () {
  18. trace ("This is an static class and should not be instantiated.")
  19. }
  20. /**
  21. * Registers all the special properties to the Tweener class, so the Tweener knows what to do with them.
  22. */
  23. public static function init(): void {
  24. // Normal properties
  25. Tweener.registerSpecialProperty("_frame", _frame_get, _frame_set);
  26. Tweener.registerSpecialProperty("_autoAlpha", _autoAlpha_get, _autoAlpha_set);
  27. // Scale splitter properties
  28. Tweener.registerSpecialPropertySplitter("_scale", _scale_splitter);
  29. // scrollRect splitter properties
  30. Tweener.registerSpecialPropertySplitter("_scrollRect", _scrollRect_splitter);
  31. // scrollrect normal properties
  32. Tweener.registerSpecialProperty("_scrollRect_x", _scrollRect_property_get, _scrollRect_property_set, ["x"]);
  33. Tweener.registerSpecialProperty("_scrollRect_y", _scrollRect_property_get, _scrollRect_property_set, ["y"]);
  34. Tweener.registerSpecialProperty("_scrollRect_left", _scrollRect_property_get, _scrollRect_property_set, ["left"]);
  35. Tweener.registerSpecialProperty("_scrollRect_right", _scrollRect_property_get, _scrollRect_property_set, ["right"]);
  36. Tweener.registerSpecialProperty("_scrollRect_top", _scrollRect_property_get, _scrollRect_property_set, ["top"]);
  37. Tweener.registerSpecialProperty("_scrollRect_bottom", _scrollRect_property_get, _scrollRect_property_set, ["bottom"]);
  38. Tweener.registerSpecialProperty("_scrollRect_width", _scrollRect_property_get, _scrollRect_property_set, ["width"]);
  39. Tweener.registerSpecialProperty("_scrollRect_height", _scrollRect_property_get, _scrollRect_property_set, ["height"]);
  40. }
  41. // ==================================================================================================================================
  42. // PROPERTY GROUPING/SPLITTING functions --------------------------------------------------------------------------------------------
  43. // ----------------------------------------------------------------------------------------------------------------------------------
  44. // scale
  45. public static function _scale_splitter(p_value:Number, p_parameters:Array) : Array{
  46. var nArray:Array = new Array();
  47. nArray.push({name:"scaleX", value: p_value});
  48. nArray.push({name:"scaleY", value: p_value});
  49. return nArray;
  50. }
  51. // ----------------------------------------------------------------------------------------------------------------------------------
  52. // _scrollRect
  53. /**
  54. * Splits the _scrollRect parameter into specific scrollRect variables
  55. *
  56. * @param p_value Rectangle The original _scrollRect rectangle
  57. * @return Array An array containing the .name and .value of all new properties
  58. */
  59. public static function _scrollRect_splitter (p_value:Rectangle, p_parameters:Array, p_extra:Object = null):Array {
  60. var nArray:Array = new Array();
  61. if (p_value == null) {
  62. // No parameter passed, so try any rectangle :/
  63. nArray.push({name:"_scrollRect_x", value:0});
  64. nArray.push({name:"_scrollRect_y", value:0});
  65. nArray.push({name:"_scrollRect_width", value:100});
  66. nArray.push({name:"_scrollRect_height", value:100});
  67. } else {
  68. // A rectangle is passed, so just return the properties
  69. nArray.push({name:"_scrollRect_x", value:p_value.x});
  70. nArray.push({name:"_scrollRect_y", value:p_value.y});
  71. nArray.push({name:"_scrollRect_width", value:p_value.width});
  72. nArray.push({name:"_scrollRect_height", value:p_value.height});
  73. }
  74. return nArray;
  75. }
  76. // ==================================================================================================================================
  77. // NORMAL SPECIAL PROPERTY functions ------------------------------------------------------------------------------------------------
  78. // ----------------------------------------------------------------------------------------------------------------------------------
  79. // _frame
  80. /**
  81. * Returns the current frame number from the movieclip timeline
  82. *
  83. * @param p_obj Object MovieClip object
  84. * @return Number The current frame
  85. */
  86. public static function _frame_get (p_obj:Object, p_parameters:Array, p_extra:Object = null):Number {
  87. return p_obj.currentFrame;
  88. }
  89. /**
  90. * Sets the timeline frame
  91. *
  92. * @param p_obj Object MovieClip object
  93. * @param p_value Number New frame number
  94. */
  95. public static function _frame_set (p_obj:Object, p_value:Number, p_parameters:Array, p_extra:Object = null): void {
  96. p_obj.gotoAndStop(Math.round(p_value));
  97. }
  98. // ----------------------------------------------------------------------------------------------------------------------------------
  99. // _autoAlpha
  100. /**
  101. * Returns the current alpha
  102. *
  103. * @param p_obj Object MovieClip or Textfield object
  104. * @return Number The current alpha
  105. */
  106. public static function _autoAlpha_get (p_obj:Object, p_parameters:Array, p_extra:Object = null):Number {
  107. return p_obj.alpha;
  108. }
  109. /**
  110. * Sets the current autoAlpha
  111. *
  112. * @param p_obj Object MovieClip or Textfield object
  113. * @param p_value Number New alpha
  114. */
  115. public static function _autoAlpha_set (p_obj:Object, p_value:Number, p_parameters:Array, p_extra:Object = null): void {
  116. p_obj.alpha = p_value;
  117. p_obj.visible = p_value > 0;
  118. }
  119. // ----------------------------------------------------------------------------------------------------------------------------------
  120. // _scrollRect_*
  121. /**
  122. * _scrollRect_*
  123. * Generic function for the properties of the scrollRect object
  124. */
  125. public static function _scrollRect_property_get (p_obj:Object, p_parameters:Array, p_extra:Object = null):Number {
  126. return p_obj.scrollRect[p_parameters[0]];
  127. }
  128. public static function _scrollRect_property_set (p_obj:Object, p_value:Number, p_parameters:Array, p_extra:Object = null): void {
  129. var rect:Rectangle = p_obj.scrollRect;
  130. rect[p_parameters[0]] = Math.round(p_value);
  131. p_obj.scrollRect = rect;
  132. }
  133. }
  134. }