Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

accessing items in array

Status
Not open for further replies.

sarak

Programmer
May 3, 2001
25
US
Periodically as my movie runs I'd like to loop through an array of movie clips and change the visibility property of each. I'm having trouble figuring out how to reference each MC in my "for in" loop. (I'll be adding to my array as the movie runs and will have no idea how many MCs my array holds at any given time.) Here's my idea...
Code:
function changeVis () {
	allMC = ["MC1", "MC2","MC3"];
	for (n in allMC) {
		n = allMC.length;
	//the next line is specifically where I'm having trouble...	
	setProperty (HOW_ARE_INDIVIDUAL_MCS_REFERENCED_HERE?, _visible, 0);
	}
}

Thanks in advance for any help!
 
_root.mcname._visible, "false");




try that!
logo.gif


carlsatterwhite@orlandomediasolutions.com
 
Try this :

function changeVis () {
allMC = ["MC1", "MC2", "MC3"];
for (var n = 0; n<allMC.length; n++) {
_root[allMC[n]]._visible = 0;
}
} Regards

Big Bad Dave

davidbyng@hotmail.com
 
Thanks for the response! However, I won't know the how many movie clips there are in the array. These MCs are created with the attachMovie action as a result of a button push. So, the array may contain MC1 and MC2... or it might contain 100 movie clips, MC1 through MC100.

As suggested, I could name the MCs individually, but this seems inefficient as I would have to include a command to change the visibility properties of MCs that may not exist in my array yet.

I'd like to loop through the array and change the visibility property of each movie clip in it, whether there's just MC1... or MC1 through MC100.

For that reason, it seems I need to refer to the MC, at least initially, by it's place in the array. Any ideas about how I can access the visibility property of each movie clip in my array?
 
Check this :


_root.total = 1;
function changeVis (vis) {
for (var n = 0; n<_root.total+1; n++) {
_root[&quot;MC&quot;+n]._visible = vis;
}
}
function addClip () {
var numb = _root.total;
numbadd = numb+1;
duplicateMovieClip (_root.MC1, &quot;MC&quot;+numbadd, numbadd);
_root[&quot;MC&quot;+numbadd]._x = _root[&quot;MC&quot;+numb]._x+_root.MC1._width+5;
_root.total += 1;
}
function delClip () {
if (total != 1) {
removeMovieClip (_root[&quot;MC&quot;+_root.total]);
_root.total += -1;
}
} Regards

Big Bad Dave

davidbyng@hotmail.com
 
Thank you Dave!! Got it working perfectly now. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top