View Full Version : Actionscipt to hide all MCs with same prefix???
3dron
February 7th, 2007, 06:19 AM
How can I easily hide all my layers that begin with "opt_" onLoad of an swf?
I want any easy function I can put in a bunch of different swfs, that will always hide the instances of MCs with certain "wildcard" names?
Ron R. Jr.
pablo 2006
February 7th, 2007, 09:14 AM
I've written a quick script for you. It loops through all instance names and checks for "_". You can change "_" to whatever *wildcard you need. This will hide all Mcs with an "_" in the name on the top level.
function wildCardSearch(clip:MovieClip):Void {
//loop through obects
for (i in clip) {
//select only MovieClips
if (clip[i] instanceof MovieClip) {
//Check all Mc names for a "_"
var wildCard = clip[i]._name.indexOf("_");
trace(wildCard);
//if "_" is located, make this Mc invisible
if (wildCard >= 0) {
clip[i]._visible = false;
}
}
}
}
//Passes in _level0 (ie everything on _root)
wildCardSearch(this);
If you have nested Mc's that you also need to hide, you'll need to call the wildcard function from within the nested Mc eg...
_parent.wildCardSearch(this);
Hope this helps,
Pablo
3dron
February 8th, 2007, 07:05 PM
_global.wildCardHide = function (clip:MovieClip, pattern):Void {
for (i in clip) {
if (clip[i] instanceof MovieClip) {
var wildCard = clip[i]._name.indexOf(pattern);
trace(wildCard);
if (wildCard >= 0) {
clip[i]._visible = false;
}
}
}
}
I just thought Flash might allow something as simple as:
opt_* = false;
where "opt_" is the pre-fix of all MCs I want to hide.
Ron R
pablo 2006
February 9th, 2007, 01:01 PM
Nope, life's seldom that easy.
:D
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.