我已經創建了一個包含數據的位圖並將其放置在一個精靈中以便接收鼠標事件。然而,我正在努力閱讀精靈內的BitmapData。Actionscript從Sprite鼠標事件中檢索BitmapData
function showBitmapData(e:Event):void
{
var bData:BitmapData = new BitmapData(video.width, video.height);
bData.draw(video);
var bmap:Bitmap = new Bitmap(bData);
bmap.x = 220;
bmap.y = 20;
bmap.scaleX = bmap.scaleY = 2;
canvas = new Sprite;
addChild(canvas);
canvas.addChild(bmap);
//Mouse Track Pixel Colors
canvas.addEventListener(MouseEvent.CLICK, readPixel);
}
function readPixel(e:MouseEvent):void
{
var hex:uint = e.bmap.bData.getPixel32(mouseX, mouseY); // <- is the problem?
var pixelAlpha:int = (hex >>> 0x18) & 0xff;
var red:int = (hex >>> 0x10) & 0xff;
var green:int = (hex >>> 0x08) & 0xff;
var blue:int = hex & 0xff;
colorText.text = "Red:" + red + " Green:" + green + " Blue:" + blue + " Alpha:" + pixelAlpha;
}
e.currentTarget將是mc,而不是位圖。 – UltimateBrent 2010-03-03 23:01:25
@UltimateBrent沒有,因爲我將事件添加到位圖,但無論如何,因爲位圖不是一個交互式對象,我不會得到事件,我會修改它。 – Patrick 2010-03-05 19:44:02
謝謝帕特里克。完美的作品! – TheDarkIn1978 2010-03-05 21:01:23