4 Replies Latest reply on Jun 15, 2012 8:52 AM by jlehenbauer-m

    StageOrientationEvent.ORIENTATION_CHANGE not Dispatching

    MatteoLegittimo

      Hi!

      why in my Mobile Application is not dispatching the StageOrientationEvent event?

      What's wrong?

      I set in my project "Automatically reorient".

       

      This is my view:

       

      <?xml version="1.0" encoding="utf-8"?>

      <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

              xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView" creationComplete="view1_creationCompleteHandler(event)">

          <fx:Script>

              <![CDATA[

                  import mx.events.*;

                  import mx.events.StateChangeEvent;

                  import mx.states.AddChild;

                 

                  protected function view1_creationCompleteHandler(event:FlexEvent):void{

       

                      addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, changeOrientationListener)

                  }

       

                  protected function changeOrientationListener(event:Event):void{

                      trace(event)

                  }

       

              ]]>

          </fx:Script>   

      </s:View>

       

       

      thanks

        • 1. Re: StageOrientationEvent.ORIENTATION_CHANGE not Dispatching
          MatteoLegittimo Level 1

          Solved:

           

          <?xml version="1.0" encoding="utf-8"?>

          <s:View xmlns:fx="http://ns.adobe.com/mxml/2009"

                  xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView" creationComplete="view1_creationCompleteHandler(event)">

              <fx:Script>

                  <![CDATA[

                      import mx.events.*;

                     

                      protected function view1_creationCompleteHandler(event:FlexEvent):void{

                          addEventListener(Event.ADDED_TO_STAGE, _onAddedToStage)

                      }

                     

                     

                      private function _onAddedToStage(event:Event):void{

                          if(stage.autoOrients)       

                              stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE, _onStage_OrientationChange);

                      }

                     

                      private function _onStage_OrientationChange(event:StageOrientationEvent):void{

                         

                          switch(event.afterOrientation){

                             

                              case StageOrientation.DEFAULT:

                                  trace('DEFAULT')

                                  break;

                             

                              case StageOrientation.ROTATED_RIGHT:

                                  trace('ROTATED_RIGHT')

                                  break;

                             

                              case StageOrientation.ROTATED_LEFT:

                                  trace('ROTATED_LEFT')

                                  break;

                             

                              case StageOrientation.UPSIDE_DOWN:

                                  trace('UPSIDE_DOWN')

                                  break;

                             

                              case StageOrientation.UNKNOWN:

                                  trace('UNKNOWN')

                                  break;

                          }

                      }

                  ]]>

              </fx:Script>   

          </s:View>

          • 2. Re: StageOrientationEvent.ORIENTATION_CHANGE not Dispatching
            davidh38

            This code works for me, but not if i pushed a view first. And i put the code the the "pushedView" it doesnt work. What could solve the problem?

            • 4. Re: StageOrientationEvent.ORIENTATION_CHANGE not Dispatching
              jlehenbauer-m

              this again works for my app in the Emulator, but on my device, it still updates late, changing according to the dimensions of the screen before the orientation change. How could this be??