如何在 AS3 中调整大小事件期间设置舞台的宽度和高度



我想在调整该 swf 的大小时设置舞台的宽度和高度。我在调整大小事件处理中这样做。但不起作用..还有其他方法可以实现这一目标吗?

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

谢谢

通过它的声音你只需要

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

无论您拉伸窗口多少,这都将保持内容相同的大小

Updated:

您需要的是比较内容和目标的宽度和高度比例的比率。为了使加载的图像适合该区域,缩放以使所有内容都在内部,您可以执行以下操作:

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

这将确保您可以看到所有内容。如果将 Math.min 更改为 Math.max,则在维度不匹配时将获得不同的结果。

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

这个答案可以更好地理解斯瓦蒂·辛格给出的先前代码。查看此链接如何调整外部 SWF 的大小以适应容器?感谢大家

最新更新