4 Replies Latest reply on Aug 26, 2016 7:11 AM by igor.heifetz

    Animate CC HTML5 Timer Error: "Uncaught TypeError: Cannot set property 'text' of undefined"

    igor.heifetz

      Guys, I am stuck for the third day and wonder if somebody can give me a clue what I am doing wrong. I am trying to create a simple timer in Animate CC Canvas HTML5 mode. I found a working javascript timer script and I am trying to adapt it to my needs.

      I am keep getting error "Uncaught TypeError: Cannot set property 'text' of undefined" in Console. For some reason I cannot update dynamic text with calculated time variable. I highlighted offensive line in my Action code below.


      Here is all the Action code that I have in my file:

      -------------------------------------------------

      var time = 0;

      var running = 0;

      this.btn_startPause.addEventListener("click", startPause.bind(this));

      this.btn_reset.addEventListener("click", reset.bind(this));

       

      function startPause() {

        if (running == 0) {

        running = 1;

        increment();

        this.startPause.text = "Pause";

        } else {

        running = 0;

        this.startPause.text = "Resume";

        }

      }

       

      function reset() {

        running = 0;

        time = 0;

        this.startPause.text = "Start";

        this.timeDisplay.text = "00:00";

      }

       

      function increment() {

        if (running == 1) {

        setTimeout(function () {

        time++;

        var mins = Math.floor(time / 10 / 60);

        var secs = Math.floor(time / 10 % 60);

        if (mins < 10) {

        mins = "0" + mins;

        }

        if (secs < 10) {

        secs = "0" + secs;

        }

        //console.log(mins + ":" + secs);

        this.timeDisplay.text = mins + ":" + secs;

        increment();

        }, 100);

        }

      }

      -------------------------------------------------

      I uploaded all my files online so you can see the error for yourself: HTML file; FLA file; and original working file I am trying to use.


      Can somebody point me in the right direction? (I know, it is somewhere in the area of RTFM (Read The Friendly Manual))

       

      Thank you!