Skip to main content
wfzen
Inspiring
May 27, 2015
Answered

Use this properly

  • May 27, 2015
  • 1 reply
  • 530 views

I'm trying to change visibility of objects on screen using this.

this["answers" + currentQuestionNum + "." + "answer" + currentQuestionNum + "_d"].visible = 0

so if currentQuestionNum = 1, it does answers1.answer1_d.visible = 0

but I got the following error:

TypeError: Error #1010: A term is undefined and has no properties.

  at _211_fla::interaction_1/setupQuestionFrame()

  at _211_fla::interaction_1/frame3()

  at flash.display::MovieClip/gotoAndStop()

  at _211_fla::interaction_1/gotoNextQuestion()

  at MethodInfo-163()

If I do:

trace("answers" + currentQuestionNum + "." + "answer" + currentQuestionNum + "_d");

It shows the string answers1.answer1_d correctly.

How can I make it work?

Thanks,

This topic has been closed for replies.
Correct answer dmennenoh

You need two sets of brackets - one for the main object, and one for its child. This should work:

this["answers" + currentQuestionNum]["answer" + currentQuestionNum + "_d"].visible = 0;

1 reply

wfzen
wfzenAuthor
Inspiring
May 27, 2015

I searched on Error #1010: and one possibility is that the object is not there when the script runs. It does not look like it as I can put answers1.answer1_d.visible = false and the object would be hidden without any error.

dmennenohCorrect answer
Inspiring
May 28, 2015

You need two sets of brackets - one for the main object, and one for its child. This should work:

this["answers" + currentQuestionNum]["answer" + currentQuestionNum + "_d"].visible = 0;

wfzen
wfzenAuthor
Inspiring
May 28, 2015

You're the savior, dmennenoh. THANKS A LOT!

Never thought of that you don't need to include "." for it to know parent and child relationship.

Thanks again for solving this issue that bothered me for a long time.