Skip to main content
Known Participant
February 9, 2013
Answered

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

  • February 9, 2013
  • 1 reply
  • 377 views

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?

This topic has been closed for replies.
Correct answer Ned Murphy

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.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
February 9, 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.