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!

Comments

Anonymous says, "Flash CS4"
Anonymous's picture

I can't get it to compile in Flash CS4, it gives me the following error:
5000: The class 'r1.deval.D' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
Do you have any pointers about what I could do?

daniel says, "Error 5000 with D.eval"
daniel's picture

Hi Anonymous,

Are you linking the D class to a symbol in the library? That's the only way I can think to cause that error and you don't need to do that. If you're trying to make sure the library gets compiled, you just need to import it and use the class in your Actionscript code somewhere.

Anonymous says, "I drag 'D' from the"
Anonymous's picture

I drag 'D' from the components window to the library, and then on frame 1, y type "import r1.deval.D". That worked in CS3, am I doing something wrong?
If I don't drag it to the library, I get the error "1172: Definition r1.deval:D could not be found." both in CS3 and CS4.

daniel says, "eval.D problem"
daniel's picture

Hi Anonymous,
Not sure why it's behaving that way but I'd check with the D.eval folks directly.

Anonymous says, "issues with dynamically generated functions"
Anonymous's picture

dynamically generated functions used by D.eval doesnt seem to be real functions that addEventListener can use as feedbacks.

Post new comment

The content of this field is kept private and will not be shown publicly.
If you have a Gravatar account, used to display your avatar.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You can enable syntax highlighting of source code with the following tags: <code>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

About

Daniel McLaren

Daniel is a Flash and Flex developer specializing in the art of information visualization.

Latest from SketchyD

Latest Drawing from SketchyD

This is the most recent drawing from my mobile sketch blog, SketchyD.com.

Recent comments