forked from: flash on 2013-3-1

by ohisama forked from flash on 2013-3-1 (diff: 18)
♥0 | Line 96 | Modified 2013-03-01 11:52:16 | MIT License | (replaced)
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/czip
 */

// forked from ohisama's flash on 2013-3-1
package
{
    import flash.display.*;
    import flash.events.*;
    import flash.net.*;
    import flash.system.*;
    import flash.utils.*;
    import com.codeazur.as3swf.*;
    import com.codeazur.as3swf.data.*;
    import com.codeazur.as3swf.tags.*;
    import com.bit101.components.*;
    public class FlashTest extends Sprite
    {
        private static const CODE : String =
            "use namespace 'flash.display';\n" +
            "use namespace 'flash.text';\n" +
            "class Movie extends Sprite\n" +
            "{\n" +
            "    public function Movie()\n" +
            "    {\n" +
            "        var r : Array = [];\n" +
            "        for (var i : int = 1; i <= 100; i++)\n" +
            "        {\n" +
            "            var res : String = '';\n" +
            "            if (i % 3 == 0) res += 'Fizz';\n" +
            "            if (i % 5 == 0) res += 'Buzz';\n" +
            "            if (res.length == 0) res += i.toString();\n" +
            "            r.push(res);\n" +
            "        }\n" +
            "        var t : TextField = new TextField();\n" +
            "        t.text = r.join(', ');\n" +
            "        t.autoSize = TextFieldAutoSize.LEFT;\n" +
            "        t.wordWrap = true;\n" +
            "        t.width = 150;\n" +
            "        addChild(t);\n" +
            "    }\n" +
            "}";
        private var compileStringToBytes : Function;
        private var code : Text;
        private var swf : SWF;
        private var movie : Loader;
        private var data : SWFData;
        public function FlashTest()
        {
            code = new Text(this, 5, 5, CODE);
            code.width = 250;
            code.height = 350;
            addChild(code);
            new PushButton(this, 260, 340, 'make swf', compile);
            movie = new Loader();
            movie.x = 260;
            movie.y = 10;
            addChild(movie);
            var ul : URLLoader = new URLLoader;
            ul.dataFormat = URLLoaderDataFormat.BINARY;
            ul.addEventListener(Event.COMPLETE, loadESC);
            ul.load(new URLRequest("http://assets.wonderfl.net/images/related_images/3/3d/3d72/3d721c692ee6ca816bac3cb996e82a2329c725a2"));
        }
        private function loadESC(e : Event) : void 
        {
            var ul : URLLoader = e.target as URLLoader;
            ul.removeEventListener(Event.COMPLETE, loadESC);
            var data : ByteArray = new ByteArray;
            data.writeBytes(ul.data, 42, ul.data.length - 42);
            var l : Loader = new Loader();
            l.contentLoaderInfo.addEventListener(Event.COMPLETE, completeESC);
            l.loadBytes(data, new LoaderContext(false, ApplicationDomain.currentDomain));
        }
        private function completeESC(e : Event) : void
        {
            compileStringToBytes = ApplicationDomain.currentDomain.getDefinition('ESC.compileStringToBytes') as Function;
        }
        private function compile(e : MouseEvent) : void
        {
            swf = new SWF();
            swf.version = 9;
            swf.frameSize.xmax = 1000;
            swf.frameSize.ymax = 1000;
            swf.frameRate = 30;
            swf.compressed = false;
            swf.tags.push(new TagFileAttributes());
            swf.tags.push(null);
            var tsc : TagSymbolClass = new TagSymbolClass();
            tsc.symbols.push(SWFSymbol.create(0, 'Movie'));
            swf.tags.push(tsc);
            swf.tags.push(new TagShowFrame());
            swf.tags.push(new TagEnd());
            var abc : ByteArray = compileStringToBytes(code.text, 'Movie.as');
            swf.tags[1] = TagDoABC.create(abc, '', false);
            data = new SWFData();
            swf.publish(data);
            movie.unloadAndStop();
            movie.loadBytes(data);
        }
    }
}

Forked