Flash : List child Movieclips

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Flash : List child Movieclips

Antoine Gersant
Hi all,

I'm trying to access all child movieclips of a given movieclip but I
don't know how to do it. I've tried the following code but it doesnt
work (no loop iteration) :
var c = flash.Lib.current.createEmptyMovieClip('test', 46);
c.createEmptyMoviClip('t0', 0);
c.createEmptyMoviClip('t1', 1);
for (i in Reflect.fields(c)) {  trace('hello'); }

Any thought ?

Thanks in advance.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Iain Surgey
You could try using "getChildAt".

var c = flash.Lib.current.createEmptyMovieClip('test', 46);
c.createEmptyMoviClip('t0', 0);
c.createEmptyMoviClip('t1', 1);
var d : flash.display.MovieClip;
for (i in c.numChildren ) {  d = c.getChildAt(i); }

2010/1/23 Antoine Gersant <[hidden email]>
Hi all,

I'm trying to access all child movieclips of a given movieclip but I don't know how to do it. I've tried the following code but it doesnt work (no loop iteration) :
var c = flash.Lib.current.createEmptyMovieClip('test', 46);
c.createEmptyMoviClip('t0', 0);
c.createEmptyMoviClip('t1', 1);
for (i in Reflect.fields(c)) {  trace('hello'); }

Any thought ?

Thanks in advance.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Michael Baczynski-2
In reply to this post by Antoine Gersant
to iterate over all children (not recursive) you simply need;

var o:DisplayObjectContainer = c;
for (i in 0...o.numChildren)
{
   var child = o.getChildAt(i);
}

You could also use an iterator to traverse the display list like the one
here:
http://code.google.com/p/polygonal/source/browse/trunk/src/lib/de/polygonal/gl/DisplayListIterator.hx

so it's  just:

for (child in new DisplasListIterator())
{
    trace(child.name);
}

On 23.01.2010 23:50, Antoine Gersant wrote:

> Hi all,
>
> I'm trying to access all child movieclips of a given movieclip but I
> don't know how to do it. I've tried the following code but it doesnt
> work (no loop iteration) :
> var c = flash.Lib.current.createEmptyMovieClip('test', 46);
> c.createEmptyMoviClip('t0', 0);
> c.createEmptyMoviClip('t1', 1);
> for (i in Reflect.fields(c)) {  trace('hello'); }
>
> Any thought ?
>
> Thanks in advance.
>


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Antoine Gersant
Thank you very much but I'm using the AS2 API, which means that
DisplayObjectContainer is not an available solution for me. I should
have mentioned it in my first email.

Still thanks, anything else ?


Antoine Gersant

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Iain Surgey
I'm not familiar with AS2, but maybe you could try Type.getInstanceFields() instead of Reflect.Fields().

2010/1/23 Antoine Gersant <[hidden email]>
Thank you very much but I'm using the AS2 API, which means that DisplayObjectContainer is not an available solution for me. I should have mentioned it in my first email.

Still thanks, anything else ?


Antoine Gersant


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Antoine Gersant
No result at all with the following code either :

var c = flash.Lib.current.createEmptyMovieClip('test', 46);
c.createEmptyMoviClip('t0', 0);
c.createEmptyMoviClip('t1', 1);
for (i in Type.getInstanceFields(Type.getClass(c))) {
    trace("This text will never appear on screen :x");
    trace(i);
}


I also noted that Type.getClassName(Type.getClass(c)) outputs null so I
dont know how much the Type methods love the Movieclip class.


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Pimm Hogeling
Hello Antoine,

Could you please explain what you're trying to accomplish? I personally could not imagine a situation in which I would want to know who the children of a container are, except for in the debugging process. In other words, there might be another way to do whatever it is you're trying to do.

Thanks,

Pimm Hogeling

On Sun, Jan 24, 2010 at 01:25, Antoine Gersant <[hidden email]> wrote:
No result at all with the following code either :


var c = flash.Lib.current.createEmptyMovieClip('test', 46);
c.createEmptyMoviClip('t0', 0);
c.createEmptyMoviClip('t1', 1);
for (i in Type.getInstanceFields(Type.getClass(c))) {
  trace("This text will never appear on screen :x");
  trace(i);
}


