Skip to main content
Known Participant
February 24, 2013
Question

how to set the height and width of loaded swf

hi

am loading swf into fla project

fla is 800 X 400

and the loaded swf is bigger than that

so how i can set the loaded swf in any size i wont and align

to the center of the right of the scene???

This topic is closed to new replies. Start a new post to keep the conversation going.

26 replies

Inspiring
February 24, 2013

If you want to scale loaded SWF proportionately and assuming your loader name loader here how you can do that:

addChild(loader.content);

if(width / height >= loader.content.width / loader.content.height) {

          loader.content.width = width;

          loader.content.scaleY = loader.content.scaleX;

          loader.content.y = (height - loader.content.height) * .5;

}

else {

          loader.content.height = height;

          loader.content.scaleX = loader.content.scaleX;

          loader.content.x = (width - loader.content.width) * .5;

}

Translate
Known Participant
February 24, 2013

i got that error

TypeError: Error #2007: Parameter child must be non-null.

          at flash.display::DisplayObjectContainer/addChild()

          at Untitled_fla::MainTimeline/frame1()[Untitled_fla.MainTimeline::frame1:10]

and the loader name is

patloader

here is my code

var patloader:Loader=new Loader();

patloader.load(new URLRequest("patgame.swf"))

addChild(patloader.content);

if(width / height >= patloader.content.width / patloader.content.height) {

          patloader.content.width = width;

          patloader.content.scaleY = patloader.content.scaleX;

          patloader.content.y = (height - patloader.content.height) * .5;

}

else {

         patloader.content.height = height;

          patloader.content.scaleX = patloader.content.scaleX;

          patloader.content.x = (width - patloader.content.width) * .5;

}

Translate
Inspiring
February 24, 2013

You have to wait until content is loaded and use this code only after that.

To wait - you need to add event listener to loaderInfo.

Here is Loader documentation that has examples:

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Loader.html

Translate