取消选择as3中的选择项

时间:2013-02-04 13:04:35

标签: actionscript-3 flash action

首先,我在_txtbtn创建了txtfield。然后我选择任何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);
}

1 个答案:

答案 0 :(得分:0)

我的直觉告诉我,你可能已经注册了一个以上的鼠标,以及#34; 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);