ActionScript 3 比例和约束

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 比例和约束相关的知识,希望对你有一定的参考价值。

var clipConteneur_mc:MovieClip = new MovieClip();
var chargeImage:Loader = new Loader();


clipConteneur_mc.graphics.beginFill(0x000000,1);
clipConteneur_mc.graphics.drawRect(0, 0, 200, 150);
clipConteneur_mc.graphics.endFill();
addChild(clipConteneur_mc);

clipConteneur_mc.x = 20;
clipConteneur_mc.y = 20;


chargeImage.contentLoaderInfo.addEventListener(Event.COMPLETE, onChargeImageComplete);
chargeImage.load(new URLRequest("images/image.jpg"));

function onChargeImageComplete(evt:Event):void
{
	var contenuRatio:Number = clipConteneur_mc.width / clipConteneur_mc.height;
	var imgRatio:Number = evt.currentTarget.content.width / evt.currentTarget.content.height;
	
	var img:Bitmap = Bitmap(chargeImage.content);
	img.smoothing = true;

	if (imgRatio > contenuRatio)
	{
		img.width = clipConteneur_mc.width*0.95;
		img.height = (clipConteneur_mc.width/imgRatio)*0.95;
	}
	else if (imgRatio<=contenuRatio)
	{
		img.height = clipConteneur_mc.height*0.95;
		img.width = (clipConteneur_mc.height*imgRatio)*0.95;
	}
	
	clipConteneur_mc.addChild(img);
	
	img.x = clipConteneur_mc.width/2 - img.width/2;
	img.y = clipConteneur_mc.height/2 - img.height/2;
}

以上是关于ActionScript 3 比例和约束的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 按比例缩放

ActionScript 3 全屏图像调整大小(按比例)

ActionScript 3 AS3按比例调整大小

如何将间距约束指定为超级视图大小的比例?

自动布局中的比例距离约束

自动布局和设备旋转中到顶部的比例距离