7 Replies Latest reply on Jan 25, 2010 12:30 PM by NewFlasherFromKS

    Language experts: Port Java Code to AS3?

    NewFlasherFromKS

      Hello out there,

      I have been asked whether it would be feasable to translate Java code to AS3. This is a bit difficult since I am not really an expert in Java and only a beginner wrt AS3. Looking at some code samples it seems doable (at least in principle), but of course there might be hidden gotchas lurking. Hence:

      - Are there Java features which do not have an equivalent in AS3?

      - Does AS3 have prerequisites which do not exist in Java?

      - Other aspects to consider?

       

      Any comment or advice will be greatly appreciated.

      Best regards

      H.

        • 1. Re: Language experts: Port Java Code to AS3?
          Stefan Horochovec Level 2

          Hello, nice to meet you!

           

          Your objective if create something to translate java code to action script? Well, i work in a project and development a software to translate, but the software dont work to screens, just work for models.

           

          Why? Because the concept of this tecnologies is diferent.

          • 2. Re: Language experts: Port Java Code to AS3?
            Sebastien V. Level 3

            A few things that are available in Java but not in AS3 :

            - Abstract classes and methods

            - Methods overload (including multiple constructors)

            - Private constructors (for singletons for instance)

             

            There's probably more, but this shows that the translation might not be as simple as it seems... Even if there are known workarounds for those lacks in AS3.

            1 person found this helpful
            • 3. Re: Language experts: Port Java Code to AS3?
              pauland Level 4

              Don't forget the class libraries are different..

               

              I think the converter would be quite an undertaking. Adobe did make a C++ to Actionscript conversion, but I'm not sure it ever made prime time. If I remember they were able to run Quake without sound.

              1 person found this helpful
              • 4. Re: Language experts: Port Java Code to AS3?
                Sebastien V. Level 3

                I also forgot that there are no such things as java's wrappers in AS3... No null Boolean for instance...

                • 5. Re: Language experts: Port Java Code to AS3?
                  NewFlasherFromKS Level 1

                  Thanks to you all.

                  In the meantime I read "Actionscript for Java developers"

                       http://www.javaworld.com/javaworld/jw-02-2009/jw-02-actionscript1.html

                  and it seems like the two languages are not too far apart.

                  Of course there are differences, but we only need to consider those features which Java has and AS has not (like method overloading) and modify our Java sources to not use these. Since the goal is not to have a universal tool which translates _any_ kind of Java source to AS but only our specific code base I think it will be worth a small effort to test how far we get with a machine translation.

                  Yes, libraries may well be an issue - but again, I would have to see which (library) functions are actually used and how to replace them.

                  Thanks again and best regards

                  H.

                  • 6. Re: Language experts: Port Java Code to AS3?
                    msakrejda Level 4

                    I think another of the  potential stumbling blocks may be ActionScript's single-threaded, event-oriented nature. In Java, you can do whatever you want in a blocking manner. That's not the case in ActionScript--for some things (e.g., remote calls), you have no choice but to wait for a result event. I think this is actually a strength in ActionScript, but it's a different model and it could be hard to adapt if, e.g., you have RPC code all over the place (which one hopes you wouldn't anyway).

                     

                    Good luck; it sounds like an exciting project.

                    • 7. Re: Language experts: Port Java Code to AS3?
                      NewFlasherFromKS Level 1

                      Hi,

                      fortunately this won't be an issue. Our Java program is "pure logic" - think of a list of cities (and their geographical coordinates), a list which of these cities to visit, and the question: What would be the optimal route?

                      Note: This is an example (because it's somewhat easier to present than what we are doing) - I am certainly not claiming that we are able to solve the 'Traveling Sales Man' problem.

                      Still, thanks for considering this aspect.

                       

                      As for the 'exciting project': Here is hoping I won't get too much of it.

                      Best regards

                      H.