/ Published in: ActionScript 3
Expand |
Embed | Plain Text
package { import com.greensock.*; import flash.display.PixelSnapping; import flash.display.GradientType; import flash.display.SpreadMethod; import flash.display.Bitmap; import flash.display.BitmapData; import flash.display.Sprite; import flash.geom.Matrix; import flash.display.MovieClip; public class ReflectedImage extends MovieClip { private var BMPData:BitmapData; private var BMPNormal:Bitmap; private var BMPReflected:Bitmap; private var maskerNormal:Sprite; private var maskerReflected:Sprite; private var matr:Matrix = new Matrix(); private var imageHeight:int; private var imageWidth:int; public function ReflectedImage( srcImage:MovieClip ) { imageWidth = srcImage.width; imageHeight = srcImage.height; BMPData = new BitmapData( imageWidth, imageHeight, true ); BMPData.draw( srcImage ); BMPNormal = new Bitmap( BMPData, PixelSnapping.AUTO, true ); addChild( BMPNormal ); BMPNormal.y = imageHeight; BMPReflected = new Bitmap( BMPData, 'auto', true ); addChild( BMPReflected ); BMPReflected.y = imageHeight; BMPReflected.scaleY = -1; maskerNormal = new Sprite(); addChild( maskerNormal ); maskerNormal.graphics.beginFill( 0xFF0000 ); maskerNormal.graphics.drawRect( 0, 0, imageWidth, imageHeight ); maskerNormal.graphics.endFill(); BMPNormal.cacheAsBitmap = maskerNormal.cacheAsBitmap = true; BMPNormal.mask = maskerNormal; maskerReflected = new Sprite(); addChild( maskerReflected ); maskerReflected.y = imageHeight; matr.createGradientBox( imageWidth, imageHeight, Math.PI * 0.5, 0, 0 ); maskerReflected.graphics.beginGradientFill( GradientType.LINEAR, [0xFF0000, 0xff0000 ], [0.4, 0], [0x00, 0x40], matr, SpreadMethod.PAD ); maskerReflected.graphics.drawRect( 0, 0, imageWidth, imageHeight ); maskerReflected.graphics.endFill(); BMPReflected.cacheAsBitmap = maskerReflected.cacheAsBitmap = true; BMPReflected.mask = maskerReflected; } public function show():void { TweenMax.to( BMPNormal, 1, { y: 0 } ); TweenMax.to( BMPReflected, 1, { y: imageHeight * 2 } ); } public function hide():void { TweenMax.to( BMPNormal, 1, { y: imageHeight } ); TweenMax.to( BMPReflected, 1, { y: imageHeight } ); } } }
You need to login to post a comment.
