Reputation: 5474
I am trying to have a TextInput
inside a button, but it seems that my button intercept all mouse events before my TextInput
.
Basically I have a class BaseButton
like that :
public class BaseButton extends Sprite
{
[...]
public function addMouseListeners( target : InteractiveObject = null ) : void {
if ( !target ) target = this;
target.addEventListener(MouseEvent.ROLL_OVER, mouseOverHandler, false, 0, true);
target.addEventListener(MouseEvent.ROLL_OUT, mouseOutHandler, false, 0, true);
target.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, false, 0, true);
target.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler, false, 0, true);
}
[...]
}
The class where I want to put the TextInput
extends BaseButton
public class AddFilterDropDownListItem extends BaseButton {
private var _input:TextInput;
public function AddFilterDropDownListItem() {
super();
}
override protected function setupAssets():void {
_input = new TextInput();
_input.height = 40;
_input.width = 240;
this.addChild(_input);
_input.appendText("Add..");
}
}
I cannot edit the TextInput
, the click event seems to be captured by BaseButton
. I don't understand why, as a child of BaseButton
, my TextInput
hasn't the priority?
I can resolve my problem by adding the TextInput
by adding it to the parent :
override protected function setupAssets():void {
_input = new TextInput();
_input.height = 40;
_input.width = 240;
parent.addChild(_input); //<------ dirty solution
_input.appendText("Add..");
}
Can you explain me why it is failing? And how can I resolve it cleanly?
PS: I cannot change the architecture of the project. My class has to extend BaseButton
and I cannot change BaseButton
.
Upvotes: 0
Views: 114
Reputation: 22604
The BaseButton
class probably has mouseChildren
set to false
, which prevents any nested DisplayObjects from receiving mouse events. Everything should work as expected, if you set mouseChildren = true;
on your derived class.
Upvotes: 1