stage.Resize
11-05-2007, 03:29 PM
I'm having an issue resolving the correct dimensions for the stage. Check out this code below:
var brick1:Sprite = new Sprite();
var brickHolder:Sprite = new Sprite();
stage.addChild(brickHolder);
brickHolder.addChild(brick1);
brickHolder.x =0;
brickHolder.y = 0;
brickHolder.graphics.beginFill(0x00ffff);
brickHolder.graphics.drawRect(brickHolder.x, brickHolder.y, stage.stageWidth, stage.stageHeight);
brickHolder.graphics.endFill();
brick1.x = brickHolder.width/2-10;
brick1.y = brickHolder.height/2-10;
brick1.graphics.beginFill(0x000000);
brick1.graphics.drawRect(brick1.x, brick1.y, 20, 20);
trace("This brick is at: "+brick1.x+" "+ brick1.y);
trace("Stage size: "+stage.stageWidth + " " +stage.stageHeight);
brick1.graphics.endFill();
Now, what I expected to happen was there would be a square in the center of the viewable area right? But instead the square appears in the bottom right corner. If I don't divide by 2, the square appears waaaaay off screen. What gives? :confused:
var brick1:Sprite = new Sprite();
var brickHolder:Sprite = new Sprite();
stage.addChild(brickHolder);
brickHolder.addChild(brick1);
brickHolder.x =0;
brickHolder.y = 0;
brickHolder.graphics.beginFill(0x00ffff);
brickHolder.graphics.drawRect(brickHolder.x, brickHolder.y, stage.stageWidth, stage.stageHeight);
brickHolder.graphics.endFill();
brick1.x = brickHolder.width/2-10;
brick1.y = brickHolder.height/2-10;
brick1.graphics.beginFill(0x000000);
brick1.graphics.drawRect(brick1.x, brick1.y, 20, 20);
trace("This brick is at: "+brick1.x+" "+ brick1.y);
trace("Stage size: "+stage.stageWidth + " " +stage.stageHeight);
brick1.graphics.endFill();
Now, what I expected to happen was there would be a square in the center of the viewable area right? But instead the square appears in the bottom right corner. If I don't divide by 2, the square appears waaaaay off screen. What gives? :confused: