All pastes #370695 Raw Edit

michiel

public text v1 · immutable
#370695 ·published 2007-02-24 20:21 UTC
rendered paste body
MovieClip.prototype.fitToArea = function(width:Number, height:Number, type:String) : Object
{
	// Returns the correct width and height values outside of a given size.
	
	if	(type == "outside" || type == undefined)
	{
		if	((width / height) > (this._width / this._height))
		{
			var new_width:Number = this._width / (this._width / width);
			var new_height:Number = this._height / (this._width / width);
		}
		
		else
		{
			var new_width:Number = this._width / (this._height / height);
			var new_height:Number = this._height / (this._height / height);
		}
	}
	
	if	(type == "inside")
	{
		if	((width / height) < (this._width / this._height))
		{
			var new_width:Number = this._width / (this._width / width);
			var new_height:Number = this._height / (this._width / width);
		}
		
		else
		{
			var new_width:Number = this._width / (this._height / height);
			var new_height:Number = this._height / (this._height / height);
		}
	}
	
	return {width: new_width, height: new_height};
};