This should be simple. What am I missing? Create a Sprite (container), put it on the displaylist, add a new Sprite (rect) to container. Change height of the child (rect). Height values of both parent (container) and child (rect) are not reported correctly although rendered correctly. Thanks for your assistance.
var container:Sprite = new Sprite();
addChild(container);
[Embed(source = "../lib/rectangle.swf")] // height is 100
var Rect:Class;
var rect:Sprite = new Rect();
trace(rect.height); // 100 is correct before placement in container
container.addChild(rect);
trace(rect.height); // 100 is correct after placement in container
trace(container.height); // 0 is not correct; should be 100
rect.height = rect.height + 100; // renders correctly at new height
trace(rect.height); // 100 is not correct; should be 200
trace(container.height); // 0 is not correct; should be 200
Apparently your
container
is not on the stage display list. If a measuredDisplayObject
is not on the display list (anywhere), its dimensional properties are not properly recalculated, when its own display list is altered. This is apparently to save time for Flash engine to process building of a complexMovieClip
frame or any other complex container faster, and recalculation is only done if the container is placed to stage. The resolution is to place the object to be measured to stage (anywhere, anyhow), gather its properties then remove it from stage. An example:There is also another possibility,
width
of an object off stage can be in the negative, the solution is again the same - put object on stage, get width, remove object from stage.