I bet this just adds to the confusion... but who doesn't love a one-liner?
// 1. MATH - ONE LINE
var w = 800;
var h = 600;
var n = 1024;
w = ((h *= n/w) && n);
// 2. MATH - TWO LINES (same as above)
var w = 800;
var h = 600;
var n = 1024;
h *= n/w; // adjust h based on w
w = n; // set w
// 3. SIMPLE MC
mc._width = 200;
mc._yscale = mc._xscale;
// 4. BOUNDS
// stage listener
sl = {}
Stage.addListener( sl );
sl.onResize = onStageResize;
onStageResize ();
// on resize
function onStageResize ()
{
var newScale = ratioScaling ( photo_mc, Stage.width, Stage.height,
640, 480, 1024, 768, true );
trace( 'newScale: ' + newScale );
}
// resize function
function ratioScaling ( mc:MovieClip, W:Number, H:Number, minW:Number,
minH:Number, maxW:Number, maxH:Number, useMax:Boolean ) : Number
{
// set within bounds
mc._width = Math.max ( Math.min( maxW, W ), minW );
mc._height = Math.max ( Math.min( maxH, H ), minH );
// set and return the smallest ratio,
// unless useMax is true, then choose largest ratio.
return mc._xscale = mc._yscale = Math[(useMax)?'max':'min'](
mc._xscale, mc._yscale );
}
_____________________________
Jesse Graupmann
www.jessegraupmann.com
www.justgooddesign.com/blog/
_____________________________
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com