Im using flash builder 4.5 and AS3 to load images dynamicallly from a live JSON data source. its loading and working fine and responding to my swipe gestures (left swipe to go BACK and right swipe to advance to next image)...
I'd like to add some actionscript to detect the orientation of the picture after its loaded successfully then if its a vertically oriented photo, turn the stage 90 degrees (and set some type of flag to remember that its in that 'rotated state'.
how can I achieve this?
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
}
You can use the width:height ratio to work out whether the shape of the image is portrait or landscape. I am not confident that you want to rotate the Stage but rather the image itself.
Here is a class I've written up that can help:
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;
}
}
This will manage the rotation for you and you'll be able to determine if the image was originally a Landscape
or Portrait
orientation via .orientation
.