I suspect that
It would be safer programming to use:
for(var i:int = 0; i< arr.length; i++)
Run the code using the debugger and check to see what's going on with the array, or throw in a few trace statements.
..and arr.length == childsCount?
With the debugger, you should be able to see exactly where the error is and see why by inspecting the elements involved. I am only guessing.
I can see you're following this:
currentElement is null so "
targetContainer.getElementAt(i);" seems to be returning null.
..which seems to contradict "
childsCount:int = targetContainer.numElements;"
Hmm.. ..scratches head..
The loop should probably run until targetContainer.numElements-1, as the starting index is indeed zero...