Return of MovieClip “Duh”

Return of MovieClip “Duh”

I was drifting in and out of sleep, it being 520AM and as such was an appropriate time for such drifting, and I was dreaming of MovieClips and Events. I was thinking how MovieClips were kind of ungainly affairs, and like a lot of old Flash objects were of the dynamic nature…that is, they don’t require explicit declaration of properties, and in the process of referencing a non-existant property you will bring it into being. This is the sort of behavior that makes debugging Flash somewhat trick, causing experienced programmers to roll their eyes at the laxness of the environment. But then it hit me: the technique I outlined earlier to re-establish object-context for a callback method was completely unnecessary…I could just store the object context right in the MovieClip itself! This would eliminate the hashing array and lookup!

In other words, something like this:

class ClipWrapper2 // Dave Seah’s Magic Event Manager

static var ON_PRESS_EVENT = 10; static var ON_RELEASE_EVENT = 11;

static function DispatchEvent (clip:MovieClip, eventType:Number) { var execObj = lookupclip; var obj = clip.parentObj; var method:Function = Function(obj.HandleClipEvent); method.call(obj, eventType); }

private var clip:MovieClip; // wrapped clip

function ClipWrapper2() { clip = _root.createEmptyMovieClip(); clip.parentObj = this; clip.onPress = function() { ClipWrapper.DispatchEvent (this, ON_PRESS_EVENT) } clip.onRelease = function() { ClipWrapper.DispatchEvent (this, ON_RELEASE_EVENT) } }

function HandleClipEvent(eventType:Number) { switch (eventType) { … } }

}

I don’t know if this will work, but I woke up and had to write it down.

Although this insight may obselesce the old method, I still think it’s pretty cool because it made use of the understanding of objects, hashes, addresses, references, and function contexts versus object contexts.

Back to sleep…

0 Comments