Making Flex scale when resized
May 2nd, 2011
No comments
When applications made in Adobe Flash are resized, the default behavior is to scale the entire application. With Flex however, the default behavior is to resize the dimensions of the application container, without resizing any components. This is useful if you have designed a layout with relative positioning and sizing. But if you want your application to actually increase the size of each component, you will need to make a minor adjustment.
Add an event handler to the main application for addedToStage:
1 2 | <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" addedToStage="stretchHandler()"> |
And here’s the code for stretchHandler():
1 2 3 4 5 6 | private function stretchHandler():void{ stage.scaleMode = StageScaleMode.SHOW_ALL; stage.align = StageAlign.TOP; this.width = stage.stageWidth; this.height = stage.stageHeight; } |
The SWF on the left is the flex application at its normal dimensions (160×80). The SWF on the right is the exact same SWF file, but I embedded it using double dimensions (320×160).