Skip to main content
Participating Frequently
August 16, 2009
Question

Scaling and centering objects.

  • August 16, 2009
  • 1 reply
  • 1299 views

Hi,

I have a center window and a background in my flash file. I am trying to get the center window to stay in the center of the web browser screen and get the background to expand and fill the entire web browser screen below center window layer. Sort of like this site http://smlsd.com.

I've currently converted the background to a movie clip and have this code.

background_mc.width = stage.stageWidth;

background_mc.height = stage.stageWidth;

However, the background is not resizing to fill the screen,

In publishing settings, I have dimensions to "Match Movie", Window mode in "Window", HTML alignment "Default", Scale set to "No Scale" (I don't want the center window to scale and loose proportion. It should have a set size.), and Flash alignment set to both "Center" and "Center".

I do not know how to get the center window in the center of the screen and have the background automatically resize to fill the whole screen. Can somebody show me some code which would solve this problem and explain it to me? Thanks.

This topic has been closed for replies.

1 reply

AttaBoy2
Inspiring
August 16, 2009

this works:

you can view it here http://cybermountainwebservices.com/fullBrowser/FullBrowserAS3.html

stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

var bmp:Tile = new Tile(35, 35);
var tile:BitmapData = new BitmapData(35, 35);
tile.draw(bmp);

shelter.x = stage.stageWidth /2;
shelter.y = stage.stageHeight /2;

function fillBG(evt:Event = null):void {
  graphics.beginBitmapFill(tile);
  graphics.moveTo(0, 0);
  graphics.lineTo(stage.stageWidth, 0);
  graphics.lineTo(stage.stageWidth, stage.stageHeight);
  graphics.lineTo(0, stage.stageHeight);
  graphics.lineTo(0, 0);
  graphics.endFill();
shelter.x = stage.stageWidth /2;
shelter.y = stage.stageHeight /2;
};
fillBG();

stage.addEventListener(Event.RESIZE, fillBG);

in  this case the fill is with a 35pxl x 35pxl gif file but you could just as easily use a color the item called shelter is the name of the jpg in the center.

when you do this be sure in your publish settings to set dimension to percent 100 x 100  if you cont want a border or scrollbars around the outside be sure to set this css rule in your html   body {margin:0; padding:0; overflow:auto}

ansonlAuthor
Participating Frequently
August 16, 2009

If I have many components and objects in my center window (buttons, bars, images) and most of them are in one layer, is there a way to position everything in one layer in the center? Or do I have to manually position everything? If I have to manually position everything, is there a layout to automatically position everything in a few lines of code?

Also, my background is an image, would I use the same code from above, or do I have to convert it to a symbol?

Thanks!

AttaBoy2
Inspiring
August 17, 2009

What about my first question?


sorry you did ask where to put the code.  If you haven't already done so create a layre above the others, name it actions.  put all code on frame 1 of that layer.  lock it and never unlock it it won't affect your ability to write code it will just keep you from putting other stuff on the layer.