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!

Affect all Movie Clips

Status
Not open for further replies.
Dec 24, 2001
857
GB
Is there a way to affect all movie clips, i.e. set them all to 0% Alpha (using Flash 5)

Thanks...
 
You could use the for ... in loop:
Code:
for (var property in _root) {
    if (typeof _root[property] == "movieclip") {
        trace("Found instance: " + _root[property]._name);
        _root[property]._alpha = 0;
    }
}
That should find all the clips in the main timeline, trace a statement telling you what they are called, and change all their alpha values to 0.
 
There are quite a few movie clips within movie clips which are also within other movie clips. I want to be able to have a button which just sets the property of every movie clip to 0% alpha without having to type them all in. I'll give this a try.

Thanks
 
Nearly...it sets all the movie clips on the root to 0% alpha. Any movie clips within movie clips are unaffected...

Rgds
 
Okay, try this recursive function:

function findClips (myClip) {
for (var property in myClip) {
if (typeof myClip[property] == "movieclip") {
myClip[property]._alpha = 0;
findClips(myClip[property]);
}
}
}

Invoke this function on the main timeline with:

findClips (_root);

and it will find each movieClip in the main timeline, set it to 0% alpha, then check to see if there are any movieClips nested within it. If not, it will move to the next movieClip in the main timeline.
 
Thanks...I'll have to give it a try tomorrow at work. I'll let you know how I get on.
 
I tried putting it in, but it had no effect. So then I added an extra frame so the movie could loop, but then it just locked up and I got that message saying something along the lines of:

A script you are running is causing Flash to run slowly. Do you want to abort it now?


Rgds
 
Okay - I had a look at it myself and I see the effect. I'm just not sure how to fix it. The script works if anything OTHER than the main timeline is entered ... it finds all the nested clips and then stops. I don't know why it won't get all the clips off the main timeline.

I'll keep thinking and if I arrive at a solution I'll let you know ... if I can't get the script I sent you to work I'll create a work-around using an array to store primary clips and use the recursive function to search each of those.
 
Okay, I've tested this and it works ... not quite as efficient as the first attempt, but 100% more successful!
Code:
function findPrimaryClips () {
    primaryClips = new Array;
    i = 0;
    for (property in _root) {
        if (typeof _root[property] == "movieclip") {
            primaryClips[i] = _root[property]._name;
            i += 1;
        }
    }
    for (j= 0; j < primaryClips.length; j++) {
        trace (primaryClips[j]);
        eval(primaryClips[j])._alpha = 0;
        findNestedClips(eval(primaryClips[j]));
    }
}
function findNestedClips (myClip) {
    for (property in myClip) {
        if (typeof myClip[property] == &quot;movieclip&quot;) {
            trace (myClip[property]._name);
            myclip[property]._alpha = 0;
            findNestedClips (myClip[property]);
        }
    }
}
Works the way I described above ... finds all primary MCs (those on the main timeline), stores them in an array, then searches each one with a recursive function for nested MCs. Call the function with this code:
Code:
_root.findPrimaryClips();
You can take the trace() statements out, if you like ... they will just tell you which clips have been found.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top