Actionscript:
-
var txt:TextField = TextField(addChild(new TextField()));
-
txt.autoSize = TextFieldAutoSize.LEFT;
-
-
var myVar:Number = 100;
-
// works as an expression parser
-
txt.text = js("return (" + myVar + " * 2 + 10) / 2");
-
txt.appendText("\n\n");
-
-
// parses javascript
-
txt.appendText(js("var a = []; for (var i = 0; i<10; i++){ a.push(i) } return a;"));
-
-
function js( data:String ):*{
-
var res:*= ExternalInterface.call("function(){" + data + "}");
-
return (res == null) ? "null" : res;
-
}
This one made my day - CAN'T believe I never thought of it before... haven't done any speed tests yet... but it shows how to use ExternalInterface.call to parse math expressions and javascript code. This will only work when the swf is shown in an html page of course... so if your in flash cmd+f12...
I got the idea from this code snippet... which actually has an error in it... the decode() function should not return void... I found that snippet thanks to this tweet by makc3d.