Skip to content

Instantly share code, notes, and snippets.

@dpeek
Last active December 30, 2015 21:09
Show Gist options
  • Select an option

  • Save dpeek/7885802 to your computer and use it in GitHub Desktop.

Select an option

Save dpeek/7885802 to your computer and use it in GitHub Desktop.
hscript callbacks
// compile with:
// haxe -main Test -swf test.swf -lib hscript
class Test extends flash.display.Sprite
{
static function main() flash.Lib.current.addChild(new Test());
function new()
{
super();
// draw something to click
graphics.beginFill(0xFF, 1);
graphics.drawRect(0, 0, 100, 100);
// this is your users script
var script = "function(e) { trace('do something'); })";
// parse your user script
var parser = new hscript.Parser();
var ast = parser.parseString(script);
var interp = new hscript.Interp();
var callback = interp.execute(ast);
addEventListener(flash.events.MouseEvent.CLICK, callback);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment