This is sort of what I was talking about where the parent would handle the layout of its children. Note that this assumes that the width of the parent container is already known at the start of update()
, which I assume is safe based on your description. However, if the parent container might ever need to measure itself, this logic would need to be a bit more complicated.
override private function update():Void {
if (explicitWidth < 600) {
child.scaleX = child.scaleY = 0.5; // or some calculation
child.layoutData = null;
}
else if (child.layoutData == null) { // if we already created AnchorLayoutData, no need to do it again
child.scaleX = child.scaleY = 1.0; // just to be safe
child.layoutData = new AnchorLayoutData( /* args */ );
}
super.update();
}
This assumes that the update()
method may be called multiple times, so it tries to avoid creating too much garbage to be collected, and handles the possibility that the container might resize.