Advertisement
Advertisement
Advertisement
Advertisement
by Daniel Apt
Length:QuickLanguages:
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
Advertisement
Weekly email summary
Subscribe below and we’ll send you a weekly email summary of all new Code tutorials. Never miss out on learning about the next big thing.
Update me weeklyAdvertisement
Translations
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!
Translate this postPowered by![Native Native]()

Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.