繁体   English   中英

Flash Builder 4.6移动方向

[英]Flash Builder 4.6 Mobile Orientation

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

尽管最初我的应用程序具有LandScape方向。 这项要求是针对特定观点的。

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

<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>

谢谢。

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

在更新函数中,在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;
  }
}

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM