Hi, accessing elements in an array is fundamental but I'm confused because I thought you had to use getChildAt(i) in a loop etc... to access them and "do something to them". However, I have some code that doesn't use getChildAt - it simply loops through the array. So why would I use getChildAt if I do't have to???
A 'child' is a display object that is added to another display object. E.g. if I had a cat sprite and I added a hat onto it (using the addChild function) then the hat sprite would be a child of the cat sprite. It just so happens that all children of a display object are stored in an array.
If you're looping through an array you'll just want to use a simple loop function
e.g.
for(var i:uint = 0; i < myArray.length; i++)
{
myArray[i].doSomething();
}
Hi, I have been googling and think9ng about it. I think the following explains it for a newbie. I know you are correct but I wanted to really explain that we are accessing elements in an array using loops and accessing displayobjects (like a sprite or mc) in a displayObjectContainer (stage or mc...) Is this correct?
Looks like getChildAt is NOT for arrays but for displayObjectContainers ie: You have put all the elements of an array into a container sprite or even the stage or a loader etc...
A simple array is not put anywhere yet ie: not contained it just exists. When you want to do something with it you do two things
1. Loop through the array and assign the element to a variable
2. Then you can put these elements into a new container sprite. You may think this a little strange but then you can do things to that ONE container (with all those ittle sprites inside.)
Imagine you wanted to move all those sprites to a certain area - it would be real easy with the container. Also if you wanted to do something to all the elements inside that container you would use getCHildAt and loop through. You couldn't use your typical loop through an array because you don't know which elements are left inside the container. Imagine you remoe a few. Also, how do you count how may are left.
Therefore a CONTAINER is a DisplayObjectContainer and is has useful methods.
ie: One thing is accessing elements in an array and another is accessingdisplay objects in a displayObjectContainer eg: sprites inside a contianer sprite.
North America
Europe, Middle East and Africa
Asia Pacific