PDA

View Full Version : centering an mc



kritikal
October 18th, 2005, 04:52 PM
hey guys,

here's the deal, I have a main swf named index.swf with only 1 frame, on that frame I have actionscript that creates an empty movieclip loads an external swf and centers it depending on the user's browser size.

My problem is if I load an swf that doesn't take the whole 1020x610 of the index.swf it won't be centered. It's kind of hard to explain. so here's some of the code.



this.createEmptyMovieClip("container",this.getNextHighestDepth());

container.loadMovie("../swf/splash.swf");

var stageXCenter:Number = Stage.width * .5;
var stageYCenter:Number = Stage.height * .5;

stageXCenter = stageXCenter - (container._width * .5);
stageYCenter = stageYCenter - (container._height * .5);

container._x = stageXCenter;
container._y = stageYCenter;

stageListener = new Object();

stageListener.onResize = function():Void {
stageXCenter = Stage.width * .5;
stageYCenter = Stage.height * .5;

stageXCenter = stageXCenter - (container._width * .5);
stageYCenter = stageYCenter - (container._height * .5);

container._x = stageXCenter;
container._y = stageYCenter;
}

Stage.addListener(stageListener);


Any help would be greatly appreciated

Lindquist
October 18th, 2005, 05:02 PM
The registration point for a loaded movieClip will always be in the upper left hand corner, so you're going to have to compensate for that with your AS.

psykovsky
October 18th, 2005, 05:34 PM
Stage.align="CC"

kritikal
October 18th, 2005, 05:59 PM
The registration point for a loaded movieClip will always be in the upper left hand corner, so you're going to have to compensate for that with your AS.

I did by doing


stageXCenter = stageXCenter - (container._width * .5);
stageYCenter = stageYCenter - (container._height * .5);


I forgot to mention that it's perfectly centered after I resize the window...


Stage.align="CC"

that actually makes it worse, Stage.align="TL" works better

Lindquist
October 18th, 2005, 06:23 PM
Try replacing this


stageListener.onResize = function():Void{

stageXCenter = Stage.width * .5;
stageYCenter = Stage.height * .5;

stageXCenter = stageXCenter - (container._width * .5);
stageYCenter = stageYCenter - (container._height * .5);

container._x = stageXCenter;
container._y = stageYCenter;
}


with this:



function manageStage():Void {
stageXCenter = Stage.width * .5;
stageYCenter = Stage.height * .5;

stageXCenter = stageXCenter - (container._width * .5);
stageYCenter = stageYCenter - (container._height * .5);

container._x = stageXCenter;
container._y = stageYCenter;
}
stageListener.onResize = manageStage;

manageStage();

So that it calls the function when it first loads (I actually remember having that problem before).

kritikal
October 18th, 2005, 06:37 PM
hmm I see where you're going with that and it should work but for some reason that I don't understand it's not working... :(

instead of being completly centered it's a bit off

It doesn't seem to be calculating the offset

Lindquist
October 18th, 2005, 06:41 PM
interesting, do you think you could post your .fla? I'll pm you my e-mail addy if you don't want to post it here.

kritikal
October 18th, 2005, 06:43 PM
interesting, do you think you could post your .fla? I'll pm you my e-mail addy if you don't want to post it here.

sure, send me your email