I wanted to learn more about bitmap data in flash and came across the floodFill() method. It basically will replace a color with one you assign it. In the demo the original color is a light blue (rgb 003366) and when you click the stage the square will change colors via the floodFill method.
package
{
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.events.MouseEvent;
public class FloodFillExample extends Sprite
{
private var _bmd:BitmapData;
private var _rect:Rectangle;
private var _bm:Bitmap;
public function FloodFillExample()
{
_bmd = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0x00cccccc);
_rect = new Rectangle(0, 0, stage.stageWidth/2, stage.stageHeight/2);
_bmd.fillRect(_rect, 0x00336699);
AddBm();
stage.addEventListener ( MouseEvent.MOUSE_DOWN, Flood );
}
private function Flood( e:MouseEvent )
{
// public function floodFill(x:int, y:int, color:uint):void
_bmd.floodFill(0, 0, Math.random() * 0xffffff);
AddBm();
}
private function AddBm():void
{
var _bm:Bitmap = new Bitmap(_bmd);
addChild(_bm);
}
}
}
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.