Wow, a post about programming! #GameDev #Computing #CAS

Unbelievably I’ve actually undertaken a little bit of programming recently. Well, maybe that’s a slight exaggeration because I did a fair bit of coding for the games programming enrichment course I ran over 6 weeks for Year 12 pupils during the last term. What perhaps I should have said is unbelievably I’ve actually undertaken a little bit of programming on personal projects recently.

Being the kind of chap who doesn’t want to learn anything new and ignoring the massive development-trending Elephant in the room I plunged back into Actionscript to begin to code my desktop client. What I needed was the ability to create a set of custom objects where each could have no, one or many custom functions attributed to them. I didn’t want to hardcode each object within AS using the standard var declaration, but instead evaluate (hint!) these on the fly from an imported data structure – in my case JSON.

I’d seen this elegantly done in Javascript – the natural partner of course to JSON, and I suspect that the same method could be achieved importing XML – but I hate XML with a passion and JSON’s declarations are far more legible and concise. Unfortunately the Javascript code relied on the use of the eval() function. Consider this:

<script language=”javascript”>
    eval(“function hi() { alert(‘hi’); }”);
<script language=”javascript”>

A very basic example, but nevertheless shows the runtime creation of a JS command and a JS function called hi. Very powerful stuff, just what I need!

BUT ActionScript 3 does not support eval.

I turned to Twitter, and the ever helpful devs pointed me towards the AS3 Eval Library located at

As much as I tried to mess with the code, I always ended up with the same error:

eval failed: ReferenceError: Error #1065: Variable compile is not defined.

According to a single post that I could find, the Tamarin ESC code hadn’t fully loaded. I restructured the code to place the eval() later in execution, and then on a button to ensure the interface had fully initialised but with no luck. In the end, I’ve given up! I’ve not the time to spend trying to track down the reason for the fail, it would be quicker for the scale of the project to hardcode the entire library of objects – or switch programming languages! Problem is, Actionscript/AIR has such a fast and easy workflow for simple mobile and desktop apps it is hard sometimes to look elsewhere.

I should really practise what I preach. Hmmm, wonder if Unity has an eval() function …






    1. Thanks for the comment.

      With AS3 complied into JIT bytecode in a similar vain to JS I hoped their may be some way. The two eval() libraries I’ve tried seem to promise this but neither work.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s