Hello,

I have written an mc to load an external image and to
fit it into an 80 x 60 container and it works fine the 1st
time I call my load_avatar() method. On the repeated
load_avatar() calls however the image gets distorted.

Does anybody have an idea how to fix this?

I've reduced my code to a simple test case,
which you can see at http://preferans.de/user/ and
I'll paste the AS-code at the bottom of this mail too.

I do see that the problem is that after the scaling
the target_mc._width and _height change:

    --- this in resize_clip() ---
    loader_mcl: [object Object]
    box_ratio: 1.33333333333333
    box_height: 60
    box_width: 80
    avatar_mc: _level0.user_mc.avatar_mc
    target_mc: 320 x 240

    --- this in resize_clip() ---
    loader_mcl: [object Object]
    box_ratio: 1.33333333333333
    box_height: 60
    box_width: 80
    avatar_mc: _level0.user_mc.avatar_mc
    target_mc: 71.85 x 58.75

    --- this in resize_clip() ---
    loader_mcl: [object Object]
    box_ratio: 1.33333333333333
    box_height: 60
    box_width: 80
    avatar_mc: _level0.user_mc.avatar_mc
    target_mc: 362.25 x 296.35

    ....

but how could I workaround this please?

Regards
Alex

--
http://preferans.de

------- Here is my User.as ----------

import mx.utils.Delegate;

class User extends MovieClip {
        private var avatar_mc:MovieClip;
        private var loader_mcl:MovieClipLoader;
        
        private var box_width:Number;
        private var box_height:Number;
        private var box_ratio:Number;
                        
        public function User() {
                box_width = 80;                         //avatar_mc._width;
                box_height = 60;                        //avatar_mc._height;
                box_ratio = box_width / box_height;

                var listener:Object = new Object();
                listener.onLoadInit = Delegate.create(this, resize_clip);
                
                loader_mcl = new MovieClipLoader();
                loader_mcl.addListener(listener);
                //load_avatar('Avatar.jpg');
        }
        
        public function load_avatar(image:String):Void {
                loader_mcl.loadClip(image, avatar_mc);
        }
        
        private function resize_clip(target_mc:MovieClip):Void {
                trace(newline + '--- this in resize_clip() ---');
                for (var key:String in this)
                        trace(key + ': ' + this[key]);
                trace('target_mc: ' + target_mc._width + ' x ' + 
target_mc._height);
                        
                // draw a white box around the image
                with(target_mc) {
                        lineStyle(1, 0xFFFFFF);
                        moveTo(-1, -1);
                        lineTo(_width, -1);
                        lineTo(_width, _height);
                        lineTo(-1, _height);
                        lineTo(-1, -1);
                        _rotation = 10;
                }

                // scale the loaded image to fit into box_width x box_height
                var clip_ratio:Number = target_mc._width / target_mc._height;
                if (clip_ratio > box_ratio)
                        target_mc._xscale = target_mc._yscale =
                           100 * box_width / target_mc._width;
                else
                        target_mc._xscale = target_mc._yscale =
                           100 * box_height / target_mc._height;
        };
}
_______________________________________________
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