I think I've figured out a better way of doing this:
- Set the
resizeMode
of the component toscale
- Add a listener for the
updateComplete
event, in the listener manipulate the$scaleX
and$scaleY
properties of themx_internal
namespace.
Example:
<s:Group id="myContainer" resizeMode="scale">
<!-- Some children, images etc... -->
<s:updateComplete>
<![CDATA[
import mx.core.mx_internal;
myContainer.mx_internal::$scaleX = Math.min(myContainer.mx_internal::$scaleX, myContainer.mx_internal::$scaleY);
myContainer.mx_internal::$scaleY = myContainer.mx_internal::$scaleX;
]]>
</s:updateComplete>
</s:Group>
This way is better becuase...
- It allows for not knowing the aspect ratio in advance.
- it also allows for complex layouts and many children where the ratio can change at runtime.
If used often a library function could be created instead.