Reputation: 4627
I am trying to convert some pre-existing html/JavaScript files to Flex. I tried making some research to see if there was any compiler that compiles code from javascript to actionscript. As far as I can see, there are many ways to transform actionscript to javascript, but I couldn't find any for the other way around. Does anyone know if there is a way to do that, or should I just write my own tool?
Upvotes: 2
Views: 3837
Reputation: 12527
I think you will find this will not work well, as AS3 is a strict-typed language, and Javascript is not. Even if such a compiler exists, your ActionScript will likely have problems from the fact that it would create a bunch of generic object.
In short: ActionScript to Javascript works, because Javascript is more permissive, but a lot of structure is lost. Inheritance, Type, etc.
But to go the other way, there is no way to add back in the structure required by ActionScript.
As one of the commenters mentioned, you may need to do this conversion by hand.
One other idea: the Flash player can talk to Javascript. There may be no need to convert the Javascript to ActionScript, instead just create a few functions to talk to the Flash SWF file through its ExternalInterface class. Just keep the Javascript in Javascript.
Upvotes: 7
Reputation: 2111
I highly suggest a complete rewrite, it won't take much time since both of them (JS & AS) are ECMA standard languages (correct me if I'm wrong)
But if you really need an automated way, Try:
It's the easiest solution on top of my mind.
Upvotes: 4
Reputation: 2591
You're better off writing your own tool. There are so many different ways to write javascript, and including the fact that it's untyped, it would be difficult to write a be-all end-all solution that converts everything. If it's a library, it might make more sense to convert opcodes rather than code-to-code, but so much of it depends on how the javascript was written.
It's going to be a pain, that's for sure.
Upvotes: 2