views:

401

answers:

1

Hi there,

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

+1  A: 

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);
}
Theo.T
Thanks for the resposne Theo. It kind of works, whenever I increase the stage larger than the movieclip it still scales :-( what I was hoping for was for it to just remain the natural size (300x250).
David
That's an easy one though, just edited the answer. Hope it helps !
Theo.T
Fantastic, thanks for that. I assumed it would be something like that I just couldn't nail it down.One last quicky...my MC has a mask on it that's outside the bounds of the space I want to display. Is there a way to calculate the height of JUST the element? I have workarounds for this but I'm wondering how the pros do it.
David