Jump to content

Problem with acceleromter example in Blackberry Tablet Application with Flex 4.5

ukracer's Photo
Posted Mar 01 2012 08:39 AM
3135 Views

Hello,

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

2 Replies

0
  rtretola's Photo
Posted Mar 07 2012 08:07 AM

Bob,

You can change the toTimeString() to simply toString(). I tested this and was able to run the application under Flex 4.6 with AIR 3.1.

info.text = "Updated: " + new Date().toString() + "\n\n"

Rich Tretola
 : Mar 07 2012 08:07 PM
So is it Flash Builder 4.5 or 4.6?

I copied and pasted your code into my Flash Builder 4.6, created a brand new Flex Mobile project and the only I ran into was the date/time for which Rich posted a fix.

I do not see the other error message.
Alejandro Ramirez
Digital Photography Club
Administrator