Skip to main content
Inspiring
December 19, 2012
Answered

Find and hide suffix _Level code fails on >1 MC

  • December 19, 2012
  • 1 reply
  • 1298 views

Hi,

Flash CS5 AS3

The following code is designed to hide any MovieClips with _Level2 or _Level3 at the end of their instance name.

I now see its only working if there is one MC on stage with a suffix of _Level2 or _Level3 in its instance name.

Introduce a second MC and only the first remains hidden, all others remain visible.

What should the code be to make this work on more than one MC please ?

The MC's with instance name suffix Level2 or Level3 sit within an MC called Map_Collection as per the code.

for(var i:uint=0; i<this.numChildren; i++){ 

     var object:* = Map_Collection.getChildAt(i);

     if(String(object.name).indexOf("_Level2") > -1
  || String(object.name).indexOf("_Level3") > -1 ){

                object.visible=false;

     }

}

By a sheer fluke I thought it was working, but I now discover all the MC's that were hidden sat within another MC also with suffix _Level2 and it saw that, hid it and hid those within as well....doh !!!!

Envirographics

(P.S. code from NedMurphy...thanks)

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

"this" can not be the same object as "Map_Collection", so one of them needs to be changed, probably "this"

     for(var i:uint=0; i<MapCollection.numChildren; i++){ 

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
December 19, 2012

"this" can not be the same object as "Map_Collection", so one of them needs to be changed, probably "this"

     for(var i:uint=0; i<MapCollection.numChildren; i++){ 

Inspiring
December 19, 2012

Hi and thanks.

As such then the name of the MC within which the MCs to be hidden reside needs to go in there, I overlooked that as it wasnt obvious to me in the original post which sought to hide many.

What if the MC's to be hidden reside in two different MC's ?

Envirographics

Ned Murphy
Legend
December 19, 2012

You would need to run two loops, one for each container mc... you could probably do it in a similar looping fashion, though it could waste processing if there are alot more children sharing the same parent as those two mc's..