PDA

View Full Version : Take screenshot of Stage and split that image


meemain
02-18-2009, 03:18 PM
What i am trying to achieve is take a screen shot of the stage and save the screengrab into a movieclip or image in the library. which i can further transform later. Here is an example:

There are dragable items sitting on the stage; user will be able to arrange them in any order he/she may like; finished result will be a stacked of items over each other in the sequence; so far so good no problems there... now i would like to show an animation where the stack of items breaks from centre into two parts. I can do it with an existing image but as you can see the stack of image can be organize in any order and to make the split/breaking of images realistic i have to take a screen grab of stage; save it in library; and run the following script to split it into two pieces.

I would appreciate if any one could help me or point me in a direction where i can get some help.

Thanks

rrh
02-18-2009, 04:17 PM
Can it be a bitmap? I can imagine how to do this with bitmaps if nothing else.

meemain
02-18-2009, 04:36 PM
but can that bitmap be generated dynamically from the stage?

rrh
02-18-2009, 06:15 PM
From here:
http://www.newgrounds.com/bbs/topic/872585
import flash.display.Bitmap;
import flash.display.BitmapData;

var a:BitmapData = new BitmapData(100, 100);
var b:Bitmap = new Bitmap(a);

addChild(b);

a.draw(pie);
pie.visible = false;

meemain
02-18-2009, 07:16 PM
Thanks a lot... here is the final code:



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

var stageBMD:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);

var stBM:Bitmap = new Bitmap(stageBMD);

addChild(stBM);

stageBMD.draw(stage);
tong.visible = false;

var bmd:BitmapData = new BitmapData(stageBMD.width/2, stageBMD.height/2);
bmd.draw(stageBMD, null, null, null, new Rectangle(0, 0, stageBMD.width/2, stageBMD.height/2));
var bm:Bitmap = new Bitmap(bmd);
var loaderBMD:BitmapData = new BitmapData(stageBMD.width, stageBMD.height);
loaderBMD.draw(stageBMD);
var bmd2:BitmapData = new BitmapData(stageBMD.width/2, stageBMD.height/2, true, 0xFF0000);
bmd2.copyPixels(stageBMD, new Rectangle(stageBMD.width/2, 0, stageBMD.width/2, stageBMD.height/2), new Point(0, 0));

var bm2:Bitmap = new Bitmap(bmd2);

addChild(bm);
addChild(bm2);
bm2.x = bm.width + 20;
stageBMD.dispose();
removeChild(stBM);