# String to actual actionscript code

**URL:** https://forum.kirupa.com/t/string-to-actual-actionscript-code/263445
**Category:** Uncategorized
**Created:** [June 16, 2008, 9:25am UTC](https://forum.kirupa.com/t/string-to-actual-actionscript-code/263445 "2008-06-16T09:25:48Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Lone\_wolf](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@Lone\_wolf](https://forum.kirupa.com/u/Lone_wolf)
#### Post date: [June 16, 2008, 9:25am UTC](https://forum.kirupa.com/t/string-to-actual-actionscript-code/263445/1 "2008-06-16T09:25:48Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![dthought](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/dthought/32/3573_2.png) [@dthought](https://forum.kirupa.com/u/dthought)
#### Post date: [June 16, 2008, 12:31pm UTC](https://forum.kirupa.com/t/string-to-actual-actionscript-code/263445/2 "2008-06-16T12:31:36Z")

</div>

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 🙂

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 🙂

---

<div class="post-metadata">

### Author: ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)
#### Post date: [June 16, 2008, 5:12pm UTC](https://forum.kirupa.com/t/string-to-actual-actionscript-code/263445/3 "2008-06-16T17:12:57Z")

</div>

```auto
if(object.hasProperty(query)) {

```

---

<div class="post-metadata">

### Author: ![Lone\_wolf](https://avatars.discourse-cdn.com/v4/letter/l/839c29/32.png) [@Lone\_wolf](https://forum.kirupa.com/u/Lone_wolf)
#### Post date: [June 16, 2008, 8:26pm UTC](https://forum.kirupa.com/t/string-to-actual-actionscript-code/263445/4 "2008-06-16T20:26:02Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)
#### Post date: [June 17, 2008, 2:49pm UTC](https://forum.kirupa.com/t/string-to-actual-actionscript-code/263445/5 "2008-06-17T14:49:36Z")

</div>

```auto
Object.hasOwnProperty()

```
