Skip to main content
Participant
September 16, 2026
Question

Keep getting error when using a js Ticker with a dynamic text field

  • September 16, 2026
  • 6 replies
  • 44 views

I’m working on incrementing a dynamic text field over time. I’ve tried a few different methods but the Ticker seems to be the best, but for some reason I keep getting a “Cannot set properties of undefined (setting 'text')” error when trying to set the field in the Ticker function.

I’ve tried setting the text field outside the function and it works just fine. I’ve also tried initializing the text field in a frame well in advance of the function, but that didn’t help either. If I send the function output to the console instead of the text field, it works just fine.

Here’s my code. Any ideas?

Thanks!

 

var i = 0;

createjs.Ticker.on("tick", tick);
function tick() { 

    this.bunting_count.text = i;

    //console.log(i); 
    i++;
    }

 

 

    6 replies

    Participant
    September 22, 2026

    Hey thanks! That did the trick! I’m guessing I needed to define the scope for the ticker before it would work with the dynamic text field I defined?

    JoãoCésar17023019
    Community Expert
    Community Expert
    September 22, 2026

    If you don’t set the scope, the default value for the “this” keyword inside of a event handler function will be the global window. So you either need to pass the scope, or maybe store a reference to the object on stage you want to access in variable outside the function, or also use bind.

    Participating Frequently
    September 17, 2026

    One thing I’d check is the Ticker callback timing. The callback may be firing before the text field has been created or added to the display list. Try starting the Ticker only after the text field is initialized, and verify the instance name matches exactly.

    Known Participant
    September 17, 2026

    It sounds like the text field reference is undefined when the Ticker callback runs. I’d check that the field exists before assigning .text, and make sure the callback is using the correct scope/reference to the dynamic text field. Logging the field itself inside the Ticker would also confirm whether it’s available at that point.

    JoãoCésar17023019
    Community Expert
    Community Expert
    September 16, 2026

    Hi.

    Try this instead:

    createjs.Ticker.on("tick", tick, this);


    https://createjs.com/docs/easeljs/classes/EventDispatcher.html#method_on

    Regards,

    JC

    kglad
    Community Expert
    Community Expert
    September 16, 2026

    “this” is probably out of scope.  eg, what does   the console show about this.bunting_count ?