I have a TabNavigator that i'm trying to make work like Firefox in that the last tab is a special "+" tab that adds a new tab to the control. To do this I add an event handler to the very first tab's button which I get using tabNavigator.getTabAt(0).addEventListener(MouseEvent.CLICK, clickFunction, false, int.MAX_VALUE, false). I set the priority to int.MAX_VALUE so my method should be the very first one called and then can stop other handlers from being called using stopImmediatePropagation().
My problem is that every now and then my click handler isn't called and instead the normal logic runs and the "+" tab is switched to.
Code for CustomTab (I've removed a lot of proprietary code):
private var addTab:Function = null;
private var tabCreationAllowed:Boolean = true;
private function onCreationCompleted():void {
var tabButton:Button = getTab(0);
Container(getChildAt(0)).setStyle("closable", false);
tabButton.addEventListener(MouseEvent.CLICK, clickFunction, false, int.MAX_VALUE, false);
tabButton.addEventListener(MouseEvent.DOUBLE_CLICK, function(event:MouseEvent):void {event.stopImmediatePropagation(); }, false, int.MAX_VALUE, false);
}
private function clickFunction(event:MouseEvent):void {
event.stopImmediatePropagation();
if (this.tabCreationAllowed && (this.addTab != null) && (event.eventPhase == EventPhase.AT_TARGET)) {
this.tabCreationAllowed = false;
this.addTab();
var $this:CustomTab = this;
setTimeout(function ():void {
$this.tabCreationAllowed = true;
}, 1500);
}
}
tabNavigator. So now, to get the "+" tab, you'd have to usetabNavigator.getTabAt(1). Is it possible that's what's happening? If not, can you post some source code? - Travesty3event.preventDefault();afterevent.stopImmediatePropagation();. - Travesty3