views:

268

answers:

2

Since Function is just another type I was wondering. Is it possible to serialize functions in actionscript 3.0?

A: 

Do you mean to serialize not just the pointer to the function, but the actual function contents and then send them to a remote machine? I do not believe you can do that, you would have to use some type of remoting to do something like that.

CookieOfFortune
Yes, I mean the actual function contents. Pack up the compiled AVM2 bytecode into a string, manipulate it runtime and de-serialize it into a new function.
Richard J. Terrell
errr yeah... don't think you can do that.
CookieOfFortune
+3  A: 

With AS3, Adobe gave us enough power to create, modify and run ByteCode at run-time. You can achieve a 'function serialization' using this runtime bytecode concept.

This can get pretty technical, but I recommend you to read about some libraries that should help you:

Libspark's swfassist

Hurlant's AS3Eval

I should also point that AS3Eval should be easier to understand -- swfassist have no english documentation, as far as I can tell. With AS3Eval you can modify code as a string and execute it at real-time, just like the old eval method.

Of course you can go hardcore style and implement a complex system on bytecode reading/serializing, but using such libraries would make it pretty simple.

MrKishi
Can you be a bit more specific? I am interested in how can I get the AVM2 bytecode of one of my function into a string, and how can I create a function using a bytecode from a string?
Richard J. Terrell