2011-07-25 108 views
1

我有一个Flash射击游戏,当用户拍摄一个瓶子后,我播放销毁动画并将其从屏幕上移除。问题是当用户点击的速度太快时,就像超人一样快速进入该方法两次,无论如何。有谁知道如何解决这个问题?如何在点击对象后禁用鼠标点击?

下面是代码:

public function bottleHasClicked(bottle : BottleBase) : void { 
     bottle.mouseEnabled = false; 
     collectedBottles++; 
     bottlesInRound--; 

     gameSound.getShootSound().playSound(); 
     gameSound.getBottleSound().playSound(); 


     ArrayUtil.removeValueFromArray(elementsInScreenArray, bottle); 
     cleanElementsTimer[bottle].stop(); 
     delete cleanElementsTimer[bottle]; 

     if (bottlesInRound == 0) { 
      stopElementsTimer(); 
      showElementsWaitForSeconds(0.5); 
     } 

     createBulletHole(); 
     bottle.play(); 
    } 

我做的第一件事是禁用对象的鼠标,它仍然会发生。我只有在我要再次展示瓶子时才能启用它。

+0

你是如何要求这种方法? –

回答

1

this post

如果你只需要拥有鼠标 禁用单个元素,使用mouseEnabled属性。但是,如果您想要将鼠标事件级联到禁用的 特定对象上的子元素为 ,请确保将mouseChildren属性设置为 。第二个发现之前,我仍然对 响应鼠标事件感兴趣,尽管我已经禁用了它们。

+0

我试图这样的事情: \t \t \t为(VAR I:编号= 0; I Gilson

0

难道你在瓶子类中没有“玩”变量吗?你可以在调用bottleHasClicked()之前检查它。另外,提供addListener调用会有所帮助。

0

嗯,我想有几种方法可以做到这一点,但这取决于你如何注册鼠标点击事件。如果您要为每个Bullets调用addEventListener(MouseEvent.Click,...)以最终到达bottleHasClicked,那么您可以通过调用removeEventListener(...)来简单地移除对象上的侦听器;

如果您使用的是其他方法,另一个简单的方法是通过添加一个布尔值来检查瓶子是否已经被点击(让我们将该变量称为“wasClicked”,并且Bottle的构造函数应该将其设置为假)。在这种情况下,你可以做的是将上面的代码更改为如下所示:

public function bottleHasClicked(bottle : BottleBase) : void 
{ 
    if(!bottle.wasClicked) 
    { 
     bottle.wasClicked = true; 
     bottle.mouseEnabled = false; 
     collectedBottles++; 
     bottlesInRound--; 

     gameSound.getShootSound().playSound(); 
     gameSound.getBottleSound().playSound(); 


     ArrayUtil.removeValueFromArray(elementsInScreenArray, bottle); 
     cleanElementsTimer[bottle].stop(); 
     delete cleanElementsTimer[bottle]; 

     if (bottlesInRound == 0) { 
      stopElementsTimer(); 
      showElementsWaitForSeconds(0.5); 
     } 

     createBulletHole(); 
     bottle.play(); 
    } 
} 

它应该这样做。