divya
divya

Reputation: 81

how to set width and height for stage during resize event in as3

I want to set width and height of the stage during resize of that swf.. I do it in resize event handling..but doesn't work..any other way to achieve this?

 stage.addEventListener (Event.RESIZE, resizeListener);

 function resizeListener (e:Event):void {
  stage.stageWidth=500;
  stage.stageHeight=300;

 }

Thanks

Upvotes: 0

Views: 8765

Answers (3)

divya
divya

Reputation: 81

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

  }

This answer gives better understanding of previous code given by swati singh.See this link How to resize an external SWF to fit into a container? Thanks to all

Upvotes: 0

Swati Singh
Swati Singh

Reputation: 1863

Updated:

you need is to compare the ratios of the width and height scales of the content and the target. To make the loaded image fit within the area, scaling so that everything is inside you can do something like this:

    var scale:Number = Math.min( _holder.width / _loader.content.width,
                            _holder.height / _loader.content.height );
   _loader.content.scaleX = _loader.content.scaleY = scale;

This will make sure that you can see everything. If you change Math.min to Math.max, you will get a different result if the dimensions don't match.

Upvotes: 1

Daniel
Daniel

Reputation: 35724

by the sounds of it you just need

 stage.align     = "";
 stage.scaleMode = StageScaleMode.NO_SCALE;

this will keep the content the same size no matter how much you stretch the window

Upvotes: 2

Related Questions