Return to Snippet

Revision: 28162
at July 2, 2010 17:41 by ions


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

Initial URL

                                

Initial Description
Permet d'ajuster la taille d'une image ou swf en fonction de son ratio et de celui de son conteneur.

Initial Title
Ratio et ajustement de contenu

Initial Tags
actionscript, flash

Initial Language
ActionScript 3