Creating a Flood Fill : BitmapData : Graphics Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Graphics » BitmapData »

 

Creating a Flood Fill


 
package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;

    public class Main extends Sprite {
        private var _bitmap:BitmapData= new BitmapData(stage.stageWidth,stage.stageHeight,false, 0xffffffff);
    

        public function Main (  ) {
            var sprite:Sprite = new Sprite(  );
            addChild(sprite);
            for(var i:int 0; i < 200; i++) {
                _bitmap.fillRect(new Rectangle(
                             Math.random(  ) * stage.stageWidth,
                             Math.random(  ) * stage.stageHeight,
                             2020), Math.random(  ) 0xffffffff);
            }
            var image:Bitmap = new Bitmap(_bitmap);
            sprite.addChild(image);
            sprite.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
        }

        public function onMouseDown(event:MouseEvent):void {
            _bitmap.floodFill(mouseX, mouseY, 0xffff0000);
        }
    }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Graphics
» BitmapData