In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

flash on 2010-4-24

Get Adobe Flash player
by kihon 24 Apr 2010
/**
 * Copyright kihon ( http://wonderfl.net/user/kihon )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/r0AP
 */

package
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.FileReference;
	import flash.utils.ByteArray;
	import mx.graphics.codec.PNGEncoder;
	import mx.graphics.codec.JPEGEncoder;
	import com.bit101.components.PushButton;
	
	public class Main extends Sprite
	{	
		private var canvas:BitmapData;

		public function Main()
		{
			canvas = new BitmapData(100, 100, false, 0xED1A3D);
			var bitmap:Bitmap = new Bitmap(canvas);
			addChild(bitmap);
			bitmap.x = 182;
			bitmap.y = 182;
			
			new PushButton(this, 182, 282, "save(PNG)", onMouseClick);
			new PushButton(this, 182, 302, "save(JPEG)", onMouseClick2);
		}

		private function onMouseClick(event:Event):void 
		{
			var ba:ByteArray = new PNGEncoder().encode(canvas);
			new FileReference().save(ba, "t.png");
		}
		
		private function onMouseClick2(event:Event):void 
		{
			var ba:ByteArray = new JPEGEncoder().encode(canvas);
			new FileReference().save(ba, "t.jpeg");
		}
	}
}