I also noted that Type.getClassName(Type.getClass(c)) outputs null so I dont know how much the Type methods love the Movieclip class.



--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Antoine Gersant
I want to wipe out the content of a movieclip without losing its
position, scale, other dynamic properties (etc...) because I'm still
going to use this movie clip.
Thus, I want to loop through its child movieclips and use their
removeMovieClip() method.

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Pimm Hogeling
In that case I would store a reference to a child in a list while adding it. This way, one I iterate through that list, and remove them. Would that be possible in your situation?

On Sun, Jan 24, 2010 at 01:58, Antoine Gersant <[hidden email]> wrote:
I want to wipe out the content of a movieclip without losing its position, scale, other dynamic properties (etc...) because I'm still going to use this movie clip.
Thus, I want to loop through its child movieclips and use their removeMovieClip() method.


--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Antoine Gersant
Yes it is possible in my case. It's actually the solution I was using at the moment but I don't like it that much :x
Looks like I'll have to stick with it.

Thanks for your input.

Antoine Gersant

Le 24/01/2010 02:21, Pimm Hogeling a écrit :
In that case I would store a reference to a child in a list while adding it. This way, one I iterate through that list, and remove them. Would that be possible in your situation?

On Sun, Jan 24, 2010 at 01:58, Antoine Gersant <[hidden email]> wrote:
I want to wipe out the content of a movieclip without losing its position, scale, other dynamic properties (etc...) because I'm still going to use this movie clip.
Thus, I want to loop through its child movieclips and use their removeMovieClip() method.


--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Tony Polinelli
In reply to this post by Antoine Gersant
as you add the movieclips, push them into an array of list, then
iterate the list. This is often the best way, and only way (except the
Reflect.fields then checking type- which is a hack).

cheers

On Sun, Jan 24, 2010 at 11:58 AM, Antoine Gersant
<[hidden email]> wrote:

> I want to wipe out the content of a movieclip without losing its position,
> scale, other dynamic properties (etc...) because I'm still going to use this
> movie clip.
> Thus, I want to loop through its child movieclips and use their
> removeMovieClip() method.
>
> --
> haXe - an open source web programming language
> http://haxe.org
>



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Tony Polinelli
In reply to this post by Antoine Gersant
...only way in AS2

I  just missed the end of the sentence ;P




On Sun, Jan 24, 2010 at 12:25 PM, Antoine Gersant
<[hidden email]> wrote:

> Yes it is possible in my case. It's actually the solution I was using at the
> moment but I don't like it that much :x
> Looks like I'll have to stick with it.
>
> Thanks for your input.
>
> Antoine Gersant
>
> Le 24/01/2010 02:21, Pimm Hogeling a écrit :
>
> In that case I would store a reference to a child in a list while adding it.
> This way, one I iterate through that list, and remove them. Would that be
> possible in your situation?
>
> On Sun, Jan 24, 2010 at 01:58, Antoine Gersant
> <[hidden email]> wrote:
>>
>> I want to wipe out the content of a movieclip without losing its position,
>> scale, other dynamic properties (etc...) because I'm still going to use this
>> movie clip.
>> Thus, I want to loop through its child movieclips and use their
>> removeMovieClip() method.
>>
>> --
>> haXe - an open source web programming language
>> http://haxe.org
>
>
>
> --
> haXe - an open source web programming language
> http://haxe.org
>



--
Tony Polinelli
http://touchmypixel.com

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

jlm@justinfront.net
In reply to this post by Antoine Gersant
Probably better ways but this does not require any hacks

-swf-version 7
-swf test.swf
-main TestForAll
-swf-header 500:500:40:ffffff

import flash.MovieClip;

