Posted By

sidneydekoning on 01/21/10


Tagged

Reflection as3


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Empreintes


Reflection Class for MovieClips


 / Published in: ActionScript 3
 

URL: http://gauravjassal.com/

  1. package {
  2.  
  3. import com.greensock.*;
  4.  
  5. import flash.display.PixelSnapping;
  6. import flash.display.GradientType;
  7. import flash.display.SpreadMethod;
  8. import flash.display.Bitmap;
  9. import flash.display.BitmapData;
  10. import flash.display.Sprite;
  11. import flash.geom.Matrix;
  12. import flash.display.MovieClip;
  13.  
  14. public class ReflectedImage extends MovieClip {
  15.  
  16. private var BMPData:BitmapData;
  17. private var BMPNormal:Bitmap;
  18. private var BMPReflected:Bitmap;
  19.  
  20. private var maskerNormal:Sprite;
  21. private var maskerReflected:Sprite;
  22. private var matr:Matrix = new Matrix();
  23.  
  24. private var imageHeight:int;
  25. private var imageWidth:int;
  26.  
  27. public function ReflectedImage( srcImage:MovieClip ) {
  28.  
  29. imageWidth = srcImage.width;
  30. imageHeight = srcImage.height;
  31.  
  32. BMPData = new BitmapData( imageWidth, imageHeight, true );
  33. BMPData.draw( srcImage );
  34.  
  35. BMPNormal = new Bitmap( BMPData, PixelSnapping.AUTO, true );
  36. addChild( BMPNormal );
  37. BMPNormal.y = imageHeight;
  38.  
  39. BMPReflected = new Bitmap( BMPData, 'auto', true );
  40. addChild( BMPReflected );
  41. BMPReflected.y = imageHeight;
  42. BMPReflected.scaleY = -1;
  43.  
  44. maskerNormal = new Sprite();
  45. addChild( maskerNormal );
  46. maskerNormal.graphics.beginFill( 0xFF0000 );
  47. maskerNormal.graphics.drawRect( 0, 0, imageWidth, imageHeight );
  48. maskerNormal.graphics.endFill();
  49.  
  50. BMPNormal.cacheAsBitmap = maskerNormal.cacheAsBitmap = true;
  51. BMPNormal.mask = maskerNormal;
  52.  
  53. maskerReflected = new Sprite();
  54. addChild( maskerReflected );
  55. maskerReflected.y = imageHeight;
  56. matr.createGradientBox( imageWidth, imageHeight, Math.PI * 0.5, 0, 0 );
  57. maskerReflected.graphics.beginGradientFill( GradientType.LINEAR, [0xFF0000, 0xff0000 ], [0.4, 0], [0x00, 0x40], matr, SpreadMethod.PAD );
  58. maskerReflected.graphics.drawRect( 0, 0, imageWidth, imageHeight );
  59. maskerReflected.graphics.endFill();
  60.  
  61. BMPReflected.cacheAsBitmap = maskerReflected.cacheAsBitmap = true;
  62. BMPReflected.mask = maskerReflected;
  63.  
  64. }
  65.  
  66. public function show():void {
  67. TweenMax.to( BMPNormal, 1, { y: 0 } );
  68. TweenMax.to( BMPReflected, 1, { y: imageHeight * 2 } );
  69. }
  70.  
  71. public function hide():void {
  72. TweenMax.to( BMPNormal, 1, { y: imageHeight } );
  73. TweenMax.to( BMPReflected, 1, { y: imageHeight } );
  74. }
  75.  
  76. }
  77. }

Report this snippet  

You need to login to post a comment.