简体   繁体   中英

How can I save a movie clip symbol in as3 as a PNG on my server?

I'm developing a website in flash for a company and it's going well so far. The website allows people to create custom railings. The owner of the company wants me to save out the demo picture that's shown in flash (movie clip) as an image (pref PNG) so that I can include it in the validation email. Does anyone know how to do this please? I need to save a movie clip symbol on the web server. Thanks in advance!

You need a couple of components to work in order to make this happen. AS3 doesn't execute on the server side (has no access to the servers hard disk) so you'll have to use some other language on the server to receive the file. I would personally recommend PHP as it's great for this kind of simple task and there are lots of tutorials out on the web for handling uploaded files using PHP.

On the AS3 side of things you can use BitmapData.draw method to draw you Sprites or whatever other IBitmapDrawable objects to a BitmapData. Then using PNG encoder (can use the built in or search around there's some other implementations out there) to encode the BitmapData into a PNG. Last step send the encoded PNG to the server and have it save the file somewhere the script has write permissions.

For some references here's some code I wrote:

Basically a save button in my app is clicked and the instance of the class below is shown, this then has the methods for saving. After getting the flattened image it makes a call using a third party PNGEncoder I found called PNGEncoder2

https://github.com/wafflejock/FingerPainting/blob/master/FlashBuilderProject/FingerPainting/src/com/shaunhusain/fingerPainting/view/optionPanels/SaveOptions.as

Below I have a separate class that manages all of the "layers" which are just sprites really for my drawing app. The "LayerManager" below has the method that uses BitmapData.draw to "flatten" all the layers into a single Bitmap/raster drawing.

https://github.com/wafflejock/FingerPainting/blob/master/FlashBuilderProject/FingerPainting/src/com/shaunhusain/fingerPainting/view/managers/LayerManager.as

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM