In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

esc

build flash offline
Compile ES4 to ABC using ESC, from Mozilla Tamarin.
The following restrictions are hard coded:
- the document class is Movie
- 200x200 stage, 30 fps
Get Adobe Flash player
by wh0 12 Jun 2011
  • Related works: 3
  • Talk

    wh0 at 12 Jun 2011 10:43
    yo dawg...
    tehfailsafedesign at 03 Nov 2012 10:01
    great, but why restrcition 200x200? And where does that get set? I can't find the "hard coded" restriction anywhere...
    wh0 at 03 Nov 2012 11:53
    About the restriction: on Wonderfl, you'd typically use a metadata tag to set the movie size, but the esc compiler has no support for something like that. The size is hard coded on lines 121-122, in the unit of twips.
    tehfailsafedesign at 03 Nov 2012 23:47
    lines 121 and 122 set maxsize at 4000, how does that translate to a document size of 200x200? I'd love to use the esc compiler, but I can't figure this bit out. I would need to be able to set document to any size, or let the user input their own size via text entry.
    wh0 at 21 Feb 2013 09:53
    the 4000 is in twips, which is 1/20 of a pixel

    Tags

    Embed
/**
 * Copyright wh0 ( http://wonderfl.net/user/wh0 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2pBs
 */

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 PROXY:String = 'http://p.jsapp.us/proxy/';
        private static const BASE:String = 'http://hg.mozilla.org/tamarin-redux/raw-file/db3ebe261f68/esc/bin/';
        private static const ESC:Array = [
            'debug.es.abc',
            'util.es.abc',
            'bytes-tamarin.es.abc',
            'util-tamarin.es.abc',
            'lex-char.es.abc',
            'lex-token.es.abc',
            'lex-scan.es.abc',
            'ast.es.abc',
            'define.es.abc',
            'parse.es.abc',
            'asm.es.abc',
            'abc.es.abc',
            'emit.es.abc',
            'cogen.es.abc',
            'cogen-stmt.es.abc',
            'cogen-expr.es.abc',
            'esc-core.es.abc',
            'eval-support.es.abc',
            'esc-env.es.abc',
            'main.es.abc'
        ];
        private static const CODE:String =
            "use namespace 'flash.display';\n" +
            "class Movie extends Sprite {\n" +
            "\n" +
            "    public function Movie() {\n" +
            "        // write es4 code here..\n" +
            "        graphics.beginFill(0x000000);\n" +
            "        graphics.drawCircle(20, 20, 16);\n" +
            "    }\n" +
            "\n" +
            "}";
        
        private var progress:ProgressBar;
        private var loading:int = 0;
        private var esc:SWF;
        private var compileStringToBytes:Function;
        private var code:Text;
        private var log:Text;
        private var swf:SWF;
        private var movie:Loader;
        private var data:SWFData;
        
        public function FlashTest() {
            Security.loadPolicyFile('http://p.jsapp.us/crossdomain.xml');
            
            graphics.beginFill(0xf0f0f0);
            graphics.drawRect(0, 0, 465, 465);
            
            progress = new ProgressBar(this, 5, 5);
            progress.width = 455;
            progress.maximum = ESC.length;
            
            log = new Text(this, 260, 235, 'Loading... Please Wait...\n');
            log.editable = false;
            log.width = 200;
            log.height = 225;
            
            esc = new SWF();
            esc.version = 9;
            esc.frameSize.xmax = 0;
            esc.frameSize.ymax = 0;
            esc.frameRate = 0;
            esc.compressed = false;
            esc.tags.push(new TagFileAttributes());
            
            loadESC();
        }
        
        private function trace(...args):void {
            log.textField.appendText(args.join(' ') + '\n');
            log.textField.scrollV = log.textField.maxScrollV;
        }
        
        private function loadESC():void {
            progress.value = loading;
            if (loading >= ESC.length) {
                runESC();
                return;
            }
            var ul:URLLoader = new URLLoader(new URLRequest(PROXY + BASE + ESC[loading]));
            ul.dataFormat = URLLoaderDataFormat.BINARY;
            ul.addEventListener(Event.COMPLETE, function (e:Event):void {
                esc.tags.push(TagDoABC.create(ul.data));
                loading++;
                loadESC();
            });
        }
        
        private function runESC():void {
            esc.tags.push(new TagShowFrame());
            esc.tags.push(new TagEnd());
            var data:SWFData = new SWFData();
            esc.publish(data);
            esc = null;
            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;
            
            swf = new SWF();
            swf.version = 9;
            swf.frameSize.xmax = 4000;
            swf.frameSize.ymax = 4000;
            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());
            
            // clear();
            trace('ESC Compiler Boot Complete');
            
            var p:Panel = new Panel(this, 260, 5);
            p.width = 200;
            p.height = 200;
            
            removeChild(progress);
            progress = null;
            
            code = new Text(this, 5, 5, CODE);
            code.width = 250;
            code.height = 455;
            
            new PushButton(this, 260, 210, 'compile', compile);
            new PushButton(this, 360, 210, 'save', save);
            
            movie = new Loader();
            movie.x = 260;
            movie.y = 5;
            addChild(movie);
            
            compile(null);
        }
        
        private function compile(e:MouseEvent):void {
            // clear();
            trace('Compiling...');
            try {
                var abc:ByteArray = compileStringToBytes(code.text, 'Movie.as');
            } catch (e:Error) {
                trace(e);
            }
            
            swf.tags[1] = TagDoABC.create(abc, '', false);
            data = new SWFData();
            swf.publish(data);
            trace('Compile Complete (' + data.length + ' bytes)');
            
            trace('Reloading swf');
            movie.unloadAndStop();
            movie.loadBytes(data);
        }
        
        private function save(e:MouseEvent):void {
            if (!data) return;
            new FileReference().save(data, 'movie.swf');
        }
        
    }
}