8.7.创建一个充溢填充

问题
我要填充一个大的不规则的区域
解决办法
使用BitmapData类的floodFill( )方法
讨论
floodFill( )方法和setPixel( )方法语法一样,接受一个x,y坐标和颜色。

看下面的代码演示,首先创建一个位图和一些随机的方框,然后鼠标点击某个方框,就会用红色填充它:
+展开
-ActionScript
package {
import flash.display.Sprite;
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.MouseEvent;
import flash.geom.Rectangle;
public class FloodFillDemo extends Sprite {
private var _bitmap:BitmapData;
public function FloodFillDemo ( ) {
var sprite:Sprite = new Sprite( );
addChild(sprite);
_bitmap = new BitmapData(stage.stageWidth,
stage.stageHeight,
false, 0xffffffff);
for(var i:int = 0; i < 20; i++) {
_bitmap.fillRect(new Rectangle(
Math.random( ) * stage.stageWidth,
Math.random( ) * stage.stageHeight,
50, 50), 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);
}
}
}

加支付宝好友偷能量挖...


评论(0)网络
阅读(115)喜欢(0)flash/flex/fcs/AIR