views:

4274

answers:

6

Hello,

has anyone ever tried to get the list of all the movieclips (even the nested ones) that are on Stage at a specified stopped (and current) frame in Flash 8, AS 2?

I did the following:

for(i in _root){
if(typeof(_root[i])=="movieclip"){
trace(_root[i]);}
}

But this is good for a first level search: that is, if inside the movieclips you have other movieclips, you can't reach them. Furthermore, inside a movieclip there can be more then one movieclip.

Has anyone ever tried to do what I'm trying to do?

Bye!

A: 

My AS2 experience is pretty limited (I've done bit of AS3), but here goes:

What if you wrote a recursive function that, if it encountered a movieclip, would look through all of it's child objects for other movie clips (and did the same for any movieclips it found there, etc.)? The function could take object parameter, as well as an array of "found" clips that is added to on each pass.

I wish I could write the code that would do this, but (as I said), I'm not much of an AS2 guy :\

inkedmn
The fact is that a specific level can "host" dozens of movieclips: you can have one, as you can have 100. So a recursive function (that for sure IS the way) could easily become a very "consuming" task.
Btw, here is our function:function stopMCs(mc:MovieClip):Void { mc.stop(); for (i in mc) { if (mc[i] instanceof MovieClip) { mc[i].stop(); stopMCs(mc[i]); } }}
+3  A: 

Are you just trying to trace? If so there's a nice little undocumented utility called ObjectDumper that can do this.

This is probably the best explanation of it out there

So what you can do is this:

import mx.data.binding.ObjectDumper;

trace(ObjectDumper.toString(_root));

There may be a lot of extras (functions, variables, etc) in there, so there are additional parameters you can use:

ObjectDumper.toString(obj, showFunctions, showUndefined, showXMLstructures, maxLineLength, indent)
nerdabilly
Hi, very valuable suggestion: I totally ignored the existence of ObjectDumper. I can't try at the moment: my goal is not exactly the trace but to stop all the movieclips, even the nested ones, found in stage at the current frame.
If the ObjectDumper.as code is this http://www.elegancia2.com/TestSite/mx/data/binding/ObjectDumper.as I'm not sure it works with movieclips.
you're right, I just did a quick little experiment with it and it's not listing the movieclips. I think your only option is a recursive function. Or if you have control when the clips are placed, place each clip into an array when it goes on the stage, then loop through the array and stop.
nerdabilly
I've no real control: they provide me with compiled swf made by third party content developers and I should control all the timelines of all the movieclips at the currentframe using the main videorecorder commands.
A: 

I did something very similar to this today. My clips where part of a navigation and were duplicates of one movieclip. In order to find out how many there were I put a variable on the main stage that was incremented up by actions in the movieclips. I set a interval to wait till all the clips were account for, then used a loop to fill in the interactivity to my navigation. Works pretty well too. Hope this helps someone.

A: 

You can do something like that by adding a function to the MovieClip class:

MovieClip.prototype.StopEverything = function()
{
    stop();
    for (var i in this) {
     if (typeof(this[i]) == "movieclip") {
      this[i].StopEverything();
     }
    }
}
ASSetPropFlags(MovieClip.prototype, ["StopEverything"], 1);

That last bit ASSetPropFlags is something I found that allows StopEverything to iterate over built-in classes like MovieClip using for..in for every field, even hidden properties and items. Without ASSetPropFlags, StopEverything() might not hit every contained movie clip.

Aaron
I posted a similar solution in a comment (Feb 2 at 20:01).
A: 

The reason the AS2.0 undocumented ObjectDumper feature does not enumerate movieclips at the root is because it ignores nameValue pairs at the Object's root level, which is an egregious flaw (to say the least), since the very definition of an associate array is an array/object that is made up of nameValue pairs at it's root.

For example: trace(ObjectDumper.toString({myName:"myValue"})) //output = "". No wonder they left this "feature" undocumented. Frankly, I think it's amazing that there is no built-in way to easily and reliably enumerate all the contents of an object for debugging purposes in either AS2 nor AS3. If you search the net all you'll find are hack jobs of for...in loops that only look at the root of an array ... nothing recursive.

davea0511
A: 

exactly as suggested by inkedmn

printStuff first checks to see if the value it finds is a mc then if it is, traces and then checks inside it for more mcs.

printStuff = function(object){
    for(var x in object){
        if(typeof(object[x])=="movieclip"){
            trace(object[x]);
            printStuff(object[x]);
        }
    }
}
printStuff(_root);

oh....and sorry for being a year and some change late...

Steffen