Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Animate CC Canvas reference instance with variable

New Here ,
Oct 22, 2020 Oct 22, 2020

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!

 

201
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 22, 2020 Oct 22, 2020

Hi.

 

Use bracket notation. For example:

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

 

Regards,

JC

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2020 Oct 22, 2020
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 22, 2020 Oct 22, 2020

Got it! it is

this["player"+i].score

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 22, 2020 Oct 22, 2020
LATEST

Thanks for the replies!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines