Custom DisplayObjects & stupid getBounds

I’ve encountered a bit of a problem with the getBounds method when nesting custom display objects. What I’ve been trying to do is is overrite a Sprite’s width, height, getBounds and getRect methods to return the dimensions of a mask. This works fine when accessing these directly on the object.

For example, say my custom sprite contains a 200x200 circle with a 100x100 mask.



var myCustomSprite:CustomSprite = new CustomSprite();
addChild(myCustomSprite);
trace(myCustomSprite.getBounds(this));  // Outputs [0,0,100,100] as it should.


However, when I add this to an empty Sprite then run getBounds on this new Sprite the returned Rectangle is the literal size of of my custom object and not the size of the mask. Clearly getBounds is not derived by looking at the target children’s properties rather through some other internal way.



var myCustomSprite:CustomSprite = new CustomSprite();
// Create an empty sprite
var sprite:Sprite = new Sprite();
addChild(sprite);
// Add the custom sprite to it
sprite.addChild(myCustomSprite);
// Output the bounds of the containing sprite
trace(sprite.getBounds(this));  // Outputs [0,0,200,200]. 


I’m trying to build a custom scrollbar which uses getBounds on a container Sprite to determine how much to scroll the container by. Since getBounds is ignoring any overritten values defined in children of the container it’s throwing off the values needed to perfectly align the scroll area at the top of the scroll window.

Has anyone encountered this before and is there a solution?!?! Attached is a zip file with source showing the problem.

Any help would be great. Thanks.