To expand on this (since I'm now awake!) what method I use depends on
how I want to access the child objects.

If I just want a list to iterate over/trawl through, I use an Array.

If I want to access by name, I use an Object.

The reasons I don't normally directly rely on the the childlist of the
container object include:
- I can remove/add a child but still have a reference in the Array
- I can do a bunch of stuff to those clips without affecting any other
children of the container, like: iterate through the array,
reorder/reindex just those children, delete just those children,
_count_ just those children.
- I don't have to worry about checking the return types of the objects
in the array, because I know what's stored in there. Whereas using
getChildByName(), I know I'm getting a DisplayObject back, but don't
know exactly what type - I have to check.

Those last few might seem a bit peculiar - why shouldn't I know
exactly what the child objects are? This comes from two places:
- I may mix arrays of different children into the same container (e.g.
a bunch of target clips, a bunch of draggable clips - or, for a game,
the player Sprite and the enemy Sprites). Having two arrays is much
better than relying on the childList in this case.
- I am not the only person working on this code, and can't rely on
another coder not adding in a decorative background or border to my
container, or an extra graphics, or...

I hope that makes sense. And is a better answer than my earlier one. :-D


(mmm... sweet caffeine...)


Ian

On Wed, Dec 17, 2008 at 2:28 AM, Matt S. <mattsp...@gmail.com> wrote:
> I wasnt actually the original question-asker, but thanks :)
> I was just curious about the actual performance hit from getChild.
>
> .m
>
> On Tue, Dec 16, 2008 at 5:57 PM, Taka Kojima <t...@gigafied.com> wrote:
>> I use the method I gave you earlier, adding elements to an array and
>> accessing them that way.
>>
>> Also, you can use getChildAt() if you know the index of the children, which
>> it sounds like you do if you have them named as you do... i.e. column1,
>> column2, column3
>>
>> On Tue, Dec 16, 2008 at 2:17 PM, Matt S. <mattsp...@gmail.com> wrote:
>>
>>> So as a general question, what is the preferred method if you're
>>> trying to get, say, dynamically generated children, eg
>>> "image1"...."image20" etc, from a container?
>>>
>>> .m
>>>
>>> On Tue, Dec 16, 2008 at 4:51 PM, Ian Thomas <i...@eirias.net> wrote:
>>> > Yes.
>>>
>>> > On Tue, Dec 16, 2008 at 9:08 PM, Anthony Pace <anthony.p...@utoronto.ca>
>>> wrote:
>>> >> isn't getting a child by name very slow?
>>> _______________________________________________
>>> Flashcoders mailing list
>>> Flashcoders@chattyfig.figleaf.com
>>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>>
>> _______________________________________________
>> Flashcoders mailing list
>> Flashcoders@chattyfig.figleaf.com
>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to