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

Converting a string to a movie clip name

Contributor ,
Mar 27, 2017 Mar 27, 2017

Hi All,

I'm using Animate CC to build an HTML5<canvas> final product.

Again, I'm still learning the terminology so I can do effectively search for answers. This one is eluding me:

How do I convert a string, like "myInstanceName" to something I can use (as the name of the instance) in a line of code like:

stage.myInstanceName.addEventListener("click", myFunction.bind(this));

Thanks much!

517
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

correct answers 1 Correct answer

Community Expert , Mar 27, 2017 Mar 27, 2017

an instance name is not a string so you can use it just like colin indicated.

but if you have a string, you would use:

this[myString].addEventListener('click',myFunction.bind(this));

Translate
LEGEND ,
Mar 27, 2017 Mar 27, 2017

Stage is perhaps not the same location as where myInstanceName is. This should work:

this.myInstanceName.addEventListener("click", myFunction.bind(this));

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 ,
Mar 27, 2017 Mar 27, 2017

an instance name is not a string so you can use it just like colin indicated.

but if you have a string, you would use:

this[myString].addEventListener('click',myFunction.bind(this));

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
Contributor ,
Mar 27, 2017 Mar 27, 2017

Yes, Kglad.

I do have a string and that    "this[myString].addEventListener..."    works.

Thanks much!

Thanks also, Colin.

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 ,
Mar 27, 2017 Mar 27, 2017

you're welcome.

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 ,
Mar 27, 2017 Mar 27, 2017

All there in the manual...

Property accessors - JavaScript | MDN

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
Contributor ,
Mar 31, 2017 Mar 31, 2017
LATEST

Thanks ClayUUID

good resource.

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