0

フラッシュ ビルダー 4.5 と AS3 を使用して、ライブ JSON データ ソースから画像を動的に読み込みます。そのロードと正常に動作し、私のスワイプジェスチャに応答します(左スワイプで戻る、右スワイプで次の画像に進みます)...

画像が正常に読み込まれた後に画像の向きを検出するためのアクション スクリプトを追加し、垂直方向の写真の場合は、ステージを 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
 }
4

1 に答える 1

2

幅:高さの比率を使用して、画像の形状が縦長か横長かを判断できます。ステージを回転させたいとは思いませんが、画像自体を回転させたいと思っています。

ここに私が書いたクラスがあります:

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;
    }

}

Landscapeこれにより、回転が管理され、 を介して、画像がもともとまたはのPortrait向きであったかどうかを判断できます.orientation

于 2013-03-04T02:33:07.347 に答える