Advertisement
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
Code
Here's the code, in class form so you can use it whether you're developing with Flash or Flex:
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import hype.framework.display.BitmapCanvas;
import hype.extended.util.ContextSaveImage;
public class Demo extends MovieClip
{
public function Demo():void
{
var sprite:Sprite = new Sprite();
sprite.graphics.beginFill(0xff0000);
sprite.graphics.drawRect(150, 150, 200, 200);
sprite.graphics.endFill();
var bmc:BitmapCanvas = new BitmapCanvas(stage.stageWidth, stage.stageHeight);
bmc.startCapture(sprite);
addChild(bmc);
var saver:ContextSaveImage = new ContextSaveImage(bmc);
}
}
}
Advertisement

Translations:
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!
Translate this postPowered by
About Daniel Apt
Advertisement
Suggested Envato Tuts+ Course
Next lesson playing in 5 seconds
CancelWhat Would You Like to Learn?
Suggest an idea to the content editorial team at Envato Tuts+.


