Изображение искры - фактическое местоположение изображения - PullRequest
0 голосов
/ 09 июня 2011

Быстрый вопрос ..

У меня есть элемент управления изображением искры с scaleMode = 'letterbox'.Когда я загружаю изображение меньше, чем фактический элемент управления, оно красиво центрируется.Теперь, что мне нужно знать, это фактическое расположение изображения в почтовом ящике.Другими словами, если он будет дополнен 100px с каждой стороны, мне нужно знать количество отступов, если оно есть.

У кого-нибудь есть идеи?

-JD

1 Ответ

0 голосов
/ 19 сентября 2011

Попробуйте расширить компонент Spark Image, включив в него некоторые полезные свойства, доступные только для чтения, для доступа к местоположению масштабированного изображения (и размерам).

Следующее создаст 4 новых привязываемых свойства, которые будут возвращать фактические масштабированные x, y, ширину и высоту изображения, отображаемого внутри компонента Spark Image.

package 
{
    import spark.components.Image;

    public class ExtendedSparkImage extends Image
    {

        public function ExtendedSparkImage()
        {
            super();
        }

        /**
         * Returns the X coordinate offset of the image display taking into account 
         * the actual constraints of the container.  If no scaling has occurred it 
         * will return zero.
         */ 
        [Bindable(event="scaledXOffsetChanged")]
        public function get scaledXOffset():Number
        {
            var num:Number = 0;

            if (scaleMode == "letterbox")
            {
                try
                {                   
                    if ( (width > 0) && (sourceWidth < sourceHeight) )
                    {       
                        num = (width - scaledWidth) / 2;    
                    }                   
                }
                catch(e:Error)
                {
                    num = 0;
                }
            }

            return num;
        }

        /**
         * Returns the Y coordinate offset of the image display taking into account 
         * the actual constraints of the container.  If no scaling has occurred it 
         * will return zero.
         */ 
        [Bindable(event="scaledYOffsetChanged")]
        public function get scaledYOffset():Number
        {
            var num:Number = 0;

            if (scaleMode == "letterbox")
            {
                try
                {                   
                    if ((height > 0) && (sourceHeight < sourceWidth))
                    {
                        num = (height - scaledHeight) / 2;              
                    }                   
                }
                catch(e:Error)
                {
                    num = 0;
                }
            }

            return num;
        }

        /**
         * Returns the width of the image display taking into account the actual 
         * constraints of the container.  If no scaling has occurred the actual
         * width of the control is returned.
         */ 
        [Bindable(event="scaledWidthChanged")]
        public function get scaledWidth():Number
        {
            var num:Number = this.width;

            if (scaleMode == "letterbox")
            {
                try
                {
                    if ( (width > 0) && (sourceWidth < sourceHeight) )
                    {
                        num = (sourceWidth/sourceHeight) * width;                       
                    }                   
                }
                catch(e:Error)
                {
                    num = this.width;
                }
            }



            return num;
        }

        /**
         * Returns the height of the image display taking into account the actual 
         * constraints of the container.  If no scaling has occurred the actual
         * height of the control is returned.
         */ 
        [Bindable(event="scaledHeightChanged")]
        public function get scaledHeight():Number
        {
            var num:Number = this.width;

            if (scaleMode == "letterbox")
            {
                try
                {
                    if ((height > 0) && (sourceHeight < sourceWidth))
                    {
                        num = (sourceHeight/sourceWidth) * height;
                    }                   
                }
                catch(e:Error)
                {
                    num = this.height;
                }
            }

            return num;
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...