Skip to content

Instantly share code, notes, and snippets.

@nitoyon
Created Oct 13, 2012
Embed
What would you like to do?
ure ActionScript SWF capture demo 2
<?xml version="1.0" encoding="utf-8" ?>
<application xmlns="http://ns.adobe.com/air/application/2.6">
<id>HelloSpace</id>
<filename>Foo</filename>
<name></name>
<versionNumber>1.0.0</versionNumber>
<initialWindow>
<content>Foo.swf</content>
<systemChrome>standard</systemChrome>
<visible>true</visible>
</initialWindow>
</application>
package{
import flash.display.*;
import flash.events.Event;
import flash.text.*;
import flash.filters.*;
import flash.geom.*;
import caurina.transitions.Tweener;
[SWF(width=640, height=360)]
public class Foo extends Sprite{
private var bd:BitmapData;
public function Foo():void{
PngOutput.init(stage);
x = 100; y = 10;
var tf:TextField = new TextField();
tf.textColor = 0x000000;
tf.text = "Hello\nWorld!!!";
tf.autoSize = "left";
bd = new BitmapData(tf.width, tf.height, false, 0x3399ff);
bd.draw(tf);
bd.applyFilter(bd, bd.rect, new Point(), new BlurFilter());
bd.draw(tf);
for(var i:int = 0; i < bd.width; i++){
for(var j:int = 0; j < bd.height; j++){
Tweener.addTween(
randomize(addChild(new Circle(bd.getPixel(i, j)))),
{
x: i * 10,
y: j * 10,
alpha: 1,
delay: (i + j) * .2 * (1 - Math.pow(Math.random(), 1.7)),
time: 1
}
);
}
}
addEventListener("enterFrame", function(e:Event):void{
PngOutput.output();
});
}
private function randomize(d:DisplayObject):DisplayObject{
d.x = 400 * Math.random();
d.y = 300 * Math.random();
d.alpha = 0;
return d;
}
}
}
import flash.display.Sprite;
class Circle extends Sprite{
public function Circle(color:uint):void{
graphics.beginFill(color);
graphics.drawCircle(0, 0, 6);
graphics.endFill();
}
}
package{
public function getTimer():int{
return PngOutput.getTimer();
}
}
package {
import flash.display.*;
import flash.filesystem.File;
import flash.filesystem.FileStream;
import mx.graphics.codec.PNGEncoder;
public class PngOutput{
private static var stage:Stage;
private static var count:int;
private static var bmd:BitmapData;
public static function init(_stage:Stage):void{
stage = _stage;
count = 0;
bmd = new BitmapData(stage.stageWidth, stage.stageHeight, false, 0);
}
public static function output():void{
// get file
var file:File = new File("c:/movie/" + getFilename(count));
// draw
bmd.fillRect(bmd.rect, 0xffffff);
bmd.draw(stage);
// output
var fs:FileStream = new FileStream();
fs.open(file, "write");
fs.writeBytes(new PNGEncoder().encode(bmd));
fs.close();
count++;
}
private static function getFilename(count:int):String {
var ret:String = count.toString();
while (ret.length < 5) { ret = "0" + ret; }
return ret + ".png";
}
public static function getTimer():int {
return count * 1000 / stage.frameRate;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment