Pet Theory header image 2

why I’m pysched about AS3 packages

July 19th, 2006 by pet-theory

Like the vast majority of Flash programmers, I don’t come from a science/CS/technology background.

I’ll bet my evolution has been mirrored by others:

Phase 1: The Christmas Tree. Code actually HANGS all over the graphics.

Phase 2: The Root. The Christmas Tree is impossible, period. I centralize my code on one frame so all functions can talk to each other.

Phase 3: The Boxes. The Root was one long uproar of a scroll, and the bugs got weird, X-Files weird, when the wires got crossed. So I learned classes and practiced the virtues of encapsulation.

Phase 4: The Chinese Box or PACKAGE. It takes work to get all those encapsulated boxes to stack together, dammit. Some boxes are ridiculously small–6 lines!–and too often closely related boxes are forced to use a zillion courtly getter/setters just to say “Hi, how are you?” The only alternative is putting one box inside the other, which causes problems when the second box wonders, “Where am I, exactly?”

A package, I hear, allows multiple classes in the same file (one public class and its helper classes), and lets them share the same scope (with the default “internal” access modifier). So these problems should go away, and after that, coding will be as easy as sipping a martini.

[Edit: This is an old post. For more on packages, check out this post on access modifiers.]

Tags: code3 Comments

Leave A Comment

3 responses so far ↓

  • 1 Spacemonkey Sep 3, 2006 at 1:28 pm

    Love the evolution description. I’m currently in phase disappearing up my own backside trying to fit the movieclip with it’s associated attachMovie wierdness into the decorator pattern i.e. I have a window decorated by a border, decorated by a background. new Background(new Border(new Window())).

    All these classes end up floating in space creating and populating movieclips by reference instead of actually being those movieclips themselves.

  • 2 pet-theory Sep 3, 2006 at 4:44 pm

    I’m not at Phase 5 (design patterns) yet but I just read Head First Design Patterns, which was a gas.

    Maybe the composite pattern should do the heavy lifting in terms of populating the view, since it has the box-within-box structure of movieclips and interfaces?

    An uneducated guess…and one which would not give you the snap-on, snap-off functionality of the decorator.

    Matt

  • 3 Spacemonkey Sep 4, 2006 at 1:05 am

    Yeah find the decorator is potentially quite elegant but there’s a lot of code (re your chinese box) to get it working. My boss is more into the quick and dirty style of coding which I have a sneaking suspicion is more cost effective but doesn’t help my evolution much.