30Jun
Filling BitmapData Colors with an alternate color with the floodFill Method
No commentsI 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);
}
}
}
Categories: manewc.com
Monday, June 30th, 2008 at 9:46 am and is filed under manewc.com. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.