开发者

To check whether Movie Clip got filled at one place

I have created a empty movie clip . And i,m brushing on that .(i.e)Filling(Begin Fill开发者_C百科) it with ellipse for every click .

How do I check whether it is filled at particular place .(say 400 x 400 from x=0,y=0)?


First you would need to convert it to a bitmapdata format.
Then you would use the function getPixel to query it.

import flash.display.Bitmap;  
import flash.display.BitmapData;  

// Lets say drawingpad is a MovieClip that is getting ellipses drawn on it.  
var bitmap:Bitmap = new Bitmap(new BitmapData(stage.stageWidth,stage.stageHeight));  
bitmap.draw(drawingpad);  
var value:uint = bitmap.bitmapData.getPixel(400,400);  

Hope this helps


I assume with "400 x 400 from x=0,y=0" you mean a the area between 0,0 and 400,400.

You need to copy the content of the rectangle of your MovieClip to a Bitmap, to be able to get information about its pixels.

// coordinates as in the question's example, could be method parameters
var x1:int=0;  
var y1:int=0;
var x2:int=400;
var y2:int=400;

// bitmap with transparency, with a size of the rectangle to check
var bitmap:Bitmap = new Bitmap(new BitmapData(x2-x1, y2-y1, true, 0x00000000)); 
// draw the painted mc to the bitmap, displaced to upper left x and y
bitmap.draw(mc, new Matrix(1,0,0,1,-x1,-y1)));

Using getColorBoundsRect, you can check if a bitmap contains a colour, or if it contains any other colours. Now check if it contains any other colour than 'transparent' (= any other colours with an alpha value>0):

var maskColor:uint = 0xFF000000; // ignore rgb, only check alpha values
var color:uint = 0x00000000; // 'empty', fully transparent color
// get a rect containing all pixels with not fully transparent colors
var colorBoundsRect:Rectangle = bitmap.getColorBoundsRect(maskColor, color, false);
if (colorBoundsRect.width == 0 && colorBoundsRect.height == 0){
    trace("empty"); // rect contains no visible pixels
}


Assuming the places where it's not filled are transparent, a simple hitTestPoint should do the trick:

myObj.hitTestPoint( 400.0, 400.0, true ); // true means we use the pixels of the shape and not the bounding box

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#hitTestPoint()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