Replacement for eval()

I’m creating a AIR app and need to arrive at the dot notation path of: air.File.userDirectory.resolvePath

in my function I’m passing in a where param
var where = ‘userDirectory’;

var f = eval(‘air.File.’+where+‘.resolvePath’)(file);
eval would normally work, but in AIR eval is not allowed.

Any other suggestions?

-s

Hurrah for AIR! Eval is evil.

YOu can use an array-index notation instead.


var f = air.File[where].resolvePath(file);

Brilliant!
I had tried

var f = alr.File.[where].resolvePath(file);

but found errors.

Thanks for the tip :slight_smile:

-s

Oh yeah, there’s an obvious mis-spelling there. alr should be air
Updated now.

jQuery.air.js plugin almost ready :slight_smile:

-s

pmw’s tip also applies to any EMCA (sp?) language like Actionscript, which I’m guessing you use at least occasionally if you’re working with Adobe Air.

Great thanks.
Its been a couple of years since I have coded any actionscript, but still occasionally find myself casting ie. var myString:String = ‘bla bla’;
as and js are first cousins and their compilers are the same.

-s

Strictly speaking, actionscript is compiled and javascript is interpreted. While actionscript has eval(), it is not a full code interpreter and cannot be used to evaluate arbitrary expressions. The reason for this lies within the fact that compiled languages (even partially compiled bytecode languages like actionscript or java) do not have a compiler present at runtime.