         var fillScaleY:Number = 1;
         var roundedDrawX:Number = Math.round(drawX);
         var roundedDrawY:Number = Math.round(drawY);
-        var fillWidth:Number = unscaledWidth;
-        var fillHeight:Number = unscaledHeight;
-    
+        var fillWidth:Number = adjustedWidth;
+        var fillHeight:Number = adjustedHeight;
+        
         switch(_fillMode)
         {
             case BitmapFillMode.REPEAT: 

     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    override protected function updateDisplayList(unscaledWidth:Number, 
                                                  unscaledHeight:Number):void
    {
        if (!_bitmapData || !drawnDisplayObject || !(drawnDisplayObject is Sprite))
            return;
            
        // The base GraphicElement class has cleared the graphics for us.    
        var g:Graphics = Sprite(drawnDisplayObject).graphics;
        

                    g.beginBitmapFill(_bitmapData, matrix);
                    g.drawRect(destSection.x + roundedDrawX, destSection.y + roundedDrawY, destSection.width, destSection.height);
                    g.endFill();
                }
            }
        }
        
        previousUnscaledWidth = unscaledWidth;
        previousUnscaledHeight = unscaledHeight;
    }   

    /**
     *  @private
     */
    override protected function get needsDisplayObject():Boolean
    {
        // If we are hosting untrusted content the hosted loader becomes
        // our display object.
        return !trustedSource || super.needsDisplayObject;
    } 
    
    //--------------------------------------------------------------------------
    //
    //  Methods
    //
    //--------------------------------------------------------------------------
    
    /**
     *  @private
     *  Utility function that sets the underlying bitmapData property.
     */
    protected function setBitmapData(bitmapData:BitmapData, 
                                     internallyCreated:Boolean = false):void
    {         
        // Clear previous bitmapData
        if (_bitmapData)
        {
            // Dispose the bitmap if we created it
            if (bitmapDataCreated) 
                _bitmapData.dispose();
            _bitmapData = null;
        }
        
        if (bitmapData)
        {
            bitmapDataCreated = internallyCreated; 
            
            _bitmapData = bitmapData;
            
            imageWidth = bitmapData.width;
            imageHeight = bitmapData.height;
            
            // Flush the cached scale grid points
            cachedSourceGrid = null;
            cachedDestGrid = null;
        }
            
        invalidateSize();
        invalidateDisplayList();
    }
        
    /**
     *  @private
     *  Utility method which analyzes our source and either acquires the
     *  associated bitmap data immediately or queues up a remote request
     *  as necessary.
     */
    mx_internal function applySource():void
    {   
        var value:Object = _source;
        var bitmapData:BitmapData;
        var tmpSprite:DisplayObject;
		
        // Clear the previous scaleGrid properties
        _scaleGridLeft = NaN;
        _scaleGridRight = NaN;
        _scaleGridTop = NaN;
        _scaleGridBottom = NaN;
        var currentBitmapCreated:Boolean = false;
        
		// Clear any previously loaded content.
		loadedContent = null;
		
		// Reset byte counts and _trustedSource
		_bytesLoaded = NaN;
		_bytesTotal = NaN;
		_trustedSource = true;
		
		// We'll need to reconsider display object sharing.
		invalidateDisplayObjectSharing();
		
        if (value is Class)
        {
            var cls:Class = Class(value);
            value = new cls();
            currentBitmapCreated = true;
        }
        else if (value is String)
        {
            loadExternal(value as String);
        }
        
        if (value is BitmapData)
        {
            bitmapData = value as BitmapData;
        }
        else if (value is Bitmap)
        {
            bitmapData = value.bitmapData;
        }
        else if (value is DisplayObject)
        {
            tmpSprite = value as DisplayObject;
        }
        else if (value == null)
        {
            // This will set source to null
        }   
        else
        {
            return;
        }
        
        if (!bitmapData && tmpSprite)
        {
            bitmapData = new BitmapData(tmpSprite.width, tmpSprite.height, true, 0);
            bitmapData.draw(tmpSprite, new Matrix());
            currentBitmapCreated = true;
            
            if (tmpSprite.scale9Grid)
            {
                _scaleGridLeft = tmpSprite.scale9Grid.left;
                _scaleGridRight = tmpSprite.scale9Grid.right;
                _scaleGridTop = tmpSprite.scale9Grid.top;
                _scaleGridBottom = tmpSprite.scale9Grid.bottom;
            }
        }       
        
        setBitmapData(bitmapData, currentBitmapCreated);
    }
    
    /**
     *  @private
     */
    mx_internal function loadExternal(url:String):void
    {   
        var loaderInfo:Object;
        		        
        if (contentLoader)
        {
            // We defer our load request to the configured content loader.
            var contentRequest:ContentRequest = contentLoader.load(url, contentGrouping);
            
            if (contentRequest.complete)
            {
                // No need to attach listeners as we've received a fully complete
                // request result.
                contentComplete(contentRequest.content);
            }
            else
            {
                contentRequest.addEventListener(Event.COMPLETE, 
                    loader_completeHandler, false, 0, true);
                contentRequest.addEventListener(IOErrorEvent.IO_ERROR, 
                    loader_ioErrorHandler, false, 0, true);
                contentRequest.addEventListener(ProgressEvent.PROGRESS, 
                    loader_progressHandler, false, 0, true);
                contentRequest.addEventListener(SecurityErrorEvent.SECURITY_ERROR, 
                    loader_securityErrorHandler, false, 0, true);
            }
        }
        else
        {
            var loader:Loader = new Loader();
            
            var loaderContext:LoaderContext = new LoaderContext();
            loaderContext.checkPolicyFile = true;
            
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, 
                loader_completeHandler, false, 0, true);
            loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, 
                loader_ioErrorHandler, false, 0, true);
            loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, 
                loader_progressHandler, false, 0, true);
            loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, 
                loader_securityErrorHandler, false, 0, true);
            try
            {
                loader.load(new URLRequest(url), loaderContext);
                dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS));
            }
            catch (error:SecurityError)
            {
                handleSecurityError(error);
            }
        }
    }
    
    /**
     * @private
     * Utility function used for higher quality image scaling. Essentially we
     * simply step down our bitmap size by half resulting in a much higher result
     * though taking potentially multiple passes to accomplish.
     */
    protected static function resample(bitmapData:BitmapData, newWidth:uint, 
                                       newHeight:uint):BitmapData
    {
        var finalScale:Number = Math.min(newWidth/bitmapData.width, 
            newHeight/bitmapData.height);
        var finalData:BitmapData = bitmapData;
        
        if (finalScale > 1) 
        {
            finalData = new BitmapData(bitmapData.width * finalScale, 
                bitmapData.height * finalScale, true, 0);
            
            finalData.draw(bitmapData, new Matrix(finalScale, 0, 0, 
                finalScale), null, null, null, true);
            
            return finalData;
        }
        
        var drop:Number = .5;
        var initialScale:Number = finalScale;
        
        while (initialScale/drop < 1) 
            initialScale /= drop;
        
        var bd:BitmapData = new BitmapData(Math.ceil(bitmapData.width * 
            initialScale), Math.ceil(bitmapData.height * initialScale));
        
        bd.draw(finalData, new Matrix(initialScale, 0, 0, initialScale), 
                null, null, null, true);
        finalData = bd;
        
        for (var scale:Number = initialScale * drop; 
             Math.round(scale * 1000) >= Math.round(finalScale * 1000); 
             scale *= drop) 
        {
            bd = new BitmapData(Math.ceil(bitmapData.width * scale), 
                Math.ceil(bitmapData.height * scale));
            bd.draw(finalData, new Matrix(drop, 0, 0, drop), null, null, 
                null, true);
            finalData.dispose();
            finalData = bd;
        }
        
        return finalData;
    }
    
    /**
     * @private
     * Invoked upon completion of a load request.
     */
    protected function contentComplete(loaderInfo:LoaderInfo):void
    {
        if (loaderInfo.childAllowsParent) 
        {
            // For trusted content we adopt the loaded BitmapData.
            var image:Bitmap = Bitmap(loaderInfo.content);
            setBitmapData(image.bitmapData);
        } 
        else 
        {
			// Clear any previous bitmap data.
			setBitmapData(null);
			
            // For untrusted content we must host the acquired Loader
            // instance directly as our DisplayObject. 
            displayObjectSharingMode = DisplayObjectSharingMode.OWNS_UNSHARED_OBJECT;
            invalidateDisplayObjectSharing();
			
			// Create a content holder to use as our display object.
            var contentHolder:Sprite = new Sprite();
            setDisplayObject(contentHolder);    
			loadedContent = loaderInfo.loader;
            contentHolder.addChild(loadedContent);
			
			// Retain our source image width and height.
            imageWidth = loaderInfo.width; 
            imageHeight = loaderInfo.height ;
      
			// Update
			invalidateSize();
            invalidateDisplayList(); 
			
			// Denote that we are hosting an untrusted image and as such some
			// features requiring access to the bitmap data will no longer
			// function.
            _trustedSource = false; 
        }
    }
    
    /**
     * @private
     * Returns true if are to consider aspect ratio while scaling.
     */  
    protected function get maintainAspectRatio():Boolean
    {
        return (_scaleMode == BitmapScaleMode.LETTERBOX && _fillMode == BitmapFillMode.SCALE);
    }
    
    //--------------------------------------------------------------------------
    //
    //  Event handlers
    //
    //--------------------------------------------------------------------------
    
    /**
     *  @private
     */
	mx_internal function loader_completeHandler(event:Event):void
    {
        try
        {
            var loaderInfo:LoaderInfo = (event.target is ContentRequest) ? 
                event.target.content as LoaderInfo : event.target as LoaderInfo;
            
            if (loaderInfo.bytesLoaded)
            {
                _bytesLoaded = _bytesTotal;
                contentComplete(loaderInfo);
            }
        }
        catch (error:SecurityError)
        {
            handleSecurityError(error);
        } 
		
		dispatchEvent(event);
    }
    
    /**
     *  @private
     */
	private function loader_ioErrorHandler(error:IOErrorEvent):void
    {
        // clear any current image 
        setBitmapData(null);
		
		// forward the event, only in the case of a listener, else
		// an RTE will occur.
		if (hasEventListener(error.type))
			dispatchEvent(error);
    }
    
    /**
     *  @private
     */
	private function loader_securityErrorHandler(error:SecurityErrorEvent):void
    {
        // clear any current image and forward the error.
        setBitmapData(null);
        dispatchEvent(error);
    }
    
    /**
     *  @private
     */
	private function loader_progressHandler(progressEvent:ProgressEvent):void
    {   
        _bytesLoaded = progressEvent.bytesLoaded;
        _bytesTotal = progressEvent.bytesTotal;
        
        // forward the event
        dispatchEvent(progressEvent);
    }
        
    /**
     *  @private
     */
    private function handleSecurityError(error:SecurityError):void
    {
        setBitmapData(null);
        dispatchEvent(new SecurityErrorEvent(SecurityErrorEvent.SECURITY_ERROR, 
            false, false, error.message));
    }
}  
}
