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

Converting a string to a movie clip name

Contributor ,
Mar 27, 2017 Mar 27, 2017

Copy link to clipboard

Copied

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!

Views

298

Translate

Translate

Report

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));

Votes

Translate

Translate
LEGEND ,
Mar 27, 2017 Mar 27, 2017

Copy link to clipboard

Copied

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

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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));

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

Yes, Kglad.

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

Thanks much!

Thanks also, Colin.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

you're welcome.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

All there in the manual...

Property accessors - JavaScript | MDN

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thanks ClayUUID

good resource.

Votes

Translate

Translate

Report

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