i've programatically created a vector graphic (rect), repositioned the graphic, and set up an MOUSE_MOVE eventL开发者_如何学运维istener to trace color information of the graphic using getPixel(). however, the bitmapData is placed at 0,0 of the stage and i don't know how to move it so that it matches the graphic's location.
var coloredSquare:Sprite = new GradientRect(200, 200, 0xFFFFFF, 0x000000, 0xFF0000, 0xFFFF00);
coloredSquare.x = 100;
addChild(coloredSquare);
var coloredSquareBitmap:BitmapData = new BitmapData(coloredSquare.width, coloredSquare.height, true, 0);
coloredSquareBitmap.draw(coloredSquare);
coloredSquare.addEventListener(MouseEvent.MOUSE_MOVE, readColor);
function readColor(evt:Event):void
{
var pixelValue:uint = coloredSquare.getPixel(mouseX, mouseY);
trace(pixelValue.toString(16));
}
Use the square's transformation matrix (which contains the translation as well) as the second parameter of the draw()
method
e.g.
coloredSquareBitmap.draw(coloredSquare,coloredSquare.transform.matrix);
I do not fully understand the problem or the code. Maybe this helps:
coloredSquareBitmap.draw(coloredSquare, coloredSquare.transform.concatenatedMatrix);
Use
var pixelValue:uint = coloredSquare.getPixel(coloredSquare.mouseX, coloredSquare.mouseY);
That way the mouseX / mouseY will be local to the coloured square and thus the bitmap duplicate .
精彩评论