【发布时间】:2014-06-04 16:42:27
【问题描述】:
我一直在使用基本的油漆、橡皮擦和填充工具制作类似于 MS-Paint 的基本绘画应用程序。最后一个给我带来了一些麻烦。
我对使用 BitmapData 很陌生,但我的想法是当用户单击板时,它会触发 startFloodFill 方法。如下所示:
public static function startFloodFill(e:MouseEvent):void
{
trace("FLOODFILL");
var boardRef:MovieClip = e.currentTarget.parent.board; //Creates a reference to the board
var boardData:BitmapData = new BitmapData(boardRef.width, boardRef.height); //Creates a new BitmapData with the same size as boardRef
boardData.floodFill(e.localX, e.localY, 0x00CCCCCC); //Applies the FloodFill
boardData.draw(boardRef); //Saves the boardRef as bitmapData
boardRef.bitmapData = boardData; //Updates the board
boardRef.parent.addChild(boardRef);
}
谁能告诉我我在这里做错了什么?当我单击时,板不会改变。我希望 FloodFill 用所选颜色填充整个位图,因为当我单击时板是空白的。
我还尝试将最后两行替换为:
boardRef.addChild(new Bitmap(boardData) ); //Updates the board
谢谢
【问题讨论】:
-
boardRef是什么类型的对象?Bitmap?为什么它有bitmapData属性?如果没有,你为什么要分配它?如果它真的是Bitmap,你应该改为使用floodFill而不是bitmapData。
标签: actionscript-3 bitmap bitmapdata