Reputation: 5189
I'm wondering if it's possible at all to sort of record/capture the state of an swf movie over a period of time and save it all down as jpgs to the server?
AS3 has the new com.adobe.images.JPGEncoder class that seems to do the job, but can I capture a sequence? The hope would be that I could put it back together as a video or animation.
Is there other ways to encode swf to video programmatically?
Upvotes: 0
Views: 1487
Reputation: 28250
I have done a "screen capture" before using the JPGEncoder, so I think you should be able to capture the screen on the ENTER_FRAME event. This may not work as JPG encoding isn't super fast.
That is how I would go about doing it. For your reference, here's some code that does this(for a single screenshot):
var fileReference:FileReference = new FileReference();
// Capture the BitmapData of the stage for example
var captureMovieClip:DisplayObjectContainer = stage;
var stage_snapshot:BitmapData = new BitmapData(captureMovieClip.width, captureMovieClip.height);
stage_snapshot.draw(captureMovieClip);
// Setup the JPGEncoder, run the algorithm on the BitmapData, and retrieve the ByteArray
var encoded_jpg:JPGEncoder = new JPGEncoder(100);
var jpg_binary:ByteArray = encoded_jpg.encode(stage_snapshot);
// save
fileReference.save(jpg_binary, "screenshot.jpg");
You can probably extend this to be called in your ENTER_FRAME event handler, and then save the file to different filenames. Also instead of the stage, you can use a different display object.
I don't know how fast this will run, you may need to lower the frame rate so the ENTER_FRAME isn't called so much, but you'll lose some quality in your JPG renderings.
Also turning down the quality in the line: new JPGEncoder(100)
from 100 to a lower value may help with file sizes of the jpegs(but may or may not incur more overhead with compression).
Upvotes: 1