# Using eval for +/- calculations (AS2)

**URL:** <https://forum.kirupa.com/t/using-eval-for-calculations-as2/258981>\
**Category:** Uncategorized\
**Created:** [April 30, 2008, 1:44am UTC](https://forum.kirupa.com/t/using-eval-for-calculations-as2/258981 "2008-04-30T01:44:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![returnButton](https://avatars.discourse-cdn.com/v4/letter/r/db5fbb/32.png) [@returnButton](https://forum.kirupa.com/u/returnButton)\
**Post date:** [April 30, 2008, 1:44am UTC](https://forum.kirupa.com/t/using-eval-for-calculations-as2/258981/1 "2008-04-30T01:44:13Z")

</div>

Hi… I wonder if someone could take a look at my code.

Basically I want to eval() a string like \_level0.mc.\_x-=dist; where the “-” or “+” is a variable.

You can paste this straight in and it should work… only the last part (where it’s doing the eval) doesn’t!!

Any ideas would be really appreciated:

```auto
 
this.createEmptyMovieClip("mc",this.getNextHighestDepth());
_level0.mc._x=200;
_level0.mc.createTextField("txt",_level0.mc.getNextHighestDepth(),0,0,200,200);
_level0.mc.txt.htmlText="text";
 
this.slide=function (mc, prop, dir, dist)
{ trace(eval(mc+"."+prop));// this returns 200 as expected
 trace(mc+"."+prop+dir+"=dist;");// this returns _level0.mc._x-=dist; which is the line I want to eval
 eval(mc+"."+prop+dir+"=dist;");// this DOESN'T eval it - any idea why?
 //_level0.mc._x-=dist;// this works!!
}
 
_level0.mc.onEnterFrame=function ()
{ _level0.slide("_level0.mc", "_x", "-", 3);
};
 

```
