Avg. Rating 3.8

Problem

By default, the mx:Image component does not enable smoothing.

Solution

Extend the mx:Image component to handle smoothing automatically.

Detailed explanation

The goal is to provide an image component thats quick and easy to use, and takes care of turning the smoothing property on after the image has loaded. This is helpful if you have an image that you want to look the best it can at different sizes.

Usage:
<SmoothImage source="./art.jpg" width="100%" height="100%"/>


Source:

package {
    import mx.controls.Image;
    import flash.display.Loader;
    import flash.display.Bitmap;
    import flash.events.Event;
    import mx.core.mx_internal;
   
    use namespace mx_internal;
   
    /**
     * SmoothImage
     *
     * Automatically turns smoothing on after image has loaded
     *
     * @author Ben Longoria
     */
    public class SmoothImage extends Image {
       
        public function SmoothImage():void {
            super();
        }
       
        /**
         * @private
         */
        override mx_internal function contentLoaderInfo_completeEventHandler(event:Event):void {
            var smoothLoader:Loader = event.target.loader as Loader;
var smoothImage:Bitmap = smoothLoader.content as Bitmap;
            smoothImage.smoothing = true;
           
            super.contentLoaderInfo_completeEventHandler(event);
        }
    }
}
Report abuse

Related recipes