2011-05-18 67 views
2

我有一個下拉閃光燈,兩個下拉按鈕。在對象我用添加這些事件偵聽器:AS3 mouseChildren = false將事件監聽器添加到兒童

addEventListener(MouseEvent.MOUSE_OVER, expand); 
addEventListener(MouseEvent.MOUSE_OUT, contract); 

public function expand(evt:MouseEvent):void 
     { 
      if(!expanded) 
      { 
       TweenMax.to(this.back, 0.15, {height:82, onComplete:function(){ 
        music.alpha = 1; 
        music.y = 32; 
        quit.alpha = 1; 
        quit.y = 55; 
       }}); 
       expanded = true; 
      } 
     } 

    public function contract(evt:MouseEvent):void 
    { 
     if(expanded) 
     { 
      this.music.alpha = 0; 
      this.music.y = 0 - this.height; 
      this.quit.alpha = 0; 
      this.quit.y = 0 - this.height; 
      TweenMax.to(this.back, 0.15, {height:0}); 
      expanded = false; 
     } 
    } 

爲了使菜單正常工作,我需要添加此代碼,以便孩子不與這兩個功能觸發干擾。

this.mouseChildren = false; 

現在我要上下降兩個按鈕下拉至點擊並觸發不同的事件,但由於mouseChildren設置爲false也不會聽的事件。我如何將事件分配給我的對象的孩子,而不是由這兩個子元素的交互中斷擴展,合同功能?

感謝, 布倫南

回答

3

你就不能放:

this.mouseChildren = true; 

的功能的onComplete內爲您的擴展吐溫

然後:

this.mouseChildren = false; 

內你的收縮補間的onComplete函數的?

僅當菜單展開時,纔會在這些孩子上啓用鼠標。

+0

這是行不通的。只要它將其設置爲true,觸發合同的事件偵聽器。 – brenjt 2011-05-18 22:26:57

+1

好吧,只要將事件偵聽器更改爲ROLL_OVER和ROLL_OUT,它就會工作!謝謝 – brenjt 2011-05-18 22:31:06

+0

這個想法拯救了我的一天,謝謝! – Delcasda 2014-02-06 15:53:59