1

我有一个尺寸为:500x400 的影片剪辑。实例名称为:“main”。我有以下代码:

import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener (Event.RESIZE, resizeHandler);

// initialize sizing
resizeHandler (null);

function resizeHandler (event:Event):void {
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;

  main.height = sh;
  main.width = sw;

}

如何将 MovieClip 的大小调整比例和最大尺寸保持为 500x400?

4

3 回答 3

0

这不是我的想法,所以不是 100% 它是正确的语法,但你应该明白:

import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;

var ratio:Number = Number(stage.stageWidth)/stage.stageWidth;//you need to check if stage isn't null and this ratio is valid

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener (Event.RESIZE, resizeHandler);


// initialize sizing
resizeHandler (null);

function resizeHandler (event:Event):void {
var sw:Number = stage.stageWidth;
var sh:Number = stage.stageHeight;
  //make with width same as stage
  main.width = sw;
  main.height = sh/ratio;//keep height proprtional
  //or you can try the other way around if you want - make main.height = sh and main.width =  sh * ratio;

}
于 2012-07-11T00:23:58.340 回答
0

这段代码应该可以完成这项工作:

if (stage.stageWidth/500 < stage.stageHeight/400)
{
    main.scaleX = stage.stageWidth/500;
    main.scaleY = main.scaleX;
}else{
    main.scaleX = stage.stageHeight/400;
    main.scaleY = main.scaleX;
}
于 2012-07-10T23:59:09.680 回答
0

无论影片剪辑的比例如何,以下代码都可以解决问题。如果您希望强制执行 500 x 400 的比例,您可以将 movieClipRatio 指定为 500 / 400。

import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
stage.addEventListener (Event.RESIZE, resizeHandler);
var movieClipRatio:Number = main.width / main.height;

// initialize sizing
resizeHandler (null);

function resizeHandler (event:Event):void {
    var sw:Number = stage.stageWidth;
    var sh:Number = stage.stageHeight;

    if ( sw == 0 || sh == 0 ) {
        return; // special case to avoid
    }

    var stageRatio:Number = sw / sh;

    if ( stageRatio > movieClipRatio )  {
        // stage is proportionally wider than movieClip
        // resize by height
        main.width *= sh / main.height;
        main.height = sh;
    } else {
        // stage is proportionally taller than movieClip
        // resize by width
        main.height *= sw / main.width;
        main.width = sw;
    }

}
于 2012-07-11T02:19:58.190 回答