Last active
August 29, 2015 14:04
-
-
Save gregkepler/ccaca1c3a01845f10cd0 to your computer and use it in GitHub Desktop.
Flash save png sequence and manual advance timeline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // import TweenLite for tweening and TimelineLite for keeping track of tweens | |
| import com.greensock.TimelineLite; | |
| import com.greensock.TweenLite; | |
| // import filestream classes for saving images to disk (available only in AIR SDK) | |
| import flash.filesystem.*; | |
| // import PNGEncoder (available here https://github.com/mikechambers/as3corelib) | |
| import com.adobe.images.PNGEncoder; | |
| var timeline:TimelineLite = new TimelineLite(); // create a new timeline object | |
| timeline.pause(); // pause the timeline | |
| var currentFPS:Number = 24; | |
| // add all your tweens to the timeline | |
| timeline.append( TweenLite.to( movieclip, .5, { delay:0.0, alpha:1, ease:Quint.easeOut } ) ); | |
| addEventListener( Event.ENTER_FRAME, onFrame ); | |
| // reset frame count | |
| var frameCount:int = 0; | |
| // create a filestream object | |
| var fs : FileStream = new FileStream(); | |
| function onFrame( e:Event ) | |
| { | |
| // draw the stage to a BitmapData object | |
| var bmd:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight,true,0x000); | |
| bmd.draw(this); | |
| // encode the bitmap data object to a byte array | |
| var stream:ByteArray = PNGEncoder.encode(bmd); | |
| // create a file to write to | |
| var targetFile : File = File.desktopDirectory.resolvePath("png_test/frame_" + frameCount.toString() + ".png"); | |
| fs.open(targetFile, FileMode.WRITE); | |
| // write the bytes to the file and save | |
| fs.writeBytes(stream); | |
| fs.close(); | |
| // increase the frame count | |
| frameCount++; | |
| // advance the timeline | |
| var nextTick:Number = timeline.currentTime + (1 / currentFPS); | |
| timeline.goto(nextTick); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This shows 2 useful methods:
The png sequence saving can only be done when publishing an AIR app, so this may only be useful when you need a sequence saved out for use in something such as a video.