我试图在文本输入上简单地显示 accelerometerX 的更新值,但我不知道如何在 Flash Builder 附带的模拟器上模拟摇晃或轻推。下面是我正在使用的代码。
<?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="MainView" creationComplete="onCreationComplete(event)">
<fx:Script>
<![CDATA[
import flash.sensors.Accelerometer;
import mx.events.FlexEvent;
protected function onCreationComplete(event:FlexEvent):void
{
var tShake:Accelerometer = new Accelerometer();
tShake.addEventListener(AccelerometerEvent.UPDATE, onAccelerometerUpdate);
}
protected function onAccelerometerUpdate(event:AccelerometerEvent):void {
sampleDisplay.text = event.accelerationX.toString();
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:TextArea id="sampleDisplay" x="14" y="11"/>
</s:View>
这是我为使其发挥作用而进行的悲伤尝试的视频。当然不是。