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

Use this properly

Contributor ,
May 27, 2015 May 27, 2015

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,

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

Enthusiast , May 28, 2015 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;

Translate
Contributor ,
May 27, 2015 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.

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
Enthusiast ,
May 28, 2015 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;

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 ,
May 28, 2015 May 28, 2015
LATEST

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.

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