flash on 2013-1-30

by ohisama
import com.codeazur.as3swf.tags.TagDefineShape;
import com.codeazur.as3swf.tags.TagFileAttributes;
import com.codeazur.as3swf.data.SWFMatrix;
import com.codeazur.as3swf.tags.TagEnd;
[SWF(width=465, height=465, frameRate=30, backgroundColor=0x000000)]
♥0 | Line 118 | Modified 2013-01-31 20:57:25 | MIT License
play

ActionScript3 source code

/**
 * Copyright ohisama ( http://wonderfl.net/user/ohisama )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/6cGM
 */

package
{
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.Loader;
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.utils.ByteArray;
    import com.codeazur.as3swf.SWF;
    import com.codeazur.as3swf.SWFData;
    //import com.codeazur.as3swf.tags.TagDefineShape;
    //import com.codeazur.as3swf.tags.TagFileAttributes;
    import com.codeazur.as3swf.tags.TagPlaceObject;
    //import com.codeazur.as3swf.data.SWFMatrix;
    import com.codeazur.as3swf.tags.TagShowFrame;
    //import com.codeazur.as3swf.tags.TagEnd;
    import com.codeazur.as3swf.tags.TagSetBackgroundColor;
    import com.codeazur.as3swf.tags.TagDefineBitsLossless;
    import com.codeazur.as3swf.tags.TagDefineBitsLossless;
    import com.codeazur.as3swf.tags.TagDefineShape;
    import com.codeazur.as3swf.tags.TagEnd;
    import com.codeazur.as3swf.tags.TagFileAttributes;
    import com.codeazur.as3swf.tags.TagPlaceObject2;
    import com.codeazur.as3swf.tags.TagRemoveObject2;
    import com.codeazur.as3swf.tags.TagSetBackgroundColor;
    import com.codeazur.as3swf.tags.TagShowFrame;
    import com.codeazur.as3swf.data.SWFFillStyle;
    import com.codeazur.as3swf.data.SWFMatrix;
    import com.codeazur.as3swf.data.SWFRectangle;
    import com.codeazur.as3swf.data.SWFShapeRecordEnd;
    import com.codeazur.as3swf.data.SWFShapeRecordStraightEdge;
    import com.codeazur.as3swf.data.SWFShapeRecordStyleChange;
    import com.codeazur.as3swf.data.SWFShapeWithStyle;
    import com.codeazur.as3swf.data.consts.BitmapFormat;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    //[SWF(width=465, height=465, frameRate=30, backgroundColor=0x000000)]
    public class CreateSWF extends Sprite
    {
        private const w : Number = 320;
        private const h : Number = 240;
        private const wt : Number = w * 20;
        private const ht : Number = h * 20;
        //protected static const SHAPE_CHARACTER_ID : uint = 1;
        public function CreateSWF()
        {
            super();
            //graphics.beginFill(0xfff000);
            //graphics.drawRect(0, 0, 465, 465);
            //var swf : SWF = new SWF(loaderInfo.bytes);
            //var shape : TagDefineShape = swf.getCharacter(SHAPE_CHARACTER_ID) as TagDefineShape;

            var swf : SWF = new SWF();
            swf.frameSize.xmax = 320 * 20;
            swf.frameSize.ymax = 240 * 20;
            //swf.compressed = true;
            swf.version = 9;
            swf.frameRate = 1;
            swf.tags.push(new TagFileAttributes());
            swf.tags.push(new TagSetBackgroundColor());
            //var bitsLossless : TagDefineBitsLossless = new TagDefineBitsLossless();
            //bitsLossless.characterId = bitmapId;
            //bitsLossless.bitmapFormat = BitmapFormat.BIT_24;
            //bitsLossless.bitmapWidth = w;
            //bitsLossless.bitmapHeight = h;
            //bitsLossless.zlibBitmapData.writeBytes(_files[i].getPixels(new Rectangle(0, 0, w, h)));
            //bitsLossless.zlibBitmapData.compress();
            //swf.tags.push(bitsLossless);
            var shape : TagDefineShape = new TagDefineShape();
            shape.characterId = 1
            shape.shapeBounds = new SWFRectangle();
            shape.shapeBounds.xmin = 0;
            shape.shapeBounds.ymin = 0;
            shape.shapeBounds.xmax = 500;
            shape.shapeBounds.ymax = 500;
            shape.shapes = new SWFShapeWithStyle();
            var fillStyle : SWFFillStyle = new SWFFillStyle();
            fillStyle.type = 0x42;
            fillStyle.bitmapId = 1;
            fillStyle.bitmapMatrix = new SWFMatrix();
            fillStyle.bitmapMatrix.scaleX = 20;
            fillStyle.bitmapMatrix.scaleY = 20;
            shape.shapes.initialFillStyles.push(fillStyle);
            var styleChange : SWFShapeRecordStyleChange = new SWFShapeRecordStyleChange();
            styleChange.stateFillStyle1 = true;
            styleChange.fillStyle1 = 1;
            shape.shapes.records.push(styleChange);
            var edge : SWFShapeRecordStraightEdge = new SWFShapeRecordStraightEdge();
            edge.generalLineFlag = false;
            edge.vertLineFlag = false;
            edge.deltaX = 500;
            edge.deltaY = 0;
            shape.shapes.records.push(edge);
            edge = new SWFShapeRecordStraightEdge();
            edge.generalLineFlag = false;
            edge.vertLineFlag = true;
            edge.deltaX = 0;
            edge.deltaY = 500;
            shape.shapes.records.push(edge);
            edge = new SWFShapeRecordStraightEdge();
            edge.generalLineFlag = false;
            edge.vertLineFlag = false;
            edge.deltaX = -500;
            edge.deltaY = 0;
            shape.shapes.records.push(edge);
            edge = new SWFShapeRecordStraightEdge();
            edge.generalLineFlag = false;
            edge.vertLineFlag = true;
            edge.deltaX = 0;
            edge.deltaY = -500;
            shape.shapes.records.push(edge);
            shape.shapes.records.push(new SWFShapeRecordEnd());
            swf.tags.push(shape);
            var removeObject : TagRemoveObject2 = new TagRemoveObject2();
            removeObject.depth = 1;
            swf.tags.push(removeObject);
            var placeObject : TagPlaceObject2 = new TagPlaceObject2();
            placeObject.depth = 1;
            placeObject.characterId = 1;
            placeObject.hasCharacter = true;
            placeObject.hasColorTransform = false;
            swf.tags.push(placeObject);
            swf.tags.push(new TagShowFrame());
            swf.tags.push(new TagEnd());
            swf.frameCount = 1;
            //var shape : TagDefineShape = new TagDefineShape();
            //shape.characterId = 2;
            //shape.shapeBounds = new SWFRectangle();
            //shape.shapeBounds.xmin = 0;
            //shape.shapeBounds.ymin = 0;
            //shape.shapeBounds.xmax = wt;
            //shape.shapeBounds.ymax = ht;
            //shape.shapes = new SWFShapeWithStyle();
            //var fillStyle : SWFFillStyle = new SWFFillStyle();
            //fillStyle.type = 0x42;
            //fillStyle.bitmapId = 2;
            //fillStyle.bitmapMatrix = new SWFMatrix();
            //fillStyle.bitmapMatrix.scaleX = 20;
            //fillStyle.bitmapMatrix.scaleY = 20;
            //shape.shapes.initialFillStyles.push(fillStyle);           
            //var swfTemp : SWF = new SWF();
            //swfTemp.tags.push(new TagFileAttributes());
            //swfTemp.tags.push(new TagSetBackgroundColor());
            //swfTemp.tags.push(shape);
            //var placeObject : TagPlaceObject = new TagPlaceObject();
            //placeObject.depth = 1;
            //placeObject.matrix = new SWFMatrix();
            //placeObject.hasCharacter = true;
            //placeObject.hasMatrix = true;
            //swfTemp.tags.push(placeObject);
            //swfTemp.tags.push(new TagShowFrame());
            //swfTemp.tags.push(new TagEnd());
            var ba : ByteArray = new ByteArray();
            swf.publish(ba);
            var loader : Loader = new Loader();
            loader.x = 20;
            loader.loadBytes(ba);
            addChild(loader);
            var tf : TextField = new TextField();
            tf.text = swf.toString();
            tf.width = tf.height = 400;
            addChild(tf);
        }
    }
}