views:

17

answers:

1

I'm an experienced AS3 developer doing AIR development for the first time in order to create an iPhone app. I'm trying to account for variable device orientations using the StageOrientationEvent and related classes, and I'm getting a VerifyError when trying to test on a desktop machine, presumably because orientation-related classes are mobile-device specific.

The Adobe docs for the iPhone packager imply that it's possible to test an app containing mobile-specific code, as long as you use flags like Stage.supportsOrientationChange to test for capabilities before actually using them. Unfortunately, it seems like AIR is checking for unacceptable classes at startup, so the check is useless.

How can I test this app on the desktop without commenting out mobile-specific code every time I switch devices?

The relevant code:

package 
{
import flash.display.Sprite;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageOrientation;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.StageOrientationEvent;

public class Main extends Sprite 
{
    public function Main():void 
    {
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

    private function init(e:Event = null):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);

        if (Stage.supportsOrientationChange) 
        {
            stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, onOrientationChange);
        }
    }

    private function onOrientationChange(event:StageOrientationEvent):void
    {
        switch (event.afterOrientation) 
        {
            case StageOrientation.DEFAULT: //ignore.  Landscape.
                break;
            case StageOrientation.ROTATED_RIGHT:
                    stage.setOrientation(StageOrientation.ROTATED_RIGHT);
                break;
            case StageOrientation.ROTATED_LEFT:
                stage.setOrientation(StageOrientation.ROTATED_LEFT);
                break;
            case StageOrientation.UPSIDE_DOWN: //ignore.  Landscape.
                break;
        }
    }
}

}

And the error I get:

[Fault] exception, information=VerifyError: Error #1014: Class flash.events::StageOrientationEvent could not be found.