Skip to main content
Known Participant
June 25, 2015
Question

preventDefault() on working in Adobe Air for IOS

  • June 25, 2015
  • 1 reply
  • 931 views

Working on Adove Air  for IOS version.

Its auto oriented app.Means app  should  be rotated according to device orientation like showing portrait view ,if device is in portrait mode ,otherwise showing landscape mode.

I want to prevent app to rotating upside_down.

I try to prevent app in ORIENTATION_CHANGING event handler.

But its not work for IOS,only works for Android..

Can anyone tell me any alternative,I can use?

Thanks,

Amisha

This topic has been closed for replies.

1 reply

sinious
Legend
June 25, 2015

I have a few landscape-only apps that I use a handler such as you are to prevent the default and/or set it. I don't know if you're working in Flash Pro timeline or a separate class file but if you're working in a class file, just add the protection modifiers (protected/public/etc):

import flash.events.StageOrientationEvent;

// this should be global either to Flash or a protected class var

var stageOrientation:String = stage.orientation;

// this is run during start-up init

if (startOrientation == StageOrientation.DEFAULT || startOrientation == StageOrientation.UPSIDE_DOWN)

{

  stage.setOrientation(StageOrientation.ROTATED_RIGHT);

}

else

{

  stage.setOrientation(startOrientation);

}

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING, orientationChangeHandler);

// this is run any time orientation is changed to assure it's correct

function orientationChangeHandler(e:StageOrientationEvent):void

{

  if (e.afterOrientation == StageOrientation.DEFAULT || e.afterOrientation == StageOrientation.UPSIDE_DOWN)

  {

  e.preventDefault();

  }

}

On an iPad the default that I select in AIR becomes default and Apple will reject an app that cannot perform the upside down version of itself (since it's the same). So this just lets me check off to allow auto-orient, allows the user to spin either landscape side and simply prevents rotation if it's not my original selection.

The last time I compiled that app was AIR 17 and it is working fine. from OS 5 to OS 8

Known Participant
June 25, 2015

I want to keep app in both mode portrait  as well as landscape

That means showing portrait view or landscape view according to device orientation

Its rotate in all direction like (default,rotated_left,rotated_right,upside_down)

Now I want to prevent app  to rotating to upside_down.I don't want to allow app to rotate to upside_down

So I write following code,

stage.addEventListener( StageOrientationEvent.ORIENTATION_CHANGING, updateOrientation );

private function updateOrientation(e:StageOrientationEvent ):void
{

      var startOrientation:String = e.afterOrientation ;

      if (startOrientation == StageOrientation.UPSIDE_DOWN)

      {

              e.stopImmediatePropagation();

               e.preventDefault();

     }

}

App still rotating to upside_down.its not prevent  from rotating

Thanks,

Amisha.

sinious
Legend
June 25, 2015

Is this going on the Apple store? As I mentioned above, I got rejected for not supporting upside down landscape.