AS3 and the Scoop on OOP

i was only trying to promote Flex Camp 2 when i launched into a long lament over Macromedia/Adobe’s chosen design path for their Flash software. Industry pal Jim McGinley (of TOJam 3 fame) shared his insights:

Visual Basic programmers had an inferiority complex. Despite the fact VB programmers were building business applications in record speed, VB programmers knew in their hearts they weren’t working with a ‘real’ programming language. Microsoft responded to this, and kept adding C++ features to the VB language, eventually releasing VB.Net. VB.Net is a REAL programming language with ALL of the features and capabilities found in C#. It takes twice as long to build business applications, and programmers love it!

Flash is following this classic pattern. Flex proves that Flash is becoming a real programming language. Eventually, Flash will wind up being C++ (Threads, OpenGL, ADO database layer), forgetting what made Flash great to begin with. Animations produced in the Flash design environment will be replaced by Actionscript code that does the same thing. It will take twice as long to build things in flash, and programmers will love it!

The Primordial Days of Flash

If you’re a college student who’s just been saddled with a Flash course, or you’re keen on creating a little interactive piece for your website, you may now be quaking in your boots at the prospect of wrapping your brain tentacles around Actionscript 3. It may surprise you to learn that Flash (née Futuresplash) was once a great little vector animation tool for artists. It developed a scripting language to help with starting and stopping animations, and supported the occasional button – a button to start and stop an animations, most likely.

i got into the game at Flash version 4, where all the scripts were in a tidy little box. You couldn’t actually type any code. You could only drag and drop the script you wanted into your scripting window, and fill in the blanks. For example, you could drag the playhead control script “gotoAndPlay();” to the scripting window, and fill in a frame number or a frame label to make it read “gotoAndPlay(“act4”);

i loved everything that Flash had to offer except its script controls. Although i never had any success all through my life with programming, i didn’t like coding in Flash 4. i could actually make a whole game by myself, which was great, but it felt like throwing pottery with boxing gloves on.

The upgrade to Flash 5 blew my mind, and marked the first step in my path toward the Dark Side. For the first time, i was able to type my own code. No training wheels, no boxing gloves – all i got was a big blank window. “The power,” i cackled – “the ABSOLUTE POWAHH!!!”

But with great power comes great responsibility (Luke said that long before Uncle Ben, by the bye), and with the freedom to type your own code came the burden of learning the Actionscript language and syntax inside and out – otherwise you’d get a famously cryptic compile-time error. To quote a certain colony of ants released into zero-gravity, “Freedom! Horrible freedom!”

New Designer Features Are Coming, Right?

With each version of Flash that the Macromedia team released, those of us from the design end of the gene pool (AKA the shallow end) anxiously awaited the newest art and animation features.

Would Flash be able to handle text along a path, like Illustrator and Photoshop?

What about curved gradients?

How about a swirl tool? Or the ability to freeform/perspective distort a movieclip?

What about inverse kinematics in Flash? Hell – what about forward kinematics?

Could you make it so that we can select a bunch of movieclips at the same time and swap them out all at once, instead of swapping every symbol instance one by one?

What about range-selecting a bunch of instances across your timeline and giving them all the same instance name with one click, instead of having to individually name all your instances in case you forgot to name that first instance before you went ahead and animated it across 300 frames?

How about time stretching? Can Flash time-stretch our animations in case we have to change the frame rate in the middle of a project?

Text Along a Path in Illustrator

Illustrator flagrantly mocks me.

No? So what do we designers get, then? Photoshop-style filters? Ok … alright. So after eight years of waiting, you’re giving us Photoshop-style filters like blur and drop shadow?

Hey uh … hey Adobe: 1997 called. THEY WANT THEIR CUTTING-EDGE DESIGN FEATURES BACK.

Toon Boom

Back when i was working at Corus Entertainment, a media conglomorate with several national stations boasting millions of viewers, i was trying to make a case for building the entire YTV.com site in Flash. We got pretty close, but the idea was eventually tossed when a new concept called “Search Engine Optimization” reminded everyone of Flash content’s depressing opacity. Still, i contacted Macromedia many times asking for support and advice, sharing site links with them to show off our department’s work and generally trying to bring on the love, but they weren’t having it.

