Search code examples
flashactionscript-3resizescalemovieclip

Scale proportionally below movieclip size


I'm trying to make a movieclip scale proportionally only if the item is being resize smaller than the current.

Obviously I can use the ScaleX/Y values like so:

if (cont.scaleX < cont.scaleY ) { cont.scaleY = cont.scaleX; } else { cont.scaleX = cont.scaleY; }

I need to restrict/reset the scale proportions only in special case that the stageWidth/Height are smaller than the movieclip.

Can't do it for the life of me.

Thanks


Solution

  • Just from the top of my mind, but you may find an answer exploring something likely :

    EDIT : Added max scale of 1 in response to your first comment, should work ...

    var sw:Number = stage.stageWidth,
        sh:Number = stage.stageHeight;    
    
    if( sw/sh < c.width/c.height ) // (or the opposite depending on the way of scaling)
    {
       c.width = Math.min(origW,sw);
       c.scaleY = c.scaleX = Math.min(1, c.scaleX);
    } 
    else
    {
       c.height = Math.min(origH,sh);
       c.scaleX = c.scaleY = Math.min(1, c.scaleY);
    }