I'm using the setChildIndex method of Container to reorder some display objects, but it seems to be causing problems in other functions as soon as it's been used. I've stepped through my code, and have made sure I'm passing valid objects (which are definitely contained by the Container) and a valid index.
Here are the stack traces I got, once the setChildIndex function was called:
Container.js:116Uncaught TypeError: Object 0 has no method 'isVisible'
p.draw - Container.js:116
p.draw - Container.js:134
It continues throwing errors until I refresh the page. Some of the errors are found at (again in Container):
Is this a known issue? I've spent quite some time looking into it, and I can't see anything wrong with how I'm using the function.
I just pushed a fix that I think should fix this. Please test, and let me know if this resolves the problem (I'll try to test properly tomorrow if I don't hear back from you).
Awesome, thanks a lot for taking a look.
I got the latest source and tested the setChildIndex function again; it doesn't throw any errors now, but it doesn't rearrange the passed display object in the way I expected. This function is supposed to do the same thing as equivalent AS3 function I assume?
I used it like this:
I also tried with some other values to see if anything changed, but it never seems to reposition the child object to a different depth level.
I stepped through the function itself at runtime too, nothing breaks or fails. But I wondered: all the function seems to be doing is rearranging the position of the passed display object in an Array; this wouldn't naturally change the depth of the display object would it?
Ah, so I see now what I said about it being an Array is nothing to do with the problem. I tried removing the Display Object using removeChild, then adding it again except using addChildAt and specifying the index; this works.
And inside that function it's also splicing an Array, so clearly I just misunderstood something.
Also, in my previous post I was doing numChildren - 1, but in fact to do a put-to-back I needed to pass zero. Anyway yeah, setChildIndex still isn't working correctly, but I couldn't guess why after looking at the source.
Ok. I'll put together a quick test (hopefully today), and make sure this is fixed.
Ok. I just pushed what should be a full fix for this (tested this time). Let me know if this resolves it for you. Sorry for the previous mis-fires, not sure why this method out of all of them has been such a problem to get right. :)
Hey again; it works! Tested it a few times with different values, seems to work perfectly. Thanks a lot for your help! :D
I am still getting this issue with:
Yes. This is fixed in the NEXT version in the repo, not in the tagged 0.4.2 build. It will be part of a 0.4.3 or 0.5.0 tagged build in the not too distant future.