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

For loop and accessing objects by instance name.

New Here ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

Hey guys,

What I am trying to do should be very simple, I want to make several movieclip objects not visible by using a for loop.

Here is what I currently have...

for (var i:Number=1; i<8; i++){

          high.visible = false;

}

So I have 8 movieclip objects that have instance names of "high1", "high2", "high3" and so forth up to 8

What would be the correct syntax for this line of code to make this work?

high.visible = false;

Thank you.

TOPICS
ActionScript

Views

999

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

LEGEND , May 23, 2012 May 23, 2012

You can use String values to target instances if you use bracket notation:

for (var i:Number=1; i<8; i++){

          this["high" +String(i)].visible = false;

}

Votes

Translate

Translate
LEGEND ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

You can use String values to target instances if you use bracket notation:

for (var i:Number=1; i<8; i++){

          this["high" +String(i)].visible = false;

}

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
New Here ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

Thank You so much to both of you, that works perfect! 

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 ,
May 23, 2012 May 23, 2012

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
Enthusiast ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

All credit goes to Ned he wrote faster and better  

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
New Here ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

LATEST

Haha both of you answered at the same time literally.  Wish i could mark you both correct

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
Enthusiast ,
May 23, 2012 May 23, 2012

Copy link to clipboard

Copied

for (var i:Number=1; i<8; i++){

      this["high"+i].visible = false;

}

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