views:

392

answers:

2

I'm involved in writing a Flex/ActionScript library and in the future I will be involved in writing the same library in JavaScript. Rather than writing a library in each language and having to maintain them separately I was wondering if it was possible to:

1) Write the code in one language and share the code into the other e.g. Write the code in JavaScript and use the same .js files in ActionScript

or

2) Write the code in one language and perform a conversion into the other

I know it's possible to communicate between Flash/ActionScript and JavaScript but I'd like to avoid the overheads in using the technology bridge so this isn't really an option.

How do other people deal with writing and maintaining libraries that do exactly the same thing but in different languages? Specifically how do people do this between JavaScript and ActionScript?

+1  A: 

How about haXe.

You write the code in one language and they can compile it into various forms, including JavaScript files and compiled flash (versions 6-10). They even recently started supporting C++ compilation.

This would allow you to have the same source code (pre-compilation) for both your JS and AS3 projects.

(Noticed it when FlashDevelop started supporting it)

Glenn
It looks like the only way to do this without duplicating code is to use a code converter of some sort. Whether it be a JavaScript to ActionScript, ActionScript to JavaScript or some other language (haXe) to ActionScript/JavaScript.So, "write the code in one language and they can compile it into various forms" seems the only approach at the moment.
leggetter
A: 

PureMVC does this quite well. The reference implementation is written in AS3, and the ports (including the JS version) are maintained based off this implementation. It would be non-trivial to write a converter, and it would likely be simpler to maintain the separate versions.

Joel Hooks