Rectangle 27 0

flash How to resize an external SWF to fit into a container?


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 );
  }

You could also check greensock.com , http://www.greensock.com/ they have a great set of Loading classes where you can specify the width & height of the content you want to load , set a container to load it into and even specify how you'd like the content to fit, saves you all the code above ;)

Note