forked from: flash on 2012-9-4
forked from flash on 2012-9-4 (diff: 311)
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/14pg
*/
// forked from yurij.shaulov's flash on 2012-9-4
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" +
"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 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()
{
log = new Text(this, 260, 235, 'Please Wait\n');
log.editable = false;
log.width = 200;
log.height = 225;
//msg("ok\n");
//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());
//trace('ESC Compiler Boot Complete');
//var p : Panel = new Panel(this, 260, 5);
//p.width = 200;
//p.height = 200;
code = new Text(this, 5, 5, CODE);
code.width = 250;
code.height = 205;
new PushButton(this, 260, 210, 'compile', compile);
movie = new Loader();
movie.x = 260;
movie.y = 5;
addChild(movie);
}
private function msg(...args) : void
{
log.textField.appendText(args.join(' ') + '\n');
log.textField.scrollV = log.textField.maxScrollV;
}
private function compile(e : MouseEvent) : void
{
//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);
}
}
}