PDA

View Full Version : MovieClip to Scale or Not to Scale??



psilos
03-22-2007, 03:51 PM
I want to embed a swf in a html with lets say resolution 800x600.
What would be nice is to have inside flash file a movieClip as background that can have any resolution and in the middle of that another movie clip that remain in the same resolution no matter what resolution has the browser. Is that possible?

Medyman
03-22-2007, 05:25 PM
Yes, that's very possible.

There are two options for this.

(1) To use a perpetually tiled background by using a piece of code such as this (uses BitmapData class)


import flash.display.BitmapData;

centerimg._x = Stage.width/2;
centerimg._y = Stage.height/2;

var tile:BitmapData = BitmapData.loadBitmap("tile")

function fillBG() {
this.beginBitmapFill(tile);
this.moveTo(0,0);
this.lineTo(Stage.width,0);
this.lineTo(Stage.width,Stage.height);
this.lineTo(0,Stage.height);
this.lineTo(0,0);
this.endFill();
}

fillBG();

var stageL:Object = new Object();
stageL.onResize = function() {
fillBG();
centerimg._x = Stage.width / 2;
centerimg._y = Stage.height / 2;
}

This will apply a tiled background that doesn't stretch but rather keeps refilling the screen and also centers the content (called centerimg in this example) and doesn't scale it.

for this to work properly, put your background clip into the library and give it a linkage identifier of "tile" (or whatever else you choose, just make sure to update the AS)


(2) If you want a solid color as your background, or a scaleable movieclip use fluid dynamics with a code like this.


Stage.align = "TL";
Stage.scaleMode = "noScale";

background_mc._x = 0
background_mc._y = 0
background_mc._width = Stage.width
background_mc._height = Stage.height

content_mc._x = Stage.width/2
content_mc._y = Stage.height/2

sizeListener = new Object();
sizeListener.onResize = function() {
background_mc._x = 0
background_mc._y = 0
background_mc._width = Stage.width
background_mc._height = Stage.height

content_mc._x = Stage.width/2
content_mc._y = Stage.height/2
};

Stage.addListener(sizeListener);


This is will your content in the center if the user resizes the screen also.

If you have already created your flash movie and it will be too tedious to change all the AS to reflect this path change:


create a new .fla
use the above AS
create a moveclip (instance name content_mc) and use loadMovie(); to import your existing .swf