I am new to Flex and Flash Builder and acquired the book as an introduction to this new environment. I created a mobile flex project in Flash Builder 4.6 and copied the text from pages 47 and 48 of the publication and I am getting 1 error and 1 warning. The error is 1026: Constructor Functions must be instance methods and this relates to the line private var accelerometer:Accelerometer; and the warning 'Access of undefined property toTimeString' relates to the line info.text = "Updated: " + new Date().toTimeString + "\n\n"
The complete code is as follows:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
applicationComplete="application1_applicationCompleteHandler(event)">
<fx:Script>
<![CDATA[
import flash.sensors.Accelerometer;
import mx.events.FlexEvent;
private var accelerometer:Accelerometer;
protected function application1_applicationCompleteHandler(event:FlexEvent):void
{
if (Accelerometer.isSupported==true)
{
accelerometer = new Accelerometer();
accelerometer.addEventListener(AccelerometerEvent.UPDATE,handleUpdate);
}
else
{
status.text = "Accelerometer Not Supported";
}
}
private function handleUpdate(event:AccelerometerEvent):void
{
info.text = "Updated: " + new Date().toTimeString + "\n\n"
+ "acceleration X: " + event.accelerationX + "\n"
+ "acceleration Y: " + event.accelerationY + "\n"
+ "acceleration Z: " + event.accelerationZ;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Label id="status" text="Gently Shake the Device" top="10" width="100%" textAlign="center"/>
<s:TextArea id="info" width="100%" height="200" top="40" editable="false"/>
</s:Application>
Can somebody please advise why I am getting these problems?
many thanks in advance,
Bob

Help





