String to actual actionscript code

Greetings,

I was wondering if the following situation would be possible:

imagine having a string like

var query:String = “Object.property.toString() == somevalue.toString()”;

and that the string somehow could be converted to actual actionscript code…

if(query){
trace(“your actionscriptquery worked”);
}
else{
trace(“your actionscriptquery did not worked”);
}

thanks!

That used to be done by the eval() function, but eval is evil and was later deprecated and subsequently removed from the language. I’m not aware of any replacements for AS3, but trying to dynamically evaluate AS code is not an ideal situation :slight_smile:

Why not just assign the result of that logical statement to a variable and test against that, anyway?

Or even more to the point, just write it in the if statement. If you have ifs that only have if (variable) and the actual logic is some hundred lines away… not good for code readability :slight_smile:

if(object.hasProperty(query)) {

Sorry Felixz an object doesn’t have the hasProperty-method.

Object.hasOwnProperty()