Load order, attachMovie

Hello

I have a simple login movieclip object that contains a button. I created a custom class called DispatcherButton(see at the bottom of this message). I have set the button inside of this login movieclip to be of the DispatcherButton type by typing it into the ‘AS 2.0 class’ field inside the button properties in the library (the button is of type movieclip in the library and linkage identifier is LoginButtonSymbol, I couldn’t get the trace inside DispatcherButton() to work if the symbol was defined as a button). Ok the problem arises when I do the following:

//this code is inside of a class
loginClip = target.attachMovie(“LoginClipSymbol”, “login_mc”, depth);
this.loginClip._x = x;this.loginClip._y = y;

this.loginClip.loginBtn.addEventListener(“click”, getController());

Here nothing happens because it does not recognize the addEventListener function on the loginBtn. The problem seems to be that when I call attachMovie it does not run the constructor of its children, in this case the button inside. The DispatcherButton() function is run later. If I add the following line before I try to access the addEventListener function everything works as expected.

mx.events.EventDispatcher.initialize(this.loginClip.loginBtn);

Can someone explain what’s going on here?


import mx.events.EventDispatcher

class DispatcherButton extends Button
{
private var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;

public function DispatcherButton() {
trace(“DispatcherButton”);
mx.events.EventDispatcher.initialize(this);
}

public function onRelease(eventObj:Object) {
trace(“onRelease :)”);
//define the event object that is passed to any listeners when the event is broadcast (Step4)
// You must specify a target property and then name of the event or the event “type” property in the event object
var eventObject:Object = {target:this, type:‘click’};
//dispatch the event (Step5)
dispatchEvent(eventObject);
}
}