Using Accelerometer on Flash Lite with Nokia Platform Services

Accelerometer is a motion sensor, one device responsible for measuring the relative positions of the axes x, y and z, ie, calculate the acceleration of the object. Today it is used for a variety of utilities such as: air bags, vibration measurement, measurement of inclination, smartphones, video games etc.

The accelerometer is used today is used for a variety of utilities such as: air bags, vibration measurement, measurement of inclination, smartphones, video games etc.

Flash Player 10.1 (only for mobile) and Flash Lite 4.0 have access to the device’s accelerometer. I’m anxious to get their hands on a Nokia N8 to test new features Flash Lite 4.0, but this hard. Meanwhile, we are developing with Flash Lite 3.0 and 3.1.
Nokia has created a library especially for working with Flash Lite feature that gives access to natively are not possible as access to the accelerometer, GPS, calendar, contacts etc.

Nokia has created a library especially for working with Flash Lite feature that gives access to natively are not possible as access to the accelerometer, GPS, calendar, contacts etc.

I’ll show a simple example of using the accelerometer with Flash Lite 3.0 and Nokia Platform Services.
Download the library Nokia and then save the directory under your operating system:

Nokia Platform Services only works on devices running Symbian S60 5th.

  • Mac – /Users//Library/Application/Support/Adobe/Flash CS5/en/Configuration/Classes/
  • Windows Vista – /Users//AppData/Local/Adobe/Flash CS4/en/Configuration/Classes.
  • Windows XP – //Local Settings/Application Data/Adobe/Flash CS5/en/Configuration/Classes/

We will start our first example:

  • Create a file of type ActionScript 2.0 and ask them to compile for Flash Lite 3.0 or 3.1. Or you can create directly from Adobe Device Central CS5.
  • Create a symbol of type MovieClip and give it the instance name of “ball_mc”.
  • Create three text fields of type dynamic, therein are shown the positions x, y and z.
  • We must have a stage like this:

    Stage for test Accelerometer

This done, let’s now part of programming:
We will start setting the stage for not changing the size of the application if the window is resized. The “DisableKeypadCompatibilityMode” is for use in smartphones with touch screens, if not used, the smartphone will automatically add the virtual keys corresponding to a non-touchscreen smartphone.
[ACTIONSCRIPT]
Stage.scaleMode = “noScale”;
Stage.align = “LT”;

fscommand2(“DisableKeypadCompatibilityMode”);
fscommand2(“FullScreen”, “true”);
[/ACTIONSCRIPT]
Now let’s import the classes made by Nokia and use the Device class and disable the autorotation of the application.
[ACTIONSCRIPT]
import com.nokia.lib.Service;
import com.nokia.lib.Device;

var deviceObject:Object = new Device();
deviceObject.DisableAutoRotation(true);
[/ACTIONSCRIPT]
Service will use the class by passing the parameter sensor and then passing the criterion for a search the coordinates of the accelerometer.
[ACTIONSCRIPT]
var sensors = new Service(“Service.Sensor”, “ISensor”);
var inParam = {SearchCriterion:”AccelerometerAxis”};
var outParams = sensors.FindSensorChannel(inParam);
[/ACTIONSCRIPT]
Will return a series of values we use to “advise” the smartphone that our application will be updated with every change in value of the coordinates of the accelerometer through a callback method.
[ACTIONSCRIPT]
var channelInfo = outParams.ReturnValue;
var channelId = channelInfo[0].ChannelId;
var contextType = channelInfo[0].ContextType;
var quantity = channelInfo[0].Quantity;
var channelType = channelInfo[0].ChannelType;
var location = channelInfo[0].Location;
var vendorId = channelInfo[0].VendorId;
var dataItemSize = channelInfo[0].DataItemSize;
var channelDataTypeId = channelInfo[0].ChannelDataTypeId;
var channelParams = {ChannelId:channelId, ContextType:contextType, Quantity:quantity, ChannelType:channelType, Location:location, VendorId:vendorId, DataItemSize:dataItemSize, ChannelDataTypeId:channelDataTypeId};

var inParams = {ListeningType:”ChannelData”, ChannelInfoMap:channelParams};
sensors.RegisterForNotification(inParams, callBack);
function callBack(transactionID:String, eventID:String, outParam:Object)
{
if (outParam.ErrorCode == 0)
{
var channelData = outParam.ReturnValue;
txtX.text = channelData.XAxisData;
txtY.text = channelData.YAxisData;
txtZ.text = channelData.ZAxisData;

xSpeed -= channelData.XAxisData/NOISE;
ySpeed += channelData.YAxisData/NOISE;
}
}
[/ACTIONSCRIPT]
Then just update the x and y coordinates with the values and xSpeed ySpeed in our MovieClip. Made available at the source code to define how far the MovieClip can walk, or only in the area of our application.
DOWNLOAD SOURCE

To learn more:
http://www.forum.nokia.com/Develop/Other_Technologies/Flash_lite/
http://library.forum.nokia.com/index.jsp?topic=/Flash_Lite_Developers_Library/GUID-46EABDC1-37CB-412A-ACAD-1A1A9466BB68.html

Recommended Books:

Was this article helpful? feel free to make a donation and help keep the blog in the air
Flash, Flash Lite, Nokia , ,

1 comment


  1. Pingback: Flash Lite Tutorial: How To Use Accelerometer on Flash Lite with Nokia Platform Services | Adobe Flash Lite

Leave a Reply