2
我想要完成的是调整外部SWF的大小,使其适合显示为舞台上的容器的显示对象。现在它显示在容器外面。如何调整外部SWF以适应容器?
重要提示:我不希望外部SWF占据整个舞台;我在舞台上有一个特殊的地方(那个容器)。
我想要完成的是调整外部SWF的大小,使其适合显示为舞台上的容器的显示对象。现在它显示在容器外面。如何调整外部SWF以适应容器?
重要提示:我不希望外部SWF占据整个舞台;我在舞台上有一个特殊的地方(那个容器)。
public function loaderComplete(event:Event):void
{
var content:MovieClip = MovieClip(event.currentTarget.content);
//the dimensions of the external SWF
var _width:int = content.width;
var _height:int = content.height;
// you have several options here , assuming you have a container Sprite
// you can directly set to the dimensions of your container, if any
if(container.width < _width)
_width = container.width // and do the same for height
// or you could scale your content to fit , here's a simple version
// but you can check the height too or keep checking both value
// until it fits
if(container.width < _width)
{
var scale:Number = container.width/_width;
content.scaleX = content.scaleY = scale;
}
// when all done, you can add your content
container.addChild(content);
}
你也可以查看greensock.com, http://www.greensock.com/ 他们有一个伟大的设置加载类的,你可以指定要加载内容的宽度&高度,设置一个容器将其加载到与甚至指定你想要的内容如何适合,节省你所有的代码以上;)