Get the Flash Player to see the slideshow.

Robotlegs with BulkLoader. XML asset injection.

as a trainload of contrast to my last post, I’m playing with Robots.

this simply is a Robotlegs app which levies BulkLoader and pulls assets from paths specified in XML.


the XML format resembles:

<model>
    <assets>
        <asset source="assets/bob.jpg" loadGroup='preload' />
        <asset source="assets/robyn.jpg" loadGroup='secondState' />
        <asset source="assets/clown.jpg" loadGroup='secondState' />
    </assets>
</model>

the loadGroup identifier allows you to break your preload into stages. anything tagged ‘preload’ is pulled automatically on STARTUP_COMPLETE. subsequent calls to yourModelProxyInstance.loadState(state:String) pull whichever state you specify.

there is no ‘name’ or ‘id’ identifier because this is parsed from the URL. saves a bit of redundancy – “assets/bob.jpg” gets the following key in BulkLoader: ‘bob’.


I’m completely abusing flash.utils.describeType in my BaseObject class. it’s there to help you develop more quickly.

if you know exactly where your code is going, BaseObject is overblown. if your project’s specifications flop around like trout on a dock, BaseObject handles your busywork.

as an example, the following copies like properties from the passed-in object:

var varList:XMLList = describeType(this)..variable;
i=0;
l=varList.length();
for(i; i < l; i++)
{
  var prop:* = String(varList[i].@name);
  if (passedInObject.hasOwnProperty(prop)) {this[prop] = passedInObject[prop];}
}


any change requests, just ask. especial thanks to John Lindquist for the best of the Robotlegs tutorials.

observer pattern as MVC enabler

I had been building variations of MVC without implementing the Observer pattern. Now having studied Observer, I realize how to do MVC properly.

MVC without Observer is like NATO without formal delegates. You’d let every citizen in every nation contact every other directly.

We want our model to publish to a group of subscribers. Flex bindings can pull this off. Consider, however:

  1. Encapsulation recommends, and modularization implies, that not every class directly accesses every other. (Beware of EventBroadcaster use & Singleton abuse.)
  2. While you have a handful of models with a slew of listeners, EventListeners are firing constantly, listening for changes. This will affect memory consumption.

Observer allows for an easily-readable, encapsulated, relationship between Model and View. Your model extends a Publisher class. Publisher has a function which adds subscribers to its subscriber Array. The Publisher class also has a function to notify its group of subscribers. The Publisher knows that any Object which subscribes will implement the Subscriber class.

Views which require Model/Publisher data extend a Subscriber class. The parent Subscriber is a good place to declare your static constant strings — these describe data groups. (Having these outside the model better supports encapsulation, but I’ve seen them in the model in other examples.) Each Subscriber child has an Array which notes the data groups the Subscriber is interested in. Each Subscriber has an update function which is called by the Publisher when it sends data.

A third class keeps things organized and readable. It’s there you subscribe the Views to their Model or Models.

I searched for similar AS3 Observer implementation examples online and found but one. Hope my example helps your code find its way.

horizontal accordion component [as3]

Built a Horizontal Accordion component for the Boys & Girls Club. The Horizontal Accordion is made of different Panels, each of which automatically tab-order their child Sprites. Many Panels contain Text Input fields. Each Text Input field includes a Flex-style means to add Validation. … There’s other less-cool stuff being done all over the place too.

Am posting the major classes. All code will relate specifically to the blue Horizontal Accordion on the site.

view HorizontalAccordion class
view HAPanel class
view OnStageObject class
view TextInputMod class
view ValidatingObject class
view Validators class

object-oriented as2 development

built a game banner which published to flash 7. requirements included being <130 k with a <100 k second load.  posted it here.

have always used as2 on an as-needed basis, but decided this time to operate on it.  open it up. see how it works.  or doesn’t work. dragged as2 screaming into the year 2008. into the light.

the utility classes i found, modified, or extended are useful for anyone coming from an object-oriented background:

  • DocumentUtil allows you to specify a Document class (aka Main class). :: Ryan Taylor @ boostworthy.com
  • BezierTween creates beziers using little phrases that even Flash 7 can compile. :: Felix Turner @ airtightinteractive.com
  • MovieClipBubbler bubbles as2 MC events. it is not simpler to use than an Event Broadcaster.  it does have performance benefits over an Event Broadcaster. :: Ralf Bokelberg @ helpqlodhelp.com
  • Hitbox is an essential extension of MovieClipBubbler, at least in concept.  you should take my implementation and twist it to your ends.  using Hitbox avoids having to draw zero-alpha’d Hit areas on all your MovieClips.  in simplest execution, the MovieClip in your Library links to Hitbox (rt-click/Linkage/’Export for ActionScript’/Base Class).

the interface is your friend

picnik has the friendliest registration process i have ever experienced with immediate, intuitive, consistent feedback.