Actionscript 3 如何在加载图像后检测图像方向(纵向与横向),然后相应地旋转舞台?

Actionscript 3 如何在加载图像后检测图像方向(纵向与横向),然后相应地旋转舞台?,actionscript-3,apache-flex,flash-builder,flex4.5,Actionscript 3,Apache Flex,Flash Builder,Flex4.5,Im使用FlashBuilder4.5和AS3从实时JSON数据源动态加载图像。它的加载和工作良好,并响应我的滑动手势(左滑动返回,右滑动前进到下一个图像) 我想添加一些actionscript来检测图片加载成功后的方向,如果是垂直方向的图片,将舞台旋转90度(并设置某种类型的标志以记住它处于“旋转状态”) 我怎样才能做到这一点 if (myPic && myPic.width > myPic.height) { // this picture is horiz

Im使用FlashBuilder4.5和AS3从实时JSON数据源动态加载图像。它的加载和工作良好,并响应我的滑动手势(左滑动返回,右滑动前进到下一个图像)

我想添加一些actionscript来检测图片加载成功后的方向,如果是垂直方向的图片,将舞台旋转90度(并设置某种类型的标志以记住它处于“旋转状态”)

我怎样才能做到这一点

if (myPic && myPic.width > myPic.height)
 {
     // this picture is horizontal, so leave stage in normal landscape aspect ratio
 } else {
     // something here to take the stage and rotate it 90 degrees
 }

你可以使用宽高比来计算图像的形状是纵向的还是横向的。我不确定你是想旋转舞台,而是想旋转图像本身

下面是我写的一节课,可以帮助你:

public class PhotoHolder extends Sprite
{

    public static const Landscape:int = 0;
    public static const Portrait:int = 1;


    private var _bitmap:Bitmap;
    private var _orientation:int = 0;


    public function PhotoHolder(bitmap:Bitmap)
    {
        _bitmap = bitmap;
        _bitmap.x = -(_bitmap.width / 2);
        _bitmap.y = -(_bitmap.height / 2);

        if(bitmap.width >= bitmap.height) _orientation = Landscape;
        else
        {
            rotation = 90;
            _orientation = Portrait;
        }

        addChild(_bitmap);
    }


    public function get orientation():int
    {
        return _orientation;
    }

}
这将为您管理旋转,您将能够通过
.orientation
确定图像最初是
横向
还是
纵向
方向