Corus animation studio Nelvana seemed to have a similar problem. They animated a few different shows entirely in Flash, including Jacob Two-Two, which must have been a nightmare without any sort of linkage feature to sew characters’ limbs together. Plucky young upstart Toon Boom Studio listened to them and began building the features they requested, which included parallax background scrolling and a Maya-style hierarchy for all the kibbles n’ bits within a scene. Nelvana phased out Flash after a couple of years, and even bought Toon Boom to ensure that the software would continue to develop with animation production in mind.

In the end, the squeaky wheel gets the grease. And in the case of Flash, the nerds bemoaning improper coding practices won out; its scripting language was developed and refined until today’s Actionscript resembles many C-based languages out there. And aside from the occasional blur effect, the art and animation tools remain almost identical to the version i started using eight years ago in 2000.

Quick – Code this in Ten Minutes!

The fallout that i’m faced with is this: AS3 is not fast. Sure, it may be fast to the user, but that’s because the Flash virtual machine has offloaded the burden of figuring out a lot of junk onto the programmer. The result is that projects that i could quickly bang out in a week now take at least twice as long to build.

It’s not because i don’t know Actionscript 3 like i know Actionscript 2. i spent two months, eight hours a day, retraining myself to use AS3, and here’s my verdict: it’s simply slower. The fact that it forces an OOP (Object Oriented Programming) methodology on me means that instead of this:

1
var myWidget:Object = {};

i have to type this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
namespace ohGod.makeItStop.whattaPainInTheAss
{
    import flash.whoCares.thisTakesTooLong.SomeNonsense;
 
    public class Widget extends SomeNonsense
   {
         public function Widget()
         {
 
         }//constructor
   }//class
}//namespace
 
//*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*//
 
// Meanwhile, back at the ranch:
var myWidget:Widget = new Widget();

Count up those keystrokes. That’s a whole lot more typing.

Beyond that, there’s a whole lot more thinking and planning involved. You should no longer say this:

1
var myNum:Number;

… because the Flash Player wants to know what kind of number you need. Is it going to be signed or unsigned? With a decimal or no decimal? What’s the highest amount that number will ever reach?

You know what? Sometimes i have no idea. i don’t know, Flash. You tell me. i don’t want to have to go traipsing through additional manuals looking up the limits of your number datatypes because i don’t have time.

Many of the projects that we build at Untold Entertainment have a programming element of one to two weeks, max. It’s actually a competetive edge that we’re able to code so rapidly. So while OOP and strong-typing and proper class architecture are all nice things to have, so is a finished project.

Enemy Mine

Programmers just LOVE OOP because, theoretically, you can create modular, portable code that you can reuse in project after project. This is all true in the application world, where buttons all act in similar ways and windows all do the same nonsense from app to app. In fact, one could argue that applications are better when they adhere to a shared sense of design. i want to know in every app that when i click that the little underscore button on a window will minimize the window, instead of adjusting the application’s volume and installing a new graphics card driver for example.

Casual web games are a different story altogether. Some elements are handy to reuse – particularly a high score module, a timer, a Button class, a Sound Effects controller, and an on-screen Prompt or Dialogue routine. But OTHER elements, like the fire-breating fish who revolves around the central pivot point of the planet graphic shooting fireballs at a 37 degree angle and reacting to the player’s crossbow shots by randomly jumping or rolling – THAT kind of thing is a different story altogether.

Yes, you can build the fire-breathing fish using OOP methodology. You’d probably start really generally, maybe with a Character class. “Enemy” extends “Character” and inherits, maybe, a hitPoints member, and perhaps it has its own fire() and dodge() methods. That all sounds great – straight out of an OOP text book.

But then your next game has an evil squirrel enemy that walks orthogonally through an isometric environment, picking up any atomic acorns he finds and intermittently firing up a deadly force field.

Again, you can revisit your enemy class and tweak it so that your new enemy works, but those two Enemy cases are so different. There’s no way your original Enemy class is going to suit this new enemy character, because you simply can’t see into the future. You can’t foresee all your Enemy needs. And when “the future” is only two weeks away and you have to slam together the code for your current project, you’re not likely to futz around building the perfect reusable Enemy class all week.

Screw OOP

