Based on this awesome tutorial video posted here: http://www.adobe.com/devnet/facebook/articles/video_facebook_quick_start.html using Flex Builder and Actionscript, i was able to replicate the functionality using FlashDevelop and haXe.
Here is the process i followed to accomplish this:
For details of what the code above does, i recommend viewing the video on the adobe site.
So i haven’t been working on Haxer too much lately, mostly because i’ve hit a wall as far how to best convert some AS3 code to Haxe without having to implement a full parser/lexer. The main area i am struggling with is converting “o is Object” and “o as Object” which sounds trivial at first, but when you look at the myriad of possible ways those statements can appear in code, it becomes a much more complex task.
In HaXe, the “is” operator/keyword/whatever it is, is written as “Std.is(obj, type)” and the “as” operator is written as “cast(obj, type)”. This presents quite a challenge when you have lines like this in AS3:
There are other, more complicated examples that make using regular expressions nearly impossible. I am open to a discussion as to how i might be able to implement such a conversion.
I’ve been trying to keep an up to date list of all the differences between AS3 and haXe when it comes to translating. Here is the list as it stands now:
If anyone knows of any other differences i should be aware of, please let me know in the comments. thanks.
So over the last few days i’ve been looking at the output that was being generated by my first attempt at writing an As3tohaxe translator. The results have been inconsistent to say the least. Not inconsistent in terms of different results everytime i ran it, but inconsistent within a file itself. Some variable definitions would get updated, while others would not. Some for loops would be translated, and others wouldn’t. Now normally it would be easy to step though the code and see why this is happening, but in haXe and neko there is no debugger. The only thing you can do is litter your code with println’s all over the place, which isn’t really all that helpful.
I thought it would be cool to write the program in the target language of its output, but given this rather significant shortcoming to the development environment, something more robust and mature is needed. Enter Java and Scala. Combined with IntelliJ (my favorite Java IDE) I’ve begun re-writting the program with the help of the built-in debugger. I thought it would be interesting to take this opportunity to learn Scala at the same time, but that is proving to be a bit challenging as Scala’s syntax flirts with both OO and Functional paradigms, it’s proving a bit difficult to wrap my head around. So for the time being the code is a mix of Scala and Java while i learn more about Scala and how to apply its strengths to this project. As Steve McConnell would say, you have to program into your language, not in it. What he means is using the features of the language you are writting in to make accomplishing your goals easier. Instead of applying the same algorithms and methodologies with just different syntax.
So with this new approach in mind i am now in the process of re-designing the program and will hopefully have some better results to report in a few days.
So lately i’ve been working on creating a more formal website for myself to highlight my design work and and show potential clients what i can do for them. This site is being built in Flash using FlashDevelop and the Flex SDK. I am not using the Flash IDE from Adobe at all. The entire site is being written in Actionscript 3, including the animations. The site will consist of three main sections: the marketing site which will contain my portfolio and services, the client portal which will be an area where clients can view the status of their project, keep track of how much time is being spent, communicate with the developers (currently only me), upload and view documents and a few other features yet to be determined. The third part will be the admin section where i can manage all of the clients logins, post updates, clock im hours that i have worked and so on.
The site is being powered on the back end by Ruby on Rails using a very basic REST api. So far the client portal is about 50% complete, which has been taking some time because i can including a few different types of charts and graphs that i am writing from scratch in AS3 which is needless to say time consuming.
The more i used AS3 the more i began to realize that although certain things about the language are nice (static/dynamic typing, ability to import SWC libraries), others felt a bit lacking (no generics, enums, anonymous types). I noticed that in FlashDevelop there was this other language called haXe that it supported. Intrigued, i looked it up and quickly read over the language reference and knew that this would be a great language to develop Flash projects in. I was especially glad to see that the bytecode generated by the haXe compiler for the flash vm is often times faster than the code generated by the Adobe compilers. This is especially important for flash game developers who would like to use the nice 3D engines that are available.
One such 3D engine, FFilmation (ffilmation.org) is open-source and looks rather nice at this point. I have been working on the design of an online game based on flash that this engine would work nicely in. The problem is, the engine is written in AS3, and of course i am going to be using haXe for this project. My first thought was to manually translate the AS3 code into haXe, but once i took a closer look at the source code and it’s many files and all the work i would have to do to make the translation i thought there must be a better way. I looked online for an as3tohaxe converter and found only one that seems like it could work. When i ran this converter on the ffilmation directory, it did indeed spit out .hx files, but there was only the most basic of transformations made (basically converting void to Void, int to Int, Number to Float) the basic differences between AS3 and haXe. But the true list of differences is a bit longer:
AS3 supports wildcard import statements, haXe does not. Classes in AS3 can start with lowercase letters, in haXe thet must be uppercase.
Those two restrictions would make it very annoying to have to translate everything manually. So i figured if i wanted this library to be written in haXe, instead of spending all this time doing the translation, that would have to be updated manually every time the original AS3 source was updated, i could spend the time writing a better AS3 to haXe translator that more closely inspects the input files, determines what classes are being used, re-generates the import statements, refactors the class names, converts the data types, converts the ‘for’ loop syntax, and converts the package block into a statement.
After a few days of design and coding i have a working prototype that does everything listed above. I wrote it in haXe and its running on the neko vm so it should be cross-platform and compile on windows, linux and mac osx. I am hosting the code on GitHub so anyone can feel free to fork it and try it out, report any bugs, and ideally patches to make it better. I know its a bit rough right now and i’m sure the code is quite messy, but it will get better.
Right now i am analyzing the output that is being generated to see how things look and see where things need to be improved. My goal is to have the haXe code compile without any modifications needing to be made directly out of the translator.
Look forward to my next few posts which will cover what my analysis results are and what the next steps will be for the project.

Categories
Tag Cloud
Blog RSS
Comments RSS

Void « Default
Life
Earth
Wind
Water
Fire
Light 