Just an update:
I tried using onRegister() to register my event handlers and they are still null
MyComponent.mxml
<mx:Canvas>
<mx:Button id="myBtn"/>
</mx:Canvas>
Main.mxml (abbr.)
<view:MyComponent id="myC" creationComplete="dispatchEvent(new Event("mycreated"));"/>
MainMediator.as (abbr.)
...
public function MainMediator(vc:Main)
{
super(NAME, vc);
(viewComponent as Main).addEventListener("mycreated", onComponentCreated);
if((viewComponent as Main).myC)
facade.registerMediator(new MyComponentMediator((viewComponent as Main).myC));
}
protected function onComponentCreated(e:Event):void
{
if(!facade.hasMediator(MyComponentMediator.NAME))
{
facade.registerMediator(new MyComponentMediator((viewComponent as Main).myC));
}
}
MyComponentMediator.as
...
override public function onRegister():void
{
// THIS IS THE CODE WHERE I GET A NULL REFERENCE ON myBtn
(viewComponent as MyComponent).myBtn.addEventListener(MouseEvent.CLICK, onMouseClick);
}
Note that I've expanded out the whole (viewComponent as foo) stuff, I know I could have created a getter to do that for me.. The problem you can see is that last code block, onRegister() blows up on trying to add an event listener to myBtn, because myBtn == NULL and I have no idea why..
Hopefully that helps..
John