Kicking AS – From Actionscript 2 to Actionscript 3

i’ve been developing games in Flash since version 4 in 2000. Back then, they had recently added scripting to the program, which had been primarily focussed on animation and design. The original Actionscript author said that he created the scripting language with Lego in mind. This was pretty clear from the Flash 4 coding interface. Instead of typing code, you just chose lines of script from a list and filled in the blanks, like variable names and values. It was an experienced programmer’s nightmare, but i was not an experinced programmer. For me it was a great introduction to programming, which had baffled me since i was a young kid trying to learn AmigaBASIC so that i could make video games about my favourite Muppets.

He blows up the things.

Flash 9 and Actionscript 3 have been available for about a year now. At my last job, despite a commitment to Sarbanes-Oxley compliance, the folks controlling the budget were very slow to upgrade our software. It was a full year past the release date before we upgraded to Flash 8, despite the massive workload reduction we demonstrated thanks to the new movieclip bitmap filters. (With Flash 7, if we wanted an animated character with a uniform outline, we’d have to create that outline by hand for every frame of animation).

It was the same story when Flash 9 arrived. The jump from Actionscript version 2 to Actionscript version 3 is significant, but my company was in no hurry to ensure that everyone kept their skills current. i could have learned it on my own on evenings and weekends, but that would have left me little time to run and jump and play.

So here i am, a year late, plodding through Colin Moock’s new book. i’m on chapter five. Here are my early opinions for you Flash AS1/AS2 programmers who are fearful about upgrading your skills:

AS3. Fear it?

This is a test. This is only a test.

This is not a book review. i haven’t read the 800-odd pages to give the book a fair enough shake. i have, however, read Moock’s other Essential Actionscript books nearly cover to cover. What i appreciated about those books is missing from this one. Moock has always made the reader feel at ease and comfortable with whatever he’s teaching, easing us into the pool inch by inch. Sure, there are some uncomfortable moments – like when the icy water hits your babymaker – but for the most part, if you follow along and don’t wade in over your head, Moock will have you swimming before you know it.

With Essential Actionscript 3, Colin Moock pushes you into the churning ocean from a helicopter during a thunderstorm in the blackness of night and asks you to collect shiny marbles on the sea floor with no oxygen tank.

The analogy wears kind of thin at this point, but you get the idea. While his other books are adequate intro programming books, this one requires a much more solid basic understanding from the reader. Moock spends the first chapter exhausting the ins and outs of namespaces (“packages” in AS 3) without so much as a “Hello world”. Geez, Moock – would it hurt to spend a little time on foreplay?

i don’t know how much of this is his fault. AS3 does require a lot more initial setup than anything you’ve ever coded before, if you come from a Flash-only background like i do. And he’s clearly been mandated by Adobe to write the book flexibly enough for readers using Flash, Flex, or mxmlc (included in the free Flex SDK). That can’t be easy. (All mentions of Adobe AIR are cursory and appear to have been added at the last minute, as the book was going to print.)

i’m not sure he nailed it this time. i’ve read other books where, despite the amount of setup code required to compile that new programmers will have a hard time with, the author says “You won’t understand what any of this means, but just write it down for now so that we can get our ‘Hello World’ program running.” i think i prefer that approach. Moock takes too much time here explaining every little detail with razor precision while largely leaving new Actionscript users in the dust.

200 billion penguins can't be wrong.

(Incidentally, i had the same problem while reading the documentation for Moock’s Unity Server. Too eggheaded and abstract, as though he’s slowly losing his ability to parcel his knowledge out to us plebes. When i reviewed SmartFox Server and saw friendly methods like “Add Room”, and “List Players”, i was relieved. We ended up using SmartFox for our MMOG project.)

Are you experienced?

But what about us Actionscript old-timers? Is AS 3 really different enough to warrant a panic?

My gut feeling is “no”, but it depends on how much time you spent taking advantage of Actionscript 2’s pickier principles.

One thing that “real” programmers hate about Actionscript is how fluid and forgiving it is. Strong typing wasn’t really introduced until AS2, where you could tell the programming environment what types of variables you were using so that it could find errors for you earlier, instead of surprising you while your program is in the middle of its schtick.

AS 2, however, was permissive. You didn’t have to strong type your variables. The compiler would still perform automatic data conversions on type mismatches. It enabled you to use classes, but didn’t force you. AS 2 was like the girl up the street who talked big about being chaste and untouchable, but she’d totally let you get to third base if you paid for her movie ticket.

AS 3 is more like the girl you marry. It plays hard-to-get, but the commitment you spend learning its idiosyncracies will serve you well for many years, until you divorce and take up with a much younger, fitter programming language that the kids call “new mommy”.

The verdict.

