FORKER
Login
|
Register
GradientMask.as
[
6 revisions
|
fork this
]
Login or register first to fork code
package { import flash.display.*; import flash.geom.*; public class GradientMask extends Sprite { public function GradientMask() { var boxSize:int = 8; var pattern:BitmapData = new BitmapData( boxSize * 2, boxSize * 2, false ); pattern.fillRect( new Rectangle( 0, 0, boxSize, boxSize ), 0xCCCCCC ); pattern.fillRect( new Rectangle( boxSize, boxSize, boxSize, boxSize ), 0xCCCCCC ); graphics.beginBitmapFill( pattern ); graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight ); graphics.endFill(); /*var myImage:Bitmap = new image as Bitmap; var matrix:Matrix = new Matrix(); //Create a gradient fill. matrix.createGradientBox(myImage.width, myImage.height, Math.PI / 2); var linear:String = GradientType.LINEAR; var colors:Array = [0xFFFFFF, 0xFFFFFF]; var alphas:Array = [1.0, 0.0]; var ratios:Array = [0.0, 255]; var spread:String = SpreadMethod.PAD; var gradient:Shape = new Shape(); //Make a displayObject, fill it with your gradientFill gradient.graphics.beginGradientFill(linear, colors, alphas, ratios, matrix, spread); gradient.graphics.drawRect(0, 0, myImage.width, myImage.height); gradient.graphics.endFill(); //Make a bitmapData snapshot of that displayObject. This will be the 'alphaBitmapData' for the copyPixels routine below. var gradientBitmap:BitmapData = new BitmapData(gradient.width, gradient.height, true, 0); gradientBitmap.draw(gradient); //Make a bitmapData snapshot of the original image. Apply alpha information from gradientBitmap. var result:BitmapData = new BitmapData(myImage.width, myImage.height, true, 0); result.copyPixels(myImage.bitmapData, result.rect, new Point(), gradientBitmap, new Point(), true); //Add a new bitmap representing your creation. sprite1.addChild(new Bitmap(result)); //DOWNSIDE: We're no longer working with our original view, but a bitmap snapshot of it. //Interactivity will be lost. Maybe if we only offer this as a property on images? } } }