2010-08-14 20 views
2

我想要完成的是調整外部SWF的大小,使其適合顯示爲舞臺上的容器的顯示對象。現在它顯示在容器外面。如何調整外部SWF以適應容器?

重要提示:我不希望外部SWF佔據整個舞臺;我在舞臺上有一個特殊的地方(那個容器)。

回答

2
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/ 他們有一個偉大的設置加載類的,你可以指定要加載內容的寬度&高度,設置一個容器將其加載到與甚至指定你想要的內容如何適合,節省你所有的代碼以上;)

相關問題