3

I have some views in my mobile app (for both ios and android) whose orientation was fixed to PORTRAIT using <aspectRatio>portrait</aspectRatio><autoOrients>false</autoOrients> in the settings xml file.

Now I have added another view which plays video from Youtube and it should be able to play videos, both in LANDSCAPE & PORTRAIT orientation. So I came across this question which provides a solution to restrict only 1 orientation (globally for all views), but how can I re-enable orientation change only for one view?

Note: I am using Flash Builder 4.6 with actionscript 3 and youtube api

Any help is appreciated :)

Community
  • 1
  • 1
AabinGunz
  • 12,109
  • 54
  • 146
  • 218

1 Answers1

2

Remove the <aspectRatio>portrait</aspectRatio><autoOrients>false</autoOrients> from XML, as it will generalize it for the whole application.

Do it separately for each and every view. Since for first view you need a PORTRAIT, do it like this.(Taken from Adobe Docs)

stage.addEventListener( StageOrientationEvent.ORIENTATION_CHANGING, onOrientationChanging ); 

function onOrientationChanging( event:StageOrientationEvent ):void {
    // If the stage is about to move to an orientation we don't support, lets prevent it
    // from changing to that stage orientation.
    if(event.afterOrientation == StageOrientation.ROTATED_LEFT || event.afterOrientation==StageOrientation.ROTATED_RIGHT ) 
    {
        event.preventDefault();
    }
}

For the second view, do not define any stage orientation listeners, as you need both PORTRAIT and LANDSCAPE.

halfer
  • 19,824
  • 17
  • 99
  • 186
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • Thankyou for your reply. There are many views so I asked is there a way **globally for all views** to restrict it & enable only for 1 view? As I do not want to add code in all the views which should have restricted orientation. – AabinGunz May 02 '13 at 12:36
  • Why don't you just define this in a seperate AS and call it whichever view you want. Since the XML part globalizes what you put in there. – Shankar Narayana Damodaran May 02 '13 at 12:39
  • I am looking for a way where I do not need to add **any code** on the views which should be orientation restricted (since I have many views) but add to only video playback view to enable orientation. If that is not possible i'll have to go with this solution :) – AabinGunz May 02 '13 at 12:50
  • I guess there is no turnaround, however i suggest you open a bounty on this question(if you are really serious about the solution), such that some experts will find a way out. – Shankar Narayana Damodaran May 02 '13 at 12:52
  • any idea what should I use for resetting yt player's size on orientation change? `this.stage.stageWidth` or `FlexGlobals.topLevelApplication.width` or `this.stage.width` or any other? – AabinGunz Jun 04 '13 at 11:20