PDA

View Full Version : AS3 BitmapData getPixel??? Need Help...



popnfresh24
August 18th, 2009, 05:11 AM
been hard to find a tutorial for AS3 and this... i looked on here

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/

but i can't understand how to do it the way i need to...

i want to have a bitmap on my stage... and then when the mouse is clicked on it... it changes a MC to whatever colour it's clicked on...

for example sake... say the bitmaps name is "tree" and the movieclip is "branch"

can anyone give me an example how i can do this???

i was told to use the ColorTransform... and it works with something else i tried... i just don't know how to use the "getPixel" from a bitmap image on my stage...

thanks... :)

creatify
August 18th, 2009, 12:34 PM
// first you need to convert your clip to a bitmapdata / bitmap:

// draw tree to bmpd
var bmpd:BitmapData = new BitmapData(tree.width, tree.height);
bmpd.draw(tree);
// create bitmap which can be added to the stage, use the bmpd as the "contents"
var bmp:Bitmap = new Bitmap(bmpd);
bmp.x = tree.x;
bmp.y = tree.y;
addChild(bmp);

// remove tree
removeChild(tree);

stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);

function onDown(e:MouseEvent):void {
var ct:ColorTransform = branch.transform.colorTransform;
trace(bmp.mouseX, bmp.mouseY)
ct.color = bmpd.getPixel(bmp.mouseX, bmp.mouseY);
branch.transform.colorTransform = ct;
}