I'm looking the AS3 equivalent of the following JavaScript code:
var funcName = "foo();"
var fHandler = new Function("a",funcName + "return a + 1");
fHandler // now equals a function like function(a){ foo(); return a + 1 }
Ok, it's a very simplified example
The bigger picture is:
I have a server that works with a JavaScript Client. Every response this server gives, is a callback to a JavaScript function, providing as arguments the server's response.
As such, it does not use the combersome strict JSON protocol (with quote around attribute names that do not require such quotes to be valid Object-Literal, and so on few other minor differences that would still be a valid Object-Literal in AS3 ), and the server implements over 100 APIs already.
However, now there's a request to produce an Air client for mobile devices.
If I could just do the following - it would be great.
It's valid EMCA script, but does not pass for AS3
public function responseFromServer(String:s){
s = chopCallbackWrap(s); //strips the 'myCallback(' and ')' parts
//s is now always a string describing a valid Object-Literals not necessarily JSON
return new Function("", " return " + s ) ();
}
Another aspect is processing in a generic client algorythms distributed on the fly from the server
What is the way to do it in AS3?