Flex containers are different from normal Flash DisplayObjectContainer. They hide some of their children when you try to access by a children counting method- container.numChildren. By default when no children is attached to the containers, they show numChildren value as 0, but they do contain chidren, which are known as”chrome” elements or “non-content” children. Let’s evaluate the below code to verify it.( This code is set up by adding a new As container has no child attached to it, numChildren property traces 0, where as getObjectUnderPoint(new Point(mouseX, mouseY)); returns a single element array. The reason comes from the implementation of the child management in flex framework- Flex maintains it’s children in two different partition (content children and non-content children). Index for all the children is contiguous but content children start after the non-content children. Container maintains two state variables, _firstChildIndex and _numChildren, which keep track of the partitioning. Components that extends Container may have more non-content elements depending upon the complexity.
Flex Child Management
public function init():void{
this.addEventListener(MouseEvent.MOUSE_UP,checkOut);
}
public function checkOut(evt:MouseEvent):void{
trace(container.numChildren);//returns 0
var arrNodes:Array=container.getObjectsUnderPoint(new Point(mouseX, mouseY));
if(arrNodes.length){
trace(arrNodes[0] ); //testApp.container.border
trace(container.getChildIndex(arrNodes[0]));// -1
}
}
