0

首先,我在_txtbtn. 然后我选择任何 mc 并在它们上创建许多侦听器。现在我想在单击时删除侦听器_can。所以我创建了_unselect函数。但它没有按预期工作。

function _txtbtn(e:*):void
{
myText = new TextField();
mc3 = new MovieClip();
myText.text = "text...";
myText.type = "input";

mc3.addChild(myText);
addChild(mc3);
mc3.x = _can.x;
mc3.y =  p;
p = mc3.y + mc3.height + 10;
 this.mc3.addEventListener(MouseEvent.MOUSE_DOWN,_select);


function _select(e:MouseEvent):void
{

tool_stage.combo.addEventListener(Event.CHANGE,_font);
tool_stage.steeper.addEventListener(Event.CHANGE,_size);
tool_stage.italic.addEventListener(MouseEvent.CLICK,_bold);
tool_stage.colPicker2.addEventListener(ColorPickerEvent.CHANGE, changeColor1);
_can.addEventListener(MouseEvent.MOUSE_DOWN,_unselect);
}

function _unselect(e:*){
mc3.removeEventListener(MouseEvent.MOUSE_DOWN,_select);
}
4

1 回答 1

0

我的直觉告诉我,您可能已经为“mc3”注册了多个鼠标按下的听众。在不了解代码的全部范围的情况下,我建议您在将鼠标按下侦听器添加到 mc3 之前添加以下行。

// This is the new line, it is just to remove any prior event registrations just to be safe.
this.mc3.removeEventListener(MouseEvent.MOUSE_DOWN,_select);
//This is the original line of the code, leave it as is
this.mc3.addEventListener(MouseEvent.MOUSE_DOWN,_select);
于 2013-02-04T16:39:51.583 回答