1

I have a set of ~5 ActionScript 3 classes that are currently used within a flex 4 application. Although their output is used to display graphs etc in my flex app, the classes themselves have no visual components - they are only used to do complex math computations (I originally implemented them in AS3 in order to avoid constant server calls when computations were needed by the flex app).

However, I now want to make the same mathematical computation engine available on my linux server so the computations can be done within PHP. Is there any way at all to access the logic in these classes on the server? I would really like to avoid re-implementing the complex logic in PHP.

Thanks so much for any help you can give!

  • If you want to execute your logic on the server, you are going to have to write in a language that the server can use. – afuzzyllama Oct 12 '11 at 00:29

2 Answers2

0

How many lines of code in your AS3 classes, and what kind of load do you need to handle?

If you're building anything for more than one-off use then the easiest route is probably porting your ActionScript to JavaScript. There aren't any automated converters that I know of but JavaScript and AS3 are so similar that unless your five classes have thousands of lines of code you should be able to make short work of it. Once you've ported it to JavaScript it'll be trivial to run in Node.js, directly through the VM of your choice, or even in the user's browser.

If you only need this to scratch and itch or for limited use you may be able to get away with running AS3 directly in Tamarin or redtamarin. However as far as I know neither of these are currently suitable for production use.

If you are using this in a high-availability, high traffic PHP app, however, I think you'll experience a lot less pain in the long run just porting your code to PHP. AS3 and PHP are similar enough in syntax that you could probably just do a straight port.

Finally, you can find some further discussion and links in this thread: Is it possible to create a 'command line' swf?

Community
  • 1
  • 1
Jordan Running
  • 102,619
  • 17
  • 182
  • 182
  • Thank you so much for all the info. The code is in fact thousands of lines long. To make matters worse it will be continually updated in the AS3 version and I don't want to have to maintain 2 versions. The code uses fairly simple computational instructions - just a lot of them, so I'm going to see if I can make it work with Tamarin. – Nick DeLong Oct 12 '11 at 16:02
  • I just wanted to post an update: I was able to get redtamarin to work perfectly for this use. I had to make a few very minor changes to my code to make it redtamarin compatible, but those changes don't hurt the original operation in flex. So I now have a fully operational code base that can run on either client or server - exactly what I wanted! Thanks so much for pointing me in the right direction! – Nick DeLong Oct 14 '11 at 18:39
  • Nice! Glad you could sort it out. – Jordan Running Oct 14 '11 at 19:02
0

You can use redtamarin

http://code.google.com/p/redtamarin/

from a Linux server standpoint you will be able to run your AS3 source code as CGI (either the AS3 script directly or compiled as ABC)

or you can also bundle your AS3 code into an exe that you will then call via PHP

or make your AS3 script as executable with binfmt_misc

http://code.google.com/p/redtamarin/wiki/RunningShellScripts#Registering_an_extension_as_non-native_binaries_(Linux_only)

here on production and development servers we use redtamarin

  • as scripts, to do our SVN hooks, automate tasks on linux servers etc.
  • as socket servers, http servers and CGI
  • as executable to reuse AS3 logic into our automated builds
  • etc.

look a bit in the documentation you will see you have a lot of options to reuse your AS3 code: stdin/stdout/stderr, sockets, pipes, CGI, etc.

zwetan
  • 86
  • 3