View Full Version : Center SWF
Rundevo
April 1st, 2008, 11:12 AM
Hi all!
I wonder how you can center an externally loaded swf regardless of its height or width?
Currently I have a main swf which I load other swfs into, and I need those swfs to be centered on the main swf.
Any help in this matter would be greatly appreciated
regards
/rundevo
Rundevo
April 1st, 2008, 11:34 AM
Forgot the code :)
function onClick02(event:Event):void
{
var _loader02:Loader = new Loader();
_loader02.load(new URLRequest("swfs/swf" + _random2 + ".swf"));
stage.addChild(_loader02);
_loader02.x = stage.stageHeight / 2;
_loader02.y = stage.stageWidth / 2;
I thought it was as easy as that, just using stage.stageWidth / 2; that is, but apparently not.
Thanks.
omine
April 1st, 2008, 01:44 PM
In first place you'll have to:
- promote _loader02 to a class member;
- listen to the loader's Event.COMPLETE:
_loader02.addEventListener(Event.COMPLETE, onLoaderComplete);
The listener method should look like this:
protected function onLoaderComplete(event:Event):void
{
_loader02.x = (stage.stageWidth - _loader02.width) * 0.5;
_loader02.y = (stage.stageHeight - _loader02.height) * 0.5;
}
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.