Попробуйте расширить компонент 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;
}
}
}