protected function init(event:FlexEvent):void
{
btnBack.addEventListener(MouseEvent.CLICK, viewOverview);
}
protected function viewOverview(event:MouseEvent):void
{
dispatchEvent( new ChangeSelectedIndex(1,ChangeSelectedIndex.index_passed));
}
I try to add the eventlistener like this, but nothing happens. I’ve checked, and the init function is being called from the creationcomplete statement. Below you can see the button in the containing HGroup.
<s:HGroup x="116" y="0" width="200" height="25">
<s:Label id="lblOverviewTitle" fontFamily="Verdana" fontSize="24" fontWeight="bold"
text="Artist Details"/>
<s:Button id="btnBack" label="Back" />
</s:HGroup>
Why do you need to add the event listneer in ActionScript? You can do it in MXML like this:
As stated in the comments to the main question, it seems like you are trying to add the event listener to btnBack before the component is created. You should add the event listener in a initialize event, because initialize fires right after createChildren() is fired.
If you’re building a Spark Component, and btnBack is a skin part, you should add the event listener in partAdded() method.