In the past couple years I have done my share of AS3 work, but since I have so many unfinished game engines in AS2, I have maintained a good amount of work in that version of ActionScript because I already had a ton of work complete. However, my last Zamboozal project have changed my attitude.
For the recently finished Zamboozal Silverlight/Flash project, I decided to write the game in Silverlight/C# and then convert it back to ActionScript 2 in Flash. I thought this would take no longer than a few hours. At first, I was right. Because I had planned out my Silverlight object model to closely match how AS2 works, it was fairly easy to covert the C# code to AS2 and get a set of code that would compile. About 4 hours into the conversion process that was complete, and I was a happy boy.
Here are both games.
First, the Silverlight One:
…and the Flash version…
Getting to final Flash version was not easy. The problems arose when I tried to play the game for the first time. ActionScript 2 is so loosely-goosey with the language, that compilable code did not mean I had an application that worked at all. Coming from a Silverlight 2 C# project, which is both strongly typed and very strict about the code, this was a shock. In short,
I can’t believe that I was living with while developing in AS2! Here are some of the major headaches that occurred while trying to convert the Silverlight App the Flash AS2:
Everything’s a MovieClip: In AS2, you can create classes, but if you have object that are derived from MovieClip’s the code barfs sometimes if you don’t declare variables for those objects as MovieClips instead of the derived Class type. I found myself, more often than not, converted my pretty class references to my objects back to MovieClip just to get code to work correctly. This was not an issue in C#.
Related to the above, creating MovieClips to add to the display by using attachMovie made my code simply incompatible with C#. Instead of being able, for example, to create a new "Choice" class by declaring some thing like
new Choice("Straight",400) I had to use two lines of code, first attaching the clip : c1 =attachMovie("FStraight","F1",1000) and then calling an c1.init("Straight",400) function to set the name and score value. Not a lot of work mind you, but still very clumsy. Button Components: I could not find a way to dynamically change the text on the included button component for AS2 (in Flash 9). I wanted to use the supplied buttons so the game would match more closely with the Silverlight version. However, after multiple tries, I simple gave-up and made my own buttons. However, this was not the end of the issue. Even with my own buttons, setting the .text property dynamically was an issue. The problem seemed to be with the delegates I created to handle the button events in my class. With a delegate created, every time the button was pressed the text on the button would revert back to the default ("xxx"). It made no sense at all. I managed to fix the problem by getting rid of the default text, but why did this happen? Weird.
There were many more issues with converting C# to AS2, but I think they would just get redundant. My real point here is this:t C#->AS2 conversions are too much of a headache to undertake, especially when AS3 is so much closer to C#. If you want to make projects that work in both Flash and Silverlight, AS3 is the only way to go.