PDA

View Full Version : [AS3]External SWF scaling to objects outside of stage



pcehnaids
December 24th, 2009, 03:05 PM
I have an swf in which objects go outside the boundaries of the stage (but are properly masked). Whenever I externally load this swf into a container it scales down to fit in the objects located off stage. EX:

http://img37.imageshack.us/img37/7711/example1u.jpg (http://img37.imageshack.us/i/example1u.jpg/)http://img704.imageshack.us/img704/8982/example2s.jpg (http://img704.imageshack.us/i/example2s.jpg/)

I have tried removing the objects outside the boundaries and the stage does not shrink the image. The container is the same dimensions as the external swf.

Here is my code for main stage; the external swf code does not adjust the scale, but if you need to see it, I will post. Any help will be extremely appreciated.


function open_puzzle(openSWF:String)
{
//Load SWF
container = new MovieClip();
addChild(container);

var url:URLRequest = new URLRequest(openSWF);
var loader:Loader = new Loader();
loader.load(url);

loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, completeHandler);

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

}

function completeHandler(event:Event):void
{
container.addChild(event.target.content);

container.height = stage.stageHeight - 20;
container.width = (stage.stageHeight - 20) * 1.333;
container.x = stage.stageWidth / 2 - container.width / 2;
container.y = stage.stageHeight / 2 - container.height / 2;

stage.addEventListener(Event.RESIZE, resizeHandler);
//container.addEventListener(MouseEvent.CLICK, exitSWF);
}

//Adjust SWF if stage is resized
function resizeHandler(event:Event):void
{
container.height = stage.stageHeight - 20;
container.width = (stage.stageHeight - 20) * 1.33;
container.x = stage.stageWidth / 2 - container.width / 2;
container.y = stage.stageHeight / 2 - container.height / 2;
}

Scythe
December 26th, 2009, 06:46 PM
It is usually bad practice to set an object's width or height. Use scaleX and scaleY instead. Sometimes a bit of math will have to be used to find what the exact values you want to change to are, but not much. In general,
mc.height = newHeight; should be changed to something like
mc.scaleY *= newHeight / mc.height;

But your code should be written in such a way so that it's actually easier to use scaleX and scaleY and so conversions are rarely necessary.

That won't fix your problem, though. Invisible content still contributes to the size of its container. There are many solutions available to you depending on what values are known, so I don't know enough about your project to know what to suggest. Assuming you know what the loaded SWF's dimensions are ahead of time, you could do something like this:


container.scaleX = container.scaleY = (stage.stageHeight - 20) / swfHeight;