When my function buildingBuilt is called, it is dispatching an event like so:

dispatchEvent(new Event("Built"));

I've got, in my Toolbar.as a listener that triggers a timer when he heard "built".

Every 10 second my string "money" is dropping 500.

Toolbar.as

drop500=new Timer(10000);
drop500.addEventListener(TimerEvent.TIMER, dropMoney);
addEventListener("Built", timerMoney, false, 0, true);

private function timerMoney(event):void{
            drop500.start();

}

private function dropMoney(event):void {
   money.text = String( Number(money.text ) - 500 );
}

Question : The event "Built" is dispatched by other function. Is it possible to add -500 every-time "Built" is heard ?

So, if "Built" is dispatched once : "money" is dropping 500 every 10 sec, if "Built" is dispatched twice : "money" is dropping 1000 every 10 sec and so on.

有帮助吗?

解决方案

Try updating your code like so,

  var moneyDropper:int = 0;

  private function timerMoney(event):void {

     if(moneyDropper == 0)
     {        
         drop500.start();            
     }
     else
     {
         moneyDropper += 500;
     }
  }

  private function dropMoney(event):void {
      money.text = String( Number(money.text ) - moneyDropper);
  }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top