How do you programmatically take a screenshot of a Flash app, and send the bitmap to server? - without using javascript, just Actionscript
Taking a screenshot is as simple as drawing into a BitmapData
object. Something like:
var bmd:BitmapData = new BitmapData( this.stage.stageWidth, this.stage.stageHeight );
bmd.draw( this.stage );
Replace this.stage
with whatever DisplayObject
you want to draw. Check out the BitmapData
docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/BitmapData.html#draw()
Sending it to the server depends on how you're connecting to the server. If it can accept the raw data from BitmapData, then go with it. Otherwise, encode it with JPEGEncoder
or PNGEncoder
from the the as3corelib: https://github.com/mikechambers/as3corelib.
You can probably upload it through PHP, or by writing the ByteArray
data from the image to a URLRequest
. How that works is a bit more complicated to write here (it involves multipart/form-data). The easiest way to see how it works is to check out the Facebook AS3 API where they have image uploading working: http://code.google.com/p/facebook-actionscript-api/ (check out the call()
function in the FacebookRequest
class)