Click here to Skip to main content
12,758,605 members (30,974 online)
Rate this:
Please Sign up or sign in to vote.
Hello friends,

I'm working with FlashBuilder 4.6 to develop Android app.
In the application there is a requirement of setting some values when device orientation changes. i.e. setting the values when the screen/device orientation changes from Landscape to Portrait and vice-verse.

Although Initially my application has LandScape orientation. And this requirement is on specific view.

I want every time when the screen/device orientation changes the values must be set there.
I am not getting the desired result.
Please guide me and tell me if I am at wrong in code or how can i achieve this.

<s:View xmlns:fx="" 
		xmlns:s="library://" title="{data}" 
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
	accl = new Accelerometer();
        accl.addEventListener(AccelerometerEvent.UPDATE,update);				//accl.addEventListener(AccelerometerEvent.UPDATE,adjustImage);
private function update(event:AccelerometerEvent):void
     this.stage.autoOrients = true;
     //in the below line I am attaching StageOrienationEvent that will adjust the 
private function adjust(event:StageOrientationEvent):void
     if(event.afterOrientation == StageOrientation.ROTATED_LEFT)
	testVal.text ="After OR is LEFT";
     else if(event.afterOrientation == StageOrientation.ROTATED_RIGHT)
	testVal.text ="After OR is RIGHT"; 
     else if(StageAspectRatio.LANDSCAPE)
	testVal.text ="StageAspectRatio is Landscape";
     else if(StageAspectRatio.PORTRAIT)
	testVal.text="StageAspectRatio is  Portrait";


Posted 13-Jun-12 20:02pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Finally found the solution after spending two days on this.

in update function add OrientationChanging Event in stage.addEventListner.

protected function update(event:AccelerometerEvent):void
  this.stage.autoOrients  = true;

protected function adjust(event:StageOrientationEvent):void
    case StageOrientation.DEFAULT:
       //Do Something here. The Portrait Position.
    case StageOrienatation.ROTATED_LEFT:
      //Do Something here when you rotate your phone portrait to left side.
    case StageOrienatation.ROTATED_RIGHT:
      //Do something here when you rotate your phone portrait to right side.

Many thanks to all who viewed this question and try put their efforts for solution.
Happy Programming :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 16 Jun 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100