Hi,

Just create a fla and import a picture (jpg) in the librairy (minimum 150,150). Link this picture with the id: picture_id
Then try this code.

import flash.display.BitmapData;
import flash.geom.Point;
import flash.geom.Rectangle;

var picture:BitmapData = BitmapData.loadBitmap("picture_id");
_root.createEmptyMovieClip("pictureMc",1);
pictureMc.attachBitmap(picture,1);

var subPicture:BitmapData = new BitmapData(100,100,false,0xFF0000);
_root.createEmptyMovieClip("subPictureMc",2);
subPictureMc.attachBitmap(subPicture,1);

var xPos:Number = 50;
var yPos:Number = 50;
var borderSize:Number = 10;

subPictureMc.onRelease = function() {
subPicture.copyPixels(picture,new Rectangle(xPos,yPos,subPicture.width-borderSize*2,subPicture.height-borderSize*2),new Point(borderSize,borderSize));
}

Your picture must be displayed. A red box will appear on it. Then click on the red box, a part of your picture is drawed into the red box. Change the xPos, yPos and borderSize. You'll be abble to anderstand copyPixels with this exemple.

(but it don't show how to use the alpha channel... another time, when you'll be familiar with this)

enjoy,

David Buff

----- Original Message ----- From: "Johnny Zen" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
Sent: Thursday, October 19, 2006 10:40 AM
Subject: [Flashcoders] attachbitmap and copy pixels.


Hi all

Can anyone give me a super simple example on using copypixels to take
a "snapshot" of a jpg within a movie clip. I'm having trouble
understanding the examples of bitmapdata and copypixels.

It would be a great help for me.


Best wishes


Johnny
_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to