0
我想在按钮内部有一个TextInput
,但似乎我的按钮拦截了我的TextInput
之前的所有鼠标事件。TextInput永远不会获得焦点
基本上我有一个类BaseButton
这样的:
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);
}
[...]
}
,我想把类TextInput
扩展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..");
}
}
我不能编辑TextInput
,单击事件似乎是被BaseButton
捕获。我不明白为什么,作为BaseButton
的小孩,我的TextInput
没有优先权?
我可以将它添加到父解决通过添加TextInput
我的问题:
override protected function setupAssets():void {
_input = new TextInput();
_input.height = 40;
_input.width = 240;
parent.addChild(_input); //<------ dirty solution
_input.appendText("Add..");
}
你能解释我为什么会失败?我该如何干净地解决它? PS:我不能改变项目的体系结构。我的班级必须延长BaseButton
,我不能更改BaseButton
。
您可能必须显式设置'mouseChildren = true;',具体取决于'BaseButton'类默认的功能。我不太明白你为什么要在按钮中输入文字,但是 - 从用户界面的角度来看,这对我来说并不合适。 – weltraumpirat 2012-07-06 06:57:37
@weltraumpirat对我来说也没什么意义......我是这个项目的新手,并且第一次使用as3,但我已经可以说项目代码太可怕了......无论如何,你的解决方案就像一个魅力!谢谢。请做出回答,以便我可以将其标记为已接受;) – tibo 2012-07-06 07:23:55
当然可以:)不客气。 – weltraumpirat 2012-07-06 07:38:01