My scaleToFit function. Probably not the most awesome thing, but it does the job

private function scaleToFit(target:Object,clipRect:Rectangle,maintainAspect:Boolean){
       var w:Number = clipRect.width;
       var h:Number = clipRect.height;
       var ratio:Number;
       var scalew:Number;
       var scaleh:Number;
       if(target._width>w||target._height>h){
           if(maintainAspect){
               //height
               ratio = target._width/target._height;
               scalew = w;
               scaleh = scalew/ratio;
               if(scaleh>h){
                   //width
                   ratio = target._height/target._width;
                   scaleh = h;
                   scalew = scaleh/ratio;
               }
           }else{
               scalew = w;
               scaleh = h;
           }
           target._width = scalew;
           target._height = scaleh;
       }
   }

eric e. dolecki wrote:
Ok that is SO weird. I was just thinking about this...

myListener.onLoadInit = function( target_mc:MovieClip ):Void
{
   target_mc._xscale = target_mc._yscale = Math.max( target_mc._width,
target_mc._height );
};

- Eric


On 3/26/07, Adrian Lynch <[EMAIL PROTECTED]> wrote:

Any examples out there?

I've got as far as resizing a user supplied image and am about to work on
the ratio remaining fixed. Just thought I'd throw this out there as I
think
it may be tricky.

Ta.

Adrian

_______________________________________________
Flashcoders@chattyfig.figleaf.com
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





_______________________________________________
Flashcoders@chattyfig.figleaf.com
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

Reply via email to