Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Adobe AIR Development

Reply
Highlighted
New Developer
Posts: 24
Registered: ‎10-25-2010
My Device: Not Specified

PlayBook Accelerometer SDK

To those who have a device on-hand. Has anyone you been successful in trying to get the data from the accelerometer sensors?

 

Does anyone know the correct way to do it?

 

I've been trying on the device we have and have not had much luck... doesn't look like the AccelerometerEvent is even firing.

 

in my Main constructor I call --

 

 

this.addEventListener(AccelerometerEvent.UPDATE, onAccelerometerUpdateEvent);

 

 

 

And below is the event handler, I'm just updating a Label's text property with readings from the Update event.

 

 

private function onAccelerometerUpdateEvent(event:AccelerometerEvent) : void
{
  label.text = event.accelerationX + " -- " + event.accelerationY + " -- " + event.accelerationZ; 
}

 

But the label remains in it's initialized state .. i.e. "Hello World!"

 

 

 

Developer
Developer
Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: PlayBook Accelerometer SDK

I haven't looked at the APIs but if it is anything like on the phones, you have enable polling of the accelerometer for each app in order to be able to check it. The only things that can be check statically by default is the orientation.

Developer
Posts: 133
Registered: ‎12-02-2010
My Device: Z10 & Dev Alpha C
My Carrier: T

Re: PlayBook Accelerometer SDK

THis is from the Tour De Flex Mobile project and it works on the Device I tested it. It reads out the values.

<?xml version="1.0" encoding="utf-8"?>
<s:VGroup xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        paddingTop="20" paddingLeft="20" paddingRight="20">
    
    <fxSmiley Frustratedcript>
        import flash.sensors.Accelerometer;
    </fxSmiley Frustratedcript>
    
    <s:creationComplete>
        if (Accelerometer.isSupported)
        {
            var accelerometer:Accelerometer = new Accelerometer();
            accelerometer.addEventListener(AccelerometerEvent.UPDATE, function(event:AccelerometerEvent):void {
                l.text = "accelerationX = " + event.accelerationX +
                "\naccelerationY = " + event.accelerationY +
                "\naccelerationZ = " + event.accelerationZ +
                "\ntimestamp = " + event.timestamp;
            });
        }
        else
        {
            l.text = "Accelerometer not supported.";
        }
    </s:creationComplete>
    
    <s:Label id="l"/>
    
</s:VGroup>

---------------------------------------------------------------------
Developer of Stocks for Blackberry 10
Developer
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course
My Carrier: Vodafone

Re: PlayBook Accelerometer SDK

You need to add the event listener to an instance of the Accelerometer class, not to "this"...

 

 

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands