1 Reply Latest reply on Dec 15, 2017 6:55 AM by kglad

    Help! How to create a count up in Animate?

    Nicolas_Beaulieu

      I'm creating an animated info graphic about tigers and need a count up from 0 to 3200 to show the current population of tigers in Asia.

      This is my current Code:

       

      var countUpInc:int = 1;
      var totalSecs:int = 30000;
      var countUp = 0;
      
      
      var countTimer:Timer = new Timer(countUpInc);
      countTimer.addEventListener(TimerEvent.TIMER, timerHandler);
      countTimer.start();
      
      
      function timerHandler(e:TimerEvent): void {
        if (countUp == 3200) {
        countTimer.stop();
        countUp = totalSecs;
        } else {
        countUp = countUp + countUpInc;
        counter.countertext.text = countUp;
        trace(countUp);
        }
      }
      

       

      the code runs and displays 300 then crashes as shown by the trace.

       

      I get the error:

      " TypeError: Error #1009: Cannot access a property or method of a null object reference.

      at TigerInfographic_fla::MainTimeline/timerHandler()[TigerInfographic_fla.MainTimeline::fram e210:17]

      at flash.utils::Timer/_timerDispatch()

      at flash.utils::Timer/tick() "

       

      i don't know how to fix it.

      .fla file: NBeaulieu_FinalAnimation.zip - Google Drive