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

Possible to use this[String] after "."?

Community Beginner ,
Feb 09, 2013 Feb 09, 2013

In my code, the following works as it should:

trace (sampleVar.samplevar2.currentLabel)

The current label of an instance called "sampleVar2" inside of an instance called "sampleVar" is traced.

The following works, too.

trace (this["sampleVar"].samplevar2.currentLabel)

However, what I would like to do is use "this" and a string after the first dot like this:

trace (sampleVar.this[samplevar2].currentLabel) or
trace (this["sampleVar.samplevar2"].currentLabel)

however, I get an error message saying "A term is undefined and has no properties" when I do this.Is it possible to do something like this? How should I change my code?

TOPICS
ActionScript
358
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

LEGEND , Feb 09, 2013 Feb 09, 2013

Why do you want to do that?

In case you think "this" is required, you only need to have a reference object in front of the brackets... "this" is just a convenient substitute for when you don't have a named object.  But in your case you do...

sampleVar[samplevar2]  is all you need.

Translate
LEGEND ,
Feb 09, 2013 Feb 09, 2013
LATEST

Why do you want to do that?

In case you think "this" is required, you only need to have a reference object in front of the brackets... "this" is just a convenient substitute for when you don't have a named object.  But in your case you do...

sampleVar[samplevar2]  is all you need.

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