Forcing size of a complex Flash object.

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2011-01-11T15:51:00Z Indexed on 2011/01/11 15:53 UTC
Read the original article Hit count: 161

Filed under:
|

As I've found recently, setting width/height properties on a Sprite only forces the Sprite to fit the given dimensions by scaling the actual size, which is calculated by Flash based on the rendered content.

This leaves me confused. If I have a custom Sprite subclass which draws using Graphics, how can I do layout before an initial render - the size will be zero until it is first drawn?

For a more complex issue, let's say I have a 2D game world with objects spread over a wide area with world coordinates from (0,0) to (5000,5000), where each object has a size of maybe up to 100x100. I want to have a Flash component which is the "game window", and has a fixed size like 400x300, rendering part of the game world. So how do I force the game window size to 400x300 pixels? I can draw a 400x300 rectangle to get the size correct but then if I draw any objects which are partly in-view, they can screw this up.

Is the right approach to provide a custom setSize(w,h) method which is used rather than width & height setters? But even so, is there no way to make a Sprite force to the size I want? Do you really have to catch it every render and re-scale it?

© Stack Overflow or respective owner

Related posts about flash

Related posts about actionscript-3