|
-
removing selected movieclips
Hi there!!
I have a button that clears the stage(removes all mcs) using this code:
on (press)
{
for (name in _root)
{
if (typeof (_root[name]) == "movieclip")
{
removeMovieClip(_root[name]);
}
}
}
However I want to keep all the instances of ONE of my movieClips on the stage. anyone has any idea how to do this?
Cheers!!
-
OOP is one letter from OOPS
on (press)
{
for (name in _root)
{
if (_root[name]._name != "nameToKeep")
{
removeMovieClip(_root[name]);
}
}
}
my syntax migth be a bit off, but I think that is the general idea you are going for.
-
Thanks kortex for your suggestion, this works so long as you try to keep one instance of a movieClip becuase _name targets one instance of a movieClip at a time( I might be wrong but this is how I think it works). but as I mentioned I want to keep all instances of a particular movieClip on the stage. I am working on it, please let me know if you found a fix for this.
Thanks
-
Flashmatics
Suppose all the movieclips you wanna keep are "keep1", "keep2", "keep3", etc
on (press)
{
for (name in _root)
{
if (typeof (_root[name]) == "movieclip" && name.indexOf("keep") == -1)
{
removeMovieClip(_root[name]);
}
}
}
-
Thanks Silentweed
it gave me the right idea, however I modified your code slightly to:
on (press)
{
for (name in _root)
{
if (typeof (_root[name]) == "movieclip")
{
if(name.indexOf("keep") >= 1)
{
//do nothing ignore them all!!
}
//else remove everything else!
else
{
removeMovieClip(_root[name]);
}
}
}
}
because && condtion cuases problem in removing other mcs when is set to -1
(until "keep" mc is not set to -1 all mcs remains on the stage)
thanks anyways it sure helped me!!
-
Flashmatics
np dude, however
if(typeof (_root[name]) == "movieclip" && name.indexOf("keep") == -1 ){}
is only true when it is a movieclip AND the name does not contain the string "keep" present so the above would get rid of all movieclips which do NOT have the string "keep" in their instance name
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|