Saving an image to local disk in Actionscript 3.0

294 Views Asked by At

I have a rectangle MovieClip (named rect) on the stage and i want the user to be able to save that rectangle MovieClip as a ".png" image on his computer, this is what i did:

//Convert my MovieClip to BitmapData
var bitmapData:BitmapData=new BitmapData(rect.width, rect.height);

//Create new ByteArray
var byteArray:ByteArray = new ByteArray();

//Encode my Bitmap to PNG
bitmapData.encode(new Rectangle(0,0,450,170), new flash.display.PNGEncoderOptions(), byteArray);

//saving the byteArray that holds the PNG as "myimage.png"
var fileReference:FileReference=new FileReference();
fileReference.save(byteArray, "myimage.png"); 

when i run the code, it prompts the windows save dialogue and when i save the image i get a blank ".png" image named "myimage.png" with size 450x170 that i specified. Any idea to solve this problem?

0

There are 0 best solutions below