Posted By

gfazioli on 07/11/08


Tagged

flash effects movieclip CS3 AciotnScript Reflex


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

gfazioli
THEPWN3R


ActionScript Reflex Class


 / Published in: ActionScript 3
 

URL: http://www.undolog.com/2008/06/13/reflex-e-reflexme-da-classe-base-a-classe/

  1. /**
  2. * Reflex è una classe che permette di creare un effetto riflessione
  3. * su un qualsiasi MovieClip.
  4. *
  5. * @author Giovambattista Fazioli <[email protected]>
  6. * @web http://www.undolog.com
  7. * @version 1.0.2
  8. */
  9.  
  10. import flash.display.*;
  11. import flash.filters.*;
  12. import flash.geom.*;
  13. import flash.text.*;
  14. import flash.events.*;
  15.  
  16. public class Reflex extends MovieClip {
  17. private var _mc:MovieClip;
  18. private var __bmpd:BitmapData;
  19. private var __bmp:Bitmap;
  20. private var __mask:Shape;
  21. private var __oWidth:Number
  22. private var __oHeight:Number;
  23. private var __gradientRadial:Boolean = false;
  24. private var __reflexOffset:Number = 0;
  25. private var __gradientOffset:Number = 128;
  26. private var __alphaOffset:Number = .5;
  27. private var __matrix:Matrix;
  28. /**
  29. * Class Constructor
  30. */
  31. public function Reflex(mc:MovieClip):void {
  32. _mc = mc;
  33. init();
  34. }
  35.  
  36. /**
  37. * Trigged from constructor. Init all properties
  38. *
  39. * @param {event} Event (can be null)
  40. * @return void
  41. * @private
  42. */
  43. private function init(e:Event = null):void {
  44. // save original clip dimension
  45. __oWidth = _mc.width;
  46. __oHeight = _mc.height;
  47. // bitmapdata/bitmap reflex
  48. __bmpd = new BitmapData( _mc.width, _mc.height, true, 0x000000);
  49. __bmpd.draw( _mc );
  50. __bmp = new Bitmap( __bmpd );
  51. _mc.addChild( __bmp );
  52. __bmp.scaleY = -1;
  53. __bmp.y = __oHeight*2 + __reflexOffset;
  54. __bmp.cacheAsBitmap = true;
  55. // gradient
  56. __mask = new Shape();
  57. __mask.cacheAsBitmap = true;
  58. __mask.y = __oHeight + __reflexOffset;
  59. __matrix = new Matrix();
  60. __matrix.createGradientBox(__oWidth, __oHeight, Math.PI/2);
  61. doGradient();
  62. _mc.addChild( __mask );
  63. __bmp.mask = __mask;
  64. }
  65.  
  66. /**
  67. * Draw original MovieClip into a Bitmap for reflection
  68. *
  69. * @param {event} Event (can be null)
  70. * @return void
  71. * @private
  72. */
  73. private function render(e:Event = null):void {
  74. __bmpd.draw( _mc );
  75. }
  76.  
  77. /**
  78. * Create a gradient fill in mask movieclip
  79. *
  80. * @param void
  81. * @return void
  82. * @private
  83. */
  84. private function doGradient():void {
  85. with( __mask.graphics ) {
  86. clear();
  87. beginGradientFill( (__gradientRadial?GradientType.RADIAL:GradientType.LINEAR), [0x000000,0x000000], [__alphaOffset, 0], [0, __gradientOffset], __matrix);
  88. drawRect(0, 0, __oWidth, __oHeight);
  89. endFill();
  90. }
  91. }
  92.  
  93. /**
  94. * Get/Set reflection offset
  95. *
  96. * @param {number} v Offset in pixel
  97. * @return {number} Offset in pixel
  98. */
  99. public function get reflexOffset():Number { return __reflexOffset; }
  100. public function set reflexOffset(v:Number):void {
  101. __reflexOffset = v;
  102. __bmp.y = __oHeight*2 + __reflexOffset;
  103. __mask.y = __oHeight + __reflexOffset;
  104. }
  105.  
  106. /**
  107. * Get/Set gradient offset
  108. *
  109. * @param {number} v Offset in pixel
  110. * @return {number} Offset in pixel
  111. */
  112. public function get gradientOffset():Number { return __gradientOffset; }
  113. public function set gradientOffset(v:Number):void {
  114. __gradientOffset = v;
  115. doGradient();
  116. }
  117.  
  118. /**
  119. * Get/Set alpha offset
  120. *
  121. * @param {number} v Offset in pixel
  122. * @return {number} Offset in pixel
  123. */
  124. public function get alphaOffset():Number { return __alphaOffset; }
  125. public function set alphaOffset(v:Number):void {
  126. __alphaOffset = v;
  127. doGradient();
  128. }
  129.  
  130. /**
  131. * Get/Set reflection offset
  132. *
  133. * @param {boolean} v true for radial, false for linear
  134. * @return {boolean} true radial, false linear
  135. */
  136. public function get gradientRadial():Boolean { return __gradientRadial; }
  137. public function set gradientRadial(v:Boolean):void {
  138. __gradientRadial = v;
  139. doGradient();
  140. }
  141. }

Report this snippet  

You need to login to post a comment.