You are hereBlogs / daniel's blog / Using D.eval for Actionscript Evaluation in Flash CS3
Using D.eval for Actionscript Evaluation in Flash CS3
Not too long ago I posted about executing Actionscript 3.0 at runtime using Hurlant's eval library. I had used it successfully in a Flex project and was quite happy with the results. However, it turns out the awesomeness doesn't translate to Flash.
It was Tor Damian who pointed out that the library generates compiler errors in Flash. After spending a bit of time trying to resolve them I gave up.
Eventually, I poked around a bit more and found D.eval, an alternative which I somehow missed in the first round.
This library is distributed as freeware and does a great job of processing the bit of Actionscript I've had a chance to test with it. It also has a built-in method for passing data around: the eval() method receives a context object and a this object as parameters.
Unfortunately, it doesn't have try ... catch ... finally support (v1.1 at time of writing). I think this is pretty important for handling runtime errors that could appear in the custom code but it might be possible to catch the error outside the dynamic code and give error feedback there.
Another great feature is the ability to store a program and execute it later. This is especially useful if you need to execute a program several times using different inputs. You only have to parse the expression once and then you can run it over and over again using different this objects.
It looks like D.eval is still well-maintained—another bonus. I'll definitely be using this library more in future projects. Thanks to the folks at RiaOne!
