I’m doing a project where I need to convert a ton of code from Flash 5 to Flash MX 2004, AS 2.0. The code needs to retain as much of the original structure as possible. (It’s for a very popular Flash 5 book that is being re-released). After a lot of messing around, I finally came up with a guideline for myself that at least codifies the process. I thought this might be useful to others who have to do anything similar.
- Move all code to the main timeline.
- Take any clipEvent code and turn it into functions on _root.
- Assign the functions as event handlers on the associated clips.
- Re-scope the event handlers as necessary. There were changes in the scope chain from Flash 5 to MX. Generally this means sticking “this” in front of every variable in your handlers.
- Remove any “controller clips” and the like”.
- Handle any case issues. In AS1, myVar == myvar. Not in AS2. I created a JSFL file that helps with this. Read on…
- Initialize variables. In AS1/Flash5, if x is undefined, x++ equals 1. In AS2/2004, it equals NaN. A good trick to find a lot of these is searching for +=, -=, ++, –. Make sure whatever is being incremented has been set to something, usually 0, beforehand.
- Change your publish profile to Flash 7 Player, AS2.0. At this point, the code should work. But in reality, you’ll probably need to do some more debugging here. Get everything working before moving on.
- Rethink any duplicateMovieClip code, try to turn it into attachMovieClip.
- Type all variables, function parameters and returns:
- myVar = 1; becomes var myVar:Number = 1;
- function myFunc(param){} becomes function myFunc(param:String):Void {}
- Upgrade deprecated actions. i.e. random() becomes Math.random(), etc. How far you want to go in this is up to you. I also do things like changing hardcoded stage size variables to Stage.width, Stage.height.
- At this point, you should pretty much have a valid AS2.0 program. Depending on how complex it is, you might want to move into an OOP design with it. For example, if you are attaching a lot of movie clips and assigning a lot of properties and event handlers or other methods to it, or you are using prototype, it may make more sense to create a new class that extends MovieClip.
A lot of these are common sense, but it helped me to lay it out as a process.
As for Number 2, I created this JSFL Command that helps in the process. Put it in the Commands folder in your Flash Configuration folder. It’s a quick and dirty command. It just looks at the ActionScript on Frame 1 of the main time line. It makes a list of all alphabetical string segments and pares it down to those that are potential case-sensitivity offenders, and traces out that list. It’s up to you to do the search and replace. Not perfect, but it saved me a lot of time.
Is it Flash Math Creativity? Oh please please please!!
I don’t know if I’m supposed to say or not, but….yes!
Great …
can’t wait to read it
cool
I don’t think duplicateMovieClip() is deprecated in AS2 – attachMovie() has the ugly side effect of needing the movie to be included before frame 1, interrupting preloaders and can only be linked from within the current SWF, not a loaded one. But anyway, that’s a small issue. Best of luck with the book!
I didn’t say it was deprecated. I just said “rethink” it. Personally, I don’t like the idea of putting clips on the stage for the sole purpose of duplicating them. It seems messy. You can also choose to not export in frame 1 when you export a clip.