i have no idea how i managed to weave so much sexuality into a discussion about Actionscript. Suffice it to say that strong typing your variables is a pain in the ass and will make you type more slowly until you get used to it. Adopting OOP methodologies will take a long damned time if you’ve never had to do it – this is the challenge i’m facing. In particular, the best practice of creating special “get” and “set” methods to change private instance variables makes me grit my teeth. Add to this the fact that for most of my projects – small web games with 2- and 3- week production cycles – full OOP implementation is overkill.

The good news is that playing by the newer, more strict AS3 rules will prep Flash coders for learning other languages like the C family. i tried to learn C# while making light use of the (then) new AS2 principles, and i found that i didn’t have enough OOP experience to make sense of it. One loop in your code? What kind of crazy talk is that? In Flash, every item on the screen has its own loop! Yeehaw!

Flex.  It makes you not want to kill people quite as badly.

Although i have not even used it myself, i highly recommend learning to develop in Flex. Abstracting code from your design layer is a key component in learning what “real” programming is all about, and i find it’s one of the hardest things for Flash born-and-bred coders to do. Beyond that, the Flash IDE stinks for programming. Keeping track of multiple AS files without proper code hinting is a dealbreaker for me. When i build my first AS3 project, which will launch by the end of the month, i’ll use Flex.

Now pardon me – i have to go pick up personal hygiene products for AS3 before the drug store closes.

8 thoughts on “Kicking AS – From Actionscript 2 to Actionscript 3

  1. colin moock

    hi ryan,
    thanks for letting me know about your blog post. it’s gots lots of interesting thoughts. i was going to respond via email, but i figured maybe others would be interested in my reactions, so i posted here.

    firstly, i should say that i really appreciate the time it took you to write down your impressions. it is always very helpful to read considered opinions on my writing, particularly from readers that feel that it doesn’t help them learn what they want to learn.

    I think the primary difference between what you’re looking for and my book is that Essential ActionScript 3.0 doesn’t teach “how to do scripting in the Flash authoring tool using ActionScript 3.0”. it teaches “object-oriented programming with ActionScript 3.0”. by my own decision, i chose to step back from flash and flash player. instead, i decided to explore ActionScript in the context of the “Flash Platform”, which has many potential runtimes, and many potential authoring tools. I chose to explain “how to write a program using ActionScript 3.0,” rather than “how to add scripting to graphical content and timelines created manually in a .fla file.”

    put another way, i mainly write about “core actionscript”, not flash. to follow your analogy, i’m easing you into the object-oriented programming pool, not the flash scripting pool. Essential ActionScript 3.0 should, therefore, be useful for flex users, flash users, notepad users, and everyone in between. eventually I expect many other books to fill the flash “how to” gap for ActionScript 3.0. for example, another book might teach the reader how to create text like this:

    ==
    To put some text on screen, add this code to a frame script:

    var t = new TextField();
    t.text = “Your Text Here!”;
    addChild(t);

    Don’t worry about the “var” or “TextField” too much, just change “Your Text Here!” to whatever you want, and you’ll see the text appear.
    ==

    by contrast, my book *does* worry about all the underlying details. it’s for users that want to know what’s actually behind the code they’ve been copying and pasting from other books and online tutorials. of course, some flash users may not ever want to know what a “class” is or what a “type annotation” is. but if they do decide they want a deeper understanding of ActionScript, my book should be able to give it to them. personally, i think that even if you don’t normally write your own “package” or “class”, trying to write one at least once is useful because it helps you understand the built-in tools better. if nothing else, you’ll know why TextField is listed under “flash.text.TextField” in the documentation, and the whole language will seem less mysterious.

    so while i agree there’s lots of room for beginner “Flash how to” books in the market, that’s just not the type of book i set out to write. I don’t think that’s a failing of either type of book, it’s just a difference in goals.

    for the record, i should point out a few mistakes in your article:

    -absolutely none of the content in my books is mandated by Adobe in any way

    -I decided not to cover AIR directly, but at least to make reference to it so that programmers from other disciplines would be aware that the Flash Platform has a desktop option. the AIR references weren’t last minute. they were always meant to be brief.

    -type annotations are not required in ActionScript 3.0 (nothing has changed here from ActionScript 2.0).

    -ActionScript 3.0 does not “force you” to use classes. you can still do all the timeline stuff you’ve done for years.

    -ActionScript 3.0 does not require get and set methods, and does not require an object-oriented programming methodology. you are free to use as much or as little as makes sense for your project. if you work faster without classes on a small project, don’t use them.

    thanks again for your article, and good luck with your ActionScript 3.0 project!

    colin

    Reply
  2. Ryan

    Thanks, Colin! All great points.

    When i said that AS3 “forces” you to use this or that methodology, what i meant was that employers who look for people with AS3 experience are going to expect you to know the latest and greatest. If i take a contract saying “i know AS3, but i don’t use strong typing or namespaces or classes or OOP or any of that junk,” people are going to doubt that i actually *know* AS3.

    You’re right – AS3 still allows people to squeak by on bad programming. But books like yours offer the chance for AS coders to actually improve their skills, rather than fudge their way through old habits by adopting the few syntactical differences (“void” instead of “Void”, etc).

    The few people who wrote constructive reviews of your book on Amazon echo my thoughts – it’s not a beginner book, (as was your “Definitive Guide” years back), and people take exception to the “if you have no prior programming knowledge” proviso on the back cover. As far as the level of detail goes, one reviewer used the word “fussy”, which i thought was apt. Still, there’s room on the shelves for at least one “fussy” book.

    The majority of the feedback on Essential ActionScript 3 is very, very positive, and i look forward to absorbing as much as i can the further into it i survive.

    Reply
  3. colin moock

    hi ryan,
    two more responses…

    1) unfortunately, sometimes employers are uninformed about technologies, and adopt common misconceptions. believing that ActionScript 3.0 means “object-oriented programming” is as misguided as believing that “web 2.0” means “rounded corners”. remember that ActionScript 1.0 allowed for the use of object-oriented programming techniques through the use of functions-as-constructors and prototypes. yet, people don’t equate ActionScript 1.0 programming with oop. often, they falsely equate it with timeline scripting. i’ve even heard people say “i’ll stick with ActionScript 1.0 because i don’t want to use classes,” not realizing that a) ActionScript 1.0 conceptually also had classes, and b) ActionScript 3.0 still includes timeline coding tools like gotoAndPlay(). ActionScript is a big world, with multiple development methodologies. you don’t have to use them all to claim to “know” how to develop with ActionScript 3.0. an informed employer should be more specific about what they need; e.g., “ActionScript 3.0 developers proficient in timeline scripting” or “proficient in object-oriented programming”. there are lots of very skilled computer science types who might have good ActionScript 3.0 object-oriented programming skills, but no timeline scripting experience. those folks might be inappropriate to hire for a flash project. just as a timeline scripter might be inappropriate for a flex application project.

    2) i’ve been following the “beginner” issue on amazon. again, i think it comes down to expectations: my book is suitable for beginners who want to learn formal object-oriented application programming techniques. but it’s not suitable for beginners who want to add simple scripting to a timeline or a button in flash. i think the book’s marketing should do a better job of expressing that distinction (i.e., that the book is mostly about object-oriented programming.)

    lastly, a bit of advice about Essential ActionScript 3.0: if you’re just trying to get your head around the language, consider skipping some chapters. things like namespaces, interfaces, dynamic ActionScript, and security typically apply to special cases, such as large, complex applications, or multi-domain web content. on your way through part 1, you should probably skip those chapters and head directly into part 2 (display programming).

    kind regards,
    colin

    Reply
  4. Orneryboy

    Man, I am so screwed. I gotta get me a book and start honing my Actionscript skills right away. Either that, or move away from building Flash games, and move into mining coal or lifting heavy objects.

    Reply
  5. Ryan

    Good luck with that. Lifting heavy objects ain’t what it used to be. They’ve totally changed the process now, so that all of your old heavy object-lifting skills are obsolescent. i mean, you can still lift heavy objects the same old way, but do you really want to? When all your peers are lifting heavy objects in fanciful, cutting edge ways, you’re not going to be able to compete.

    i recommend Lifting Heavy Objects 2.0 – Heavy Objects the *Right* Way by Hurple Stumbleblimpkins.

    Reply
  6. Mark

    I appreciate the advice of skipping a few chapters and starting at display programming. I suppose I could do that or just sit on my copy of Flash 8…except that I bought Flash 9 because I was geeking out about the crappy code collapse. I’ve started placing all my different pieces of code on new levels so I can isolate the specific sections of code. Is there any way to save the way I code collapsed my stuff?

    Reply
  7. Ryan

    Again, i haven’t used it yet, but i think the answer to your problems is Flex Builder.

    Coming from an entirely Flash background, when i started learning C# and using Microsoft’s Visual Studio, i was BLOWN AWAY at what it could do. It organizes all of your separate code files. With the push of one button, it simultaneously saves all of your files and compiles your project. It gives you code hinting not jsut for built-in classes, but for your own custom classes as well. You can CTRL+click on any highlighted code word to see the help file for it, which opens within the environment instead of in a separate window.

    i will definitely report back once i start using Flex Builder, from the perspective of a timeline coder making the jump.

    Reply
  8. Pingback: untoldentertainment.com » Blog Archive » Sheet Happens - Concept Phase

Leave a Reply

Your email address will not be published. Required fields are marked *