views:

49

answers:

2

I am aligning my display objects in the middle. stage.stageWidth/2. for some reason, they are aligning further off to the right of the screen.

I haven't altered anything but the stage width in flash. Has anyone heard of this problem? Again, I haven't done anything except widen the screen and adjust the height.

Here is the code I tried to put in to fix it and nothing happened.

My focus point on the display object is top left. so it aligns perfectly when set to 0,0

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.stageWidth = 300;
+2  A: 

If you are resizing the stage (or rather the window in which your SWF is embedded), then you will benefit from using StageAlign.TOP_LEFT, and disabling stage scaling (i.e. with StageScaleMode.NO_SCALE) like what you're doing. You should never set stageWidth though, it is updated when the user resizes the stage. I'm not sure of the behavior when doing this, so I would suggest removing line three from your snippet above, and see if that helps.

richardolsson
line 3 was a last minute attempt. it is not the reason why my objects appear farther to the right. I wonder, is it because of my focus point on my object being set to top left. I am tiling this object so it probably push it farther to the right wouldnt it ??
numerical25
+1  A: 

stage.stageWidth / 2 is the exact center of your stage, in terms of pixels from the left of the stage.

Say you have an object square that is 100x100 pixels, with its registration point in the top left (at (0,0) local to itself).

If you want square to be centered on the stage, you really want to put the middle of square at the center of the stage, not the left side of square.
So instead of square.x = stage.stageWidth / 2;
Use square.x = stage.stageWidth / 2 - square.width / 2;, which puts half of the square to the left of the center, leaving the other half to the right, making it perfectly centered.

Note that this technique only works with objects that have their registration point at their left boundary. If the registration point was in the exact middle of square to begin with, then square.x = stage.stageWidth / 2; would work fine.

Cameron
yea its starting to make sense to me now.
numerical25