class TestForAll
{
   
   
private var _root: MovieClip;
   
private var _holder: MovieClip;
   
   
static function main() { new TestForAll(); }public function new()
    {
       
       
_root = flash.Lib.current;
       
_holder = _root.createEmptyMovieClip( 'holder', 0 );
       
var mc: MovieClip;
        mc
= _holder.createEmptyMovieClip( 'a', 0 );
        mc
._x = 100;
        mc
._y = 100;
        mc
.lineStyle( 0, 0xFF0000, 100 );
        mc
.lineTo( 20, 20 );
       
       
_holder.createEmptyMovieClip( 'b', 1 );
       
_holder.createEmptyMovieClip( 'c', 5 );
       
       
var i: Int = _holder.getNextHighestDepth();
       
var mc: Dynamic;
       
while( --i != -16384 )
        {
            mc
= _holder.getInstanceAtDepth( i );
           
if( Std.is( mc, MovieClip ) )
            {
               
trace( cast( mc, MovieClip )._name );
            }
        }
       
    }
}



On 23 Jan 2010, at 22:50, Antoine Gersant wrote:

Hi all,

I'm trying to access all child movieclips of a given movieclip but I don't know how to do it. I've tried the following code but it doesnt work (no loop iteration) :
var c = flash.Lib.current.createEmptyMovieClip('test', 46);
c.createEmptyMoviClip('t0', 0);
c.createEmptyMoviClip('t1', 1);
for (i in Reflect.fields(c)) {  trace('hello'); }

Any thought ?

Thanks in advance.

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

jlm@justinfront.net
correction?

while
--!= -16385 )

On 24 Jan 2010, at 03:26, Justin Lawerance Mills wrote:

while( --i != -16384 )


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

jlm@justinfront.net
sorry the formatting seems to add some spaces..  I am sure you can amend.

On 24 Jan 2010, at 03:30, Justin Lawerance Mills wrote:

correction?

while
--!= -16385 )

On 24 Jan 2010, at 03:26, Justin Lawerance Mills wrote:

while( --i != -16384 )

--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Pimm Hogeling
In reply to this post by Antoine Gersant
I would like to add that, though you don't like the solution, I prefer it over any solution that involves reflection.

You could extend the MovieClip class and add the list of children to it. Then override the addChild method so it adds the child to that list, besides the regular behaviour. That might help keeping your code clean.

On Sun, Jan 24, 2010 at 02:25, Antoine Gersant <[hidden email]> wrote:
Yes it is possible in my case. It's actually the solution I was using at the moment but I don't like it that much :x
Looks like I'll have to stick with it.

Thanks for your input.

Antoine Gersant

Le 24/01/2010 02:21, Pimm Hogeling a écrit :
In that case I would store a reference to a child in a list while adding it. This way, one I iterate through that list, and remove them. Would that be possible in your situation?

On Sun, Jan 24, 2010 at 01:58, Antoine Gersant <[hidden email]> wrote:
I want to wipe out the content of a movieclip without losing its position, scale, other dynamic properties (etc...) because I'm still going to use this movie clip.
Thus, I want to loop through its child movieclips and use their removeMovieClip() method.


--
haXe - an open source web programming language
http://haxe.org



--
haXe - an open source web programming language
http://haxe.org


--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

Antoine Gersant
I like this solution a lot Pimm thank you.
Thank you too Justin because you provided me with the most accurate
answer to the original question =)

Antoine Gersant

--
haXe - an open source web programming language
http://haxe.org
Reply | Threaded
Open this post in threaded view
|

Re: [haXe] Flash : List child Movieclips

jlm@justinfront.net
Antoine

Agreed Pimm is correct.

But I think for checking timeline loaded flash it is useful to be able  
to debug, and while using a 'for all in' loop maybe bad practice it is  
quite a common place approach among flash users, so I added  
information on this page:

http://haxe.org/doc/flash/as2_compare?lang=en

To save the next person asking.
Feel free to translate to french and to make text less verbose.

Cheers

;j

On 24 Jan 2010, at 14:12, Antoine Gersant wrote:

> I like this solution a lot Pimm thank you.
> Thank you too Justin because you provided me with the most accurate  
> answer to the original question =)
>
> Antoine Gersant
>
> --
> haXe - an open source web programming language
> http://haxe.org


--
haXe - an open source web programming language
http://haxe.org