I want to center a big movieclip (1400 px wide) on my stage on stage resize. This big movieclip moves to the right on certain events so I can't use code like this:
currentPage.x = ((stage.stageWidth/2) - (currentPage.width/2))
Is there a way to maybe use its offset from 0 (the left side of the stage 'viewport') and use that offset in centering?
The movieclip only changes in x.
When a object is resized, we can say its scale has changed. Scales are nice because they allow us to work in percentages. Given any percentage change, we can apply the same change to any other object to get a relative position. Look here:
var previousStageWidth:Number;
public function handleResize():void {
//calculate the difference in stage with as a percentage
var widthScale:Number = previousStageWidth / stage.stageWidth;
//scale the x value by the same amount
myDisplayObject.x *= widthScale;
//update the previous value for the next resize
previousStageWidth = stage.stageWidth;
}
Hopefully that works out for you.