package { import flash.display.Bitmap; import flash.display.BitmapData; import flash.events.MouseEvent; [SWF(width=1200, height=600, backgroundColor=0x000000)] /** * Colors background based on pixel color below mouse. */ public class graphic_flex_image_effects_03_Flex_GetPixelTest extends graphic_flex_image_effects_03_Flex_DualImageTest { private var _screenshot:BitmapData; /** * Takes image grab of stage so that colors can be retrieved from it, * then sets up a listener for when the mouse moves. */ override protected function operateOnImages():void { _screenshot = new BitmapData(stage.stageWidth, stage.stageHeight); _screenshot.draw(stage); stage.addEventListener(MouseEvent.MOUSE_MOVE, onStageMouseMove); } /** * Handler for when the mouse moves. This recolors the background * based on the pixel color below the mouse. * * @param event Event dispatched by Stage. */ private function onStageMouseMove(event:MouseEvent):void { var x:Number = event.localX; var y:Number = event.localY; // grabs color from screenshot var color:uint = _screenshot.getPixel(x, y); // colors whole background graphics.clear(); graphics.beginFill(color); graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight); graphics.endFill(); } } }