September 27, 2005

Mix-ins and the UIComponent framework

Disclaimer: have not studied Flash 8 yet, don't know if mixins are still an issue in the new generation of the component framework. I just remembered this issue when I revisited DHTML. I'm not saying the event dispatching approach in Flash is even good, I'm just saying if it's the accepted convention, there are ways to implement it without mix-ins.

Event dispatching capabilities are mixed into UIComponents by calling EventDispatcher.initialize(targetObject) from within the ui component's constructor.

I remember describing all this to Carol King on a whiteboard years ago... composition over inheritance: make the dispatcher a private member of the base component class with a public accessor, and call the dispatcher appropriately...

:::pseudo-code
class ComponentClass()
{
ComponentClass()
{
this.dispatcher = new Dispatcher();
}
public Dispatcher getDispatcher()
{
return this.dispatcher;
}
private void whenSomethingHappens()
{
var e = new Object(); // or some event type
this.dispatcher.dispatchEvent("onSomethingHappened", e);
}
}


var c = new ComponentClass();
c.getDispatcher().addEventListener("onSomethingHappened", this, "HandleSomethingHappend");

function onSomethingHappened(e)
{
trace("event=" + e);
}

Just a little pet peeve I remembered, and could be fixed easily. Mix-ins don't taste good.

Posted by samuel at September 27, 2005 03:11 PM
Comments
Post a comment









Enter the letters as shown in the box below:



Remember personal info?