package { import flash.display.BitmapData; import flash.display.Shape; import flash.display.Sprite; import flash.geom.Matrix; [SWF(width=550, height=400, backgroundColor=0xFFFFFF)] /** * Demonstrates the different parameters of beginBitmapFill(). */ public class graphic_flex_image_effects_01_Flex_FillingShapesWithBitmaps extends Sprite { /** * Constructor. Calls draw(). */ public function graphic_flex_image_effects_01_Flex_FillingShapesWithBitmaps() { draw(); } /** * Creates an image using Perlin noise. * * @return The image created. */ private function makeBitmapData():BitmapData { var bitmap:BitmapData = new BitmapData(100, 100); bitmap.perlinNoise(40, 40, 2, Math.random(), true, false); return bitmap; } /** * Draws the created image into four shapes. */ private function draw():void { var bitmap:BitmapData = makeBitmapData(); // parameters for shapes var width:Number = stage.stageWidth/2; var height:Number = stage.stageHeight/2; var radius:Number = 70; // top left shape simply draws bitmap var shape:Shape = new Shape(); with (shape.graphics) { beginBitmapFill(bitmap); drawRoundRect(0, 0, width, height, radius, radius); endFill(); } addChild(shape); // top right shape does not tile bitmap shape = new Shape(); var matrix:Matrix = new Matrix(); matrix.translate((width-bitmap.width)/2, (height-bitmap.height)/2); with (shape.graphics) { beginBitmapFill(bitmap, matrix, false); drawRoundRect(0, 0, width, height, radius, radius); endFill(); } shape.x = width; addChild(shape); // bottom left shape shows rotated bitmap, not tiled shape = new Shape(); matrix.rotate(Math.PI/4); with (shape.graphics) { beginBitmapFill(bitmap, matrix, false); drawRoundRect(0, 0, width, height, radius, radius); endFill(); } shape.y = height; addChild(shape); // bottom right shape shows scaled bitmap, not smoothed shape = new Shape(); matrix = new Matrix(); matrix.scale(20, 20); with (shape.graphics) { beginBitmapFill(bitmap, matrix, false, false); drawRoundRect(0, 0, width, height, radius, radius); endFill(); } shape.x = width; shape.y = height; addChild(shape); } } }