So screw OOP. Yeah – i said it. Object Oriented Programming is fine for organizing code, and certain things can be reused. But by and large, if you’re the type of user who doesn’t have a nine-month Flash project mapped out on a Gantt chart and hung on a wall so that you can interface with the twenty other people on the project and negotiate dependencies, then Adobe and Macromedia have totally screwed you – first by requiring you to adopt a methodology that’s only going to slow you down, and second by failing to deliver design features that actually would speed up production, such as those i mentioned earlier.

But hey – at least we’ve got blur. Perhaps in eight more years, the Adobe Flash gods will smile on us and give us lens flare.

Lens Flare

7 thoughts on “AS3 and the Scoop on OOP

  1. David

    While I agree it takes longer to develop AS3 than AS2 or earlier products, my experience goes back to using FutureSplash,the precursor product of Flash, the point of the feature set is the ability to do industrial quality development. We can now do reliable testing, data services, media streaming and other industrial and scalable things with the Flash Player that were difficult to bullet proof before. It is also worth pointing out that previous versions of the product are still supported in the Flash player. You can develop in the version of the product you like best and run it in the current player; you might even get a performance boost.

    I understand the frustration of the design end of the Flash spectrum. Personally I hate having to use the whole of the CS3 suite just to design a layout. On the plus side there is an ecology of products like Toonboom to fill the gaps. I think Flash and Flex are better products for team working. I am not sure if I would like Adobe to try to code everything into Flash or Flex since right now I think both product have too large a foot print.

    I think there is also a cultural problem here. It used to be that the Flash guy sat in the corner building animations, games and widgets which were superficially added to a page. Now the Flash guy is part of a team and that means things take longer to get done. That is the down side of team working.

    Reply
  2. haha

    Umm … it seems like you need to go back and check how much AS3 you really know:
    namespace ohGod.makeItStop.whattaPainInTheAss {
    .. would never compile (its package dude … package … but thanks for pretending youve given as3 a chance.

    Furthermore: the editors and environments which help you generate this code have become so far advanced you actually do less typing in a language that is easier to understand and has less flaws and illogical eccentricities. (Eclipse, FDT, FlexBuilder, FlashDevelop anyone?)

    Im sorry but I have to give you $&@!# for this article as it is totally misleading: if you want to do
    var myWidget:Object = {}; it works the same: AS1/2/3 – you just stuffed it into a (broken) class and added dependencies the widget doesnt need: if you are going to do a real contrast/compare at least be honest or know what you are talking about.

    There is major verbosity with AS3 and major power; sometimes better/sometimes worse. But this article is really just about a guy who wants to wade in the shallow end because he doesnt know how to tread water and is pissed his friends all swam to the deep end where they could have more fun.

    Boo hoo :/

    Reply
  3. Ryan

    i feel uncomfortable typing the word “package” because it reminds me of that time i watched all-male ballet on PBS. Adobe should be sensitive to this and change the language on my behalf.

    Again, having come from Flash exclusively, i don’t quite grasp all the nuances of FlashDevelop, but the scales are tipping in its favour. i much prefer writing code – any code – in FD, including xml and html. The auto-indenting is a bit of a pain when you’re pasting multiple xml nodes tho. At any rate, the editors and environments you mention are all non-Flash. It’s a little obnoxious that we’ll never see custom code-hinting or decent as file management in Flash because they’ve got Flex Builder to sell, much the same way that Photoshop retains a unique feature set compared to Illustrator, even when there is so much overlap.

    You’re right – i haven’t given AS3 a fair shake. It’s just been a very long and uncomfortable transition for someone who didn’t start out with C-based languages or anything of the sort.

    Of the half-dozen or so Flash developers i know in the industry, only one of them has really “waded into the deep end” and begun developing with AS3 in earnest. i think a more apt analogy is that taking Flash in this direction and forsaking its design roots is like one group of kids holding another group of kids’ heads under the water until they drown or become bullies themselves … when it was their pool to begin with.

    Reply
  4. Tim

    and in a couple of releases, Adobe will bring back dynamic typing because this is what the cool kids do (ruby,python, even C# in .NET 3.5)

    The progress made by the Flash player shouldn’t come at the cost of the developer. I like AS3 for many reasons, but can’t stand some *architecture* choices that Adobe made. The ubiquity of the Flash Player 9, will make AS3 the de facto standard for coding in Flash. Despite its annoying new syntax.

    Reply

Leave a Reply

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