TextShortcuts.as 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. package caurina.transitions.properties {
  2. /**
  3. * properties.TextShortcuts
  4. * Special properties for the Tweener class to handle MovieClip filters
  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 caurina.transitions.Tweener;
  11. import caurina.transitions.AuxFunctions;
  12. import flash.text.TextFormat;
  13. public class TextShortcuts {
  14. /**
  15. * There's no constructor.
  16. */
  17. public function TextShortcuts () {
  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("_text", _text_get, _text_set, null, _text_preProcess);
  26. // Tweener.registerSpecialPropertyModifier("_text", _text_modifier, _text_get);
  27. // TextFormat-based properties
  28. Tweener.registerSpecialPropertySplitter("_text_color", _generic_color_splitter, ["_text_color_r", "_text_color_g", "_text_color_b"]);
  29. Tweener.registerSpecialProperty("_text_color_r", _textFormat_property_get, _textFormat_property_set, ["color", true, "r"]);
  30. Tweener.registerSpecialProperty("_text_color_g", _textFormat_property_get, _textFormat_property_set, ["color", true, "g"]);
  31. Tweener.registerSpecialProperty("_text_color_b", _textFormat_property_get, _textFormat_property_set, ["color", true, "b"]);
  32. Tweener.registerSpecialProperty("_text_indent", _textFormat_property_get, _textFormat_property_set, ["indent"]);
  33. Tweener.registerSpecialProperty("_text_leading", _textFormat_property_get, _textFormat_property_set, ["leading"]);
  34. Tweener.registerSpecialProperty("_text_leftMargin", _textFormat_property_get, _textFormat_property_set, ["leftMargin"]);
  35. Tweener.registerSpecialProperty("_text_letterSpacing", _textFormat_property_get, _textFormat_property_set, ["letterSpacing"]);
  36. Tweener.registerSpecialProperty("_text_rightMargin", _textFormat_property_get, _textFormat_property_set, ["rightMargin"]);
  37. Tweener.registerSpecialProperty("_text_size", _textFormat_property_get, _textFormat_property_set, ["size"]);
  38. }
  39. // ==================================================================================================================================
  40. // NORMAL SPECIAL PROPERTY functions ------------------------------------------------------------------------------------------------
  41. // ----------------------------------------------------------------------------------------------------------------------------------
  42. // _text
  43. /**
  44. * Returns the current frame number from the movieclip timeline
  45. *
  46. * @param p_obj Object MovieClip object
  47. * @return Number The current frame
  48. */
  49. public static function _text_get (p_obj:Object, p_parameters:Array, p_extra:Object = null):Number {
  50. //return p_obj._currentFrame;
  51. return -p_obj.text.length;
  52. }
  53. /**
  54. * Sets the timeline frame
  55. *
  56. * @param p_obj Object MovieClip object
  57. * @param p_value Number New frame number
  58. */
  59. public static function _text_set (p_obj:Object, p_value:Number, p_parameters:Array, p_extra:Object = null): void {
  60. //p_obj.gotoAndStop(Math.round(p_value));
  61. //p_obj.text =
  62. if (p_value < 0) {
  63. // Old text
  64. p_obj.text = p_extra.oldText.substr(0, -Math.round(p_value));
  65. } else {
  66. // New text
  67. p_obj.text = p_extra.newText.substr(0, Math.round(p_value));
  68. }
  69. }
  70. public static function _text_preProcess (p_obj:Object, p_parameters:Array, p_originalValueComplete:Object, p_extra:Object): Number {
  71. p_extra.oldText = p_obj.text;
  72. p_extra.newText = p_originalValueComplete;
  73. return p_extra.newText.length;
  74. }
  75. // ==================================================================================================================================
  76. // PROPERTY GROUPING/SPLITTING functions --------------------------------------------------------------------------------------------
  77. // ----------------------------------------------------------------------------------------------------------------------------------
  78. // generic splitters
  79. /**
  80. * A generic color splitter - from 0xrrggbb to r, g, b with the name of the parameters passed
  81. *
  82. * @param p_value Number The original _color value
  83. * @return Array An array containing the .name and .value of all new properties
  84. */
  85. public static function _generic_color_splitter (p_value:Number, p_parameters:Array):Array {
  86. var nArray:Array = new Array();
  87. nArray.push({name:p_parameters[0], value:AuxFunctions.numberToR(p_value)});
  88. nArray.push({name:p_parameters[1], value:AuxFunctions.numberToG(p_value)});
  89. nArray.push({name:p_parameters[2], value:AuxFunctions.numberToB(p_value)});
  90. return nArray;
  91. }
  92. // ==================================================================================================================================
  93. // NORMAL SPECIAL PROPERTY functions ------------------------------------------------------------------------------------------------
  94. /**
  95. * Generic function for the textformat properties
  96. */
  97. public static function _textFormat_property_get (p_obj:Object, p_parameters:Array, p_extra:Object = null):Number {
  98. var fmt:TextFormat = p_obj.getTextFormat();
  99. var propertyName:String = p_parameters[0];
  100. var isColor:Boolean = p_parameters[1];
  101. if (!isColor) {
  102. // Standard property
  103. return (fmt[propertyName]);
  104. } else {
  105. // Composite, color channel
  106. var colorComponent:String = p_parameters[2];
  107. if (colorComponent == "r") return AuxFunctions.numberToR(fmt[propertyName]);
  108. if (colorComponent == "g") return AuxFunctions.numberToG(fmt[propertyName]);
  109. if (colorComponent == "b") return AuxFunctions.numberToB(fmt[propertyName]);
  110. }
  111. return NaN;
  112. }
  113. public static function _textFormat_property_set (p_obj:Object, p_value:Number, p_parameters:Array, p_extra:Object = null): void {
  114. var fmt:TextFormat = p_obj.getTextFormat();
  115. var propertyName:String = p_parameters[0];
  116. var isColor:Boolean = p_parameters[1];
  117. if (!isColor) {
  118. // Standard property
  119. fmt[propertyName] = p_value;
  120. } else {
  121. // Composite, color channel
  122. var colorComponent:String = p_parameters[2];
  123. if (colorComponent == "r") fmt[propertyName] = (fmt[propertyName] & 0xffff) | (p_value << 16);
  124. if (colorComponent == "g") fmt[propertyName] = (fmt[propertyName] & 0xff00ff) | (p_value << 8);
  125. if (colorComponent == "b") fmt[propertyName] = (fmt[propertyName] & 0xffff00) | p_value;
  126. }
  127. p_obj.defaultTextFormat = fmt;
  128. p_obj.setTextFormat(fmt);
  129. }
  130. }
  131. }