Jump to content
Search Community

centre AutoFitArea to stage?

1114rk test
Moderator Tag

Recommended Posts

i'm trying to centre the AutoFitArea object to stage that would update on Event.RESIZE but for some reason it goes off centre on resizing the window...

essentially like the LiquidStage functionality, although maybe that's why there is the LiquidStage because "it doesn't work straight out of box" ???

 

the code I'm using is as follows (with all the declarations and imports...)

 

autoFitArea.attach(attachedImage, ScaleMode.PROPORTIONAL_INSIDE, AlignMode.CENTER, AlignMode.CENTER);

stage.addEventListener(Event.RESIZE, onStageResize);

function onStageResize(e:Event):void 
{
autoFitArea.width = stage.stageWidth;
autoFitArea.height = stage.stageHeight;

autoFitArea.x = stage.stageWidth/2 - autoFitArea.width/2;
autoFitArea.y = stage.stageHeight/2 - autoFitArea.height/2;
}

any ideas are much appreciated

Link to comment
Share on other sites

essentially like the LiquidStage functionality, although maybe that's why there is the LiquidStage because "it doesn't work straight out of box" ???

Yep, exactly. There's a whole lot more that LiquidStage handles for you that makes stuff like this easy.

 

It looks like you're putting the x/y of the AutoFitArea in the center of the stage instead of the upper left corner.

 

Also, note that by default, Flash centers the stage inside the window which can cause an offset from the upper left corner unless you set the stageAlign to the top left corner. Also be mindful of how you've got Flash set up to handle scaling of the content when the window changes sizes.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...