"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Tuesday, April 24, 2007

Actionscript Loses Eval

Like Javascript, previous versions of Actionscript had eval(). The latest, Actionscript 3.0, does not.

Peter Fisk's Smalltalk and Lisp in Flex is a treasure in its own right. But in light of Adobe taking away eval(), the desire to have some kind of language interpreter at runtime goes exponential.

I could do with evaluating Actionscript at runtime. There are legitimate reasons to have a fairly-Javascript-like language for customizing interactive applications, although Lisp and Smalltalk appeal to me more, personally.

But Adobe appears intent to make Actionscript as much a static language as possible, and one that has a fairly strict boundary between development-time and run-time. Sadly.

I don't think this can or should be chalked up to security. There are better solutions to security than to throw out run-time evaluation altogether.

Oh well. As Peter has demonstrated, reflection still works fine, so you just build your own eval() for whatever language you desire.


Rich Dougherty said...

My understanding - although I've never actually tested this - is that eval() in ActionScript has always been more limited than in JavaScript. As I understand, ActionScript's eval() doesn't really provide anything more than what you can get by using subscripts to dynamically access member variables.

In ActionScript you can do this:

eval("myobject.property"+x) = 4;

but not this:


(I first read about ActionScript's eval() elsewhere, but I refer to Wikipedia: http://en.wikipedia.org/wiki/Eval#ActionScript)


Bob Ippolito said...

Rich is correct. ActionScript's eval(name) has always been little more than shorthand for this[name] with dot expansion and searching of a few different namespaces. It has never and will never actually interpret code, ActionScript is compiled down to a very simple stack based bytecode with a VM that has no idea what ActionScript syntax looks like. ActionScript effectively has as much business eval'ing ECMAScript code as PostScript does.

Simplicus said...

If you really need to evaluate a string to a numeric result, use the externalInterface to call a javaScipt function in your HTML wrapper. Pass it the string to be evaluated. The javaScript function takes the string as a parameter, and is a one liner:
(in its own script tag)

function myEval(str)
return eval(str);

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.