“Be inspired, enjoy your work, keep learning and never forget to play.” — gskinner

Taking a snapshot of an flv

Posted: December 3rd, 2007 | Author: Idoru | Filed under: Actionscript3, Bitmap, Tutorial, Video, WorkAround | 2 Comments »

Following my last post on 9-Slice items, here comes another nice one on Bitmap.draw() and the security sandbox.
Many people know the solution to this one, but i just found myself looking for it for too long, so here it goes :)

If you want to take a snapshot of a running Video object, you can't, you'll be alerted by the flash player that you are violating
the sandbox security. So how do we do it?
Easy as pie :)

video.attachNetStream( null );
bitmapData.draw( video );
video.attachNetStream ( myNetStreamObject );

Three very simple lines of code but that are hard to come by.


9-Slice and Bitmap

Posted: December 3rd, 2007 | Author: Idoru | Filed under: Actionscript3, Bitmap, Papervision3d, WorkAround | 2 Comments »

Have you ever tried to take a snapshot using bitmap.draw() of a movieclip that has 9-slice enabled?

//my9SliceEnabledMc is a 40 by 40 9-slice enabled movieclip on stage
my9SliceEnabledMc.width = 200;
my9SliceEnabledMc.height = 300;
var myBitmapData = new BitmapData(200,300);
myBitmapData.draw(my9SliceEnabledMc);
addChild(new Bitmap(myBitmapData));

So what you'd expect to happen above is to have a new bitmap that looks the same as my9SliceEnabledMc,
but what you get instead is the original 40x40 movieclip.
This doesn't make sense at all, i have no idea what Adobe was thinking when they let this one through.
This was driving me crazy for a while now, and today i finally found the answer, as simple as it seems,
putting the my9SliceEnabledMc inside another sprite corrects the issue!!

//my9SliceEnabledMc is a 40 by 40 9-slice enabled movieclip on the library
var myContainer = new Sprite();
var my9SliceEnabledMc = new my9SliceEnabledMc();
myContainer.addChild(my9SliceEnabledMc);
my9SliceEnabledMc.width = 200;
my9SliceEnabledMc.height = 300;
var myBitmapData = new BitmapData(200,300);
myBitmapData.draw(myContainer);
addChild(new Bitmap(myBitmapData))

Also i should add that this is a major issue with PV3D since you cannot directly use a 9-slice item as a texture.