Skip to main content
Participant
October 22, 2020
Question

Animate CC Canvas reference instance with variable

  • October 22, 2020
  • 3 replies
  • 241 views

I have multiple symbols on the main timeline with incremental instance names : player1, player2, player3

 

How can I reference these symbols with a string variable?

currentPlayer = 1

"player"+currentPlayer would reference "player1" for example

 

Is there a way to programatically reference these instances with a string variable? Or is there another way to reference these symbols without explicity calling them by name?

 

thanks!

 

    This topic has been closed for replies.

    3 replies

    Participant
    October 22, 2020

    Got it! it is

    this["player"+i].score

     

    Participant
    October 22, 2020

    Thanks for the replies!

    Legend
    October 22, 2020
    JoãoCésar17023019
    Community Expert
    Community Expert
    October 22, 2020

    Hi.

     

    Use bracket notation. For example:

    this["player" + currentPlayer].play();

     

    Regards,

    JC