2013-02-04 79 views
0

首先,我在_txtbtn處創建txtfield。然後我選擇任何mc並在它們上創建許多監聽器。現在我想要刪除監聽器,當我點擊_can。所以我創建了_unselect函數。但它不能按預期工作。取消選擇as3中的選擇項目

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); 
} 

回答

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); 
相關問題