0

我正在使用 FlashBuilder 4.6 开发 Android 应用程序。在应用程序中,需要在设备方向更改时设置一些值。即当屏幕/设备方向从横向更改为纵向时设置值,反之亦然。

虽然最初我的应用程序具有景观方向。而这个要求是具体的。

我希望每次屏幕/设备方向更改时都必须在此处设置值。我没有得到想要的结果。
请指导我并告诉我我的代码是否有误,或者我该如何实现。

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark" title="{data}" 
        xmlns:mx="library://ns.adobe.com/flex/mx"
        viewActivate="view1_viewActivateHandler(event)"
        creationComplete="view1_creationCompleteHandler(event)">
<fx:Script>
   <![CDATA[
protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
{
    if(Accelerometer.isSupported)
    {
    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 
     //values.
     stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE,adjust);
}
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";
     }
}

</fx:Script>

谢谢。

4

2 回答 2

1

花了两天时间终于找到了解决方案。

在更新函数中,在 stage.addEventListner 中 添加OrientationChanging 事件。

private function update(event:AccelerometerEvent):void
{
  this.stage.autoOrients  = true;
  stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGING,adjust);
}

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

非常感谢所有查看此问题并尝试解决问题的人。:)

于 2012-06-16T04:41:23.050 回答
0

我不是一个经过实验的编码器!但是:私有函数更新(事件:AccelerometerEvent):void 应该是:私有函数acl(事件:AccelerometerEvent):void ?? 或以下代码中的类似内容 if(stage[not event].afterOrientation == ??? 它只是一个意见!

于 2012-06-14T18:18:23.177 回答