1. Code
  2. Game Development

Quick Tip: How to Export Flash to PNG with HYPE

Scroll to top
8 min read

With Flash you can create some awesome code generated graphics. Often you’d like to save these graphics as an image, so you can edit them afterwards with image editing software or just showcase them. We’ll use the HYPE framework from Joshua Davis and Branden Hall to save our code-generated graphics as a PNG.


View Screencast

Please accept marketing cookies to load this content.

Code

Here's the code, in class form so you can use it whether you're developing with Flash or Flex:

1
2
package
3
{
4
	import flash.display.MovieClip;
5
	import flash.display.Sprite;
6
	import hype.framework.display.BitmapCanvas;
7
	import hype.extended.util.ContextSaveImage;
8
	
9
	public class Demo extends MovieClip
10
	{
11
		public function Demo():void
12
		{
13
			var sprite:Sprite = new Sprite();
14
			sprite.graphics.beginFill(0xff0000);
15
			sprite.graphics.drawRect(150, 150, 200, 200);
16
			sprite.graphics.endFill();
17
			
18
			var bmc:BitmapCanvas = new BitmapCanvas(stage.stageWidth, stage.stageHeight);
19
			bmc.startCapture(sprite);
20
			addChild(bmc);
21
			
22
			var saver:ContextSaveImage = new ContextSaveImage(bmc);
23
		}
24
	}
25
}