Understanding Accelerometer Development
by @ryancanullaWhat is an Accelerometer?
An accelerometer is a piece of hardware that measures the acceleration of forces. There are two types of forces that we care about; static and dynamic. You can think of static force as gravity which at all times is pulling us towards the center of the earth. We use static acceleration to figure out the angle an object is tilted. Dynamic acceleration is used for measuring the actual motion of an object. For this intro we’ll be talking mostly about tilt-based static acceleration.
Common uses
There are accelerometers all around us from our cars to our computers and phones. In cars they use accelerometer data to determine vibrations on the engine and in the airbag sensors. Companies also use accelerometers in hard-drives to protect data during collisions and general impact. Nintendo Wii shaped the future of motion gaming adding an accelerometer to their remote. Whenever you see a labyrinth style game or are playing a driving game by tilting your phone or tablet you can thank the accelerometer. As developers it’s our job to learn and interpret this information in order to improve the experience to our users.
How to handle local accelerometer on mobile device
When you are writing flash application that will handle local accelerometer updates from a phone or tablet the work flow is very simple. You check the to see if the device supports accelerometer using the flash.sensors.Accelerometer.isSupported() method. If it is supported you register a few event listeners, then handle the updates when they come in.
if (Accelerometer.isSupported) {
accelerometer = new Accelerometer();
accelerometer.addEventListener(AccelerometerEvent.UPDATE, accUpdateHandler);
}
private final function accUpdateHandler(event:AccelerometerEvent):void {
xSpeed -= event.accelerationX;
ySpeed += event.accelerationY;
}
How to handle accelerometer data from litl os remotes
When you are dealing with multiple remotes connected to a single application things get a bit more complicated because you need to pair remote updates with specific remotes, manage connections, and not mix it up in the meantime. This is an approach that works for us. It involves the creation of three classes by the developer.

LitlRemoteManager()
We will need to extend RemoteHandlerManager in order to inherit functionality. By doing this now we can override two important methods; onRemoteConnected and onRemoteDisconnected. You can do whatever you want inside these methods knowing that they’ll be called when a remote connects/disconnects.
You will need to instantiate after you are connected to the LitlService() as you will need to pass a reference to your service into it’s constructor. You will also need to instantiate a new RemoteFactory() in the constructor. This is what it looks like in our instantiation:
private function createRemoteManager():void {
remoteManager = new LitlRemoteManager(_service, new RemoteFactory());
}
RemoteFactory()
Implement IRemoteFactory(), return RemoteHandler() and you are all set. I usually set this up once and barely look at it again.
package service
{
import com.litl.helpers.richinput.remotehandler.IRemoteHandler;
import com.litl.helpers.richinput.remotehandler.IRemoteHandlerFactory;
public class RemoteFactory implements IRemoteHandlerFactory
{
public function RemoteFactory() {
}
public function createHandler():IRemoteHandler {
return new RemoteHandler();
}
public function get klass():Class {
return RemoteHandler;
}
}
}
RemoteHandler()
We have one job left to do and RemoteHandler() keeps it simple and to the point. This is where we define what to do when we get accelerometer updates. Start by extending AccelerometerEventHandler() and implement IRemoteHandler(). Next, override onAccelerometerEvent and handle your logic to handle accelerometer data. I usually loop through an array of remotes/players in my model and reference the remoteID property to match up remotes.
package service
{
import com.litl.helpers.richinput.remotehandler.AccelerometerRemoteHandler;
import com.litl.helpers.richinput.remotehandler.IRemoteHandler;
import com.litl.sdk.event.AccelerometerEvent;
public class RemoteHandler extends AccelerometerRemoteHandler implements IRemoteHandler
{
public var xSpeed:Number = 0;
public var ySpeed:Number = 0;
public function RemoteHandler() {
super();
}
override protected function onAccelerometerEvent(event:AccelerometerEvent):void {
xSpeed -= event.accelerationX;
ySpeed += event.accelerationY;
}
}
}
Wrapping up
As you can see there are not too many differences between the two workflows. Check back soon as we'll be posting more advanced accelerometer development articles, tutorials, tips and tricks!
Managing Channel Properties on the litl OS
by @ryancanullaWhat are channel properties?
Channel properties allow the developer to take application data and put it in local system storage. This memory is limited, but can be very useful for channel configurations, user preferences, high scores, or something else that’s needed by your channel.
There are four types of channel properties. Each property type has a specific set of permissions. Permissions range from device specific to properties that are shared amongst different accounts/households/devices.
Below is a list of the litl OS channel properties:
- Global: generally read-only and tell the channel about the device/environment which they are running on
- Account: these properties will be included on all instances of your channel for one household account
- Device: properties that are only visible to one specific channel and only on the device it is installed/running on
- Shared: properties that are shared with any account/household that your channel is shared with
Storing properties locally
To store properties on your device simply set them on your LitlService instance; in this example that would be the service variable. Keep in mind that channel properties should be name value pairs.
Example:
service.addEventListener(PropertyMessage.PROPERTY_CHANGED, onPropertiesChanged);
Example:
service.sharedProperties.myProp = "some value"; service.accountProperties.anotherProp = "another value"; service.deviceProperties.thirdProp = "yet another";
Retrieving local properties from your channel
Listen for the “PROPERTY_CHANGED” event on your LitlService instance. Once you do that you will have everything you need inside of the event handler message.
In the event handler you will look for an Array of properties (e.parameters). Once you have that you can loop though this array to a) check for specific property names (ie. “Prop1”, “madeUpProperty”, or “zipCode”) or b) check what type of property type you are dealing with (ie. DEVICE, SHARED, ACCOUNT, or GLOBAL).
Example:
private function onPropertiesChanged(e:PropertyMessage):void {
var properties:Array = e.parameters;
for(var i:uint=0; i < properties.length; i++) {
if(properties[i].name == "zipCode" && e.propertyScope == PropertyScope.GLOBAL){
zipLabel.text = properties[i].value;
}
}
}
Note that it is important to match the properties that you are looking for with the property type that you expext it should be paired to.
if(properties[i].name == "username" && e.propertyScope == PropertyScope.DEVICE){
You can find a great example of working with channel properties in the ZipCode tutorial on the Sample Channels page:
Getting a user’s Location from a Channel
by @ryancanullaGeo-location is a hot feature, especially in the world of mobile apps. While our devices don't travel as much, there are still limitless possibilities when basing an app around a user's location.
The litl Channel SDK gives you access to a device user's zip code by way of two things: User properties and the Location capability. The latter is a privacy hook that, when accessed, notifies the user that this channel is accessing private information. We've put together a ready-to-run sample channel that shows you how to obtain the "zip code":
1. Download the "zip-code-sample-channel"
You can download the project archive from the sample channels section of http://developer.litl.com. This sample channel was created using Flash Builder as an ActionScript Project.
2. Import the project into Flash Builder.
3. Link the project to your as3-sdk-core library project.
Right Click on "zip-code-sample-channel">Properties>ActionScript Build Path>Add Project.
4. Open the simulator.
5. Grant the location capability to your channel in the simulator.
6. Run the channel.
What's going on here.
Basically we just listen for a PropertyMessage.PROPERTY_CHANGED event on our service and then pull the zip code from that event handler.
service.addEventListener(PropertyMessage.PROPERTY_CHANGED, onPropertiesChanged);
Inside of the handler we loop through an array of properties and check to find one called "zipCode". Once we find the zip code we then make sure that it's a global property. If both tests pass then we have the zip code available to us in two places. First, we can pull it from the array itself "properties[i].value". The second option available to use is to pull it directly from our service via the "service.zipCode" property.
private function onPropertiesChanged(e:PropertyMessage):void {
var properties:Array = e.parameters;
for(var i:uint=0; i < properties.length; i++) {
if(properties[i].name == "zipCode" && e.propertyScope == PropertyScope.GLOBAL){
zipLabel.text = properties[i].value;
/**
* an also be set like this
* zipLabel.text = service.zipCode;
*
*/
}
}
}
Here's the working code!
package {
import com.litl.sdk.enum.PropertyScope;
import com.litl.sdk.message.PropertyMessage;
import com.litl.sdk.service.LitlService;
import flash.display.Sprite;
import flash.text.TextField;
public class Main extends Sprite {
private var service:LitlService;
private var zipLabel:TextField;
public function Main() {
service = new LitlService(this);
service.addEventListener(PropertyMessage.PROPERTY_CHANGED, onPropertiesChanged);
service.connect("channel_id", "Zip Code Sample Channel", "v1.01");
createZipLabel();
}
private function onPropertiesChanged(e:PropertyMessage):void {
var properties:Array = e.parameters;
for(var i:uint=0; i < properties.length; i++) {
if(properties[i].name == "zipCode" && e.propertyScope == PropertyScope.GLOBAL){
zipLabel.text = properties[i].value;
/**
* an also be set like this
* zipLabel.text = service.zipCode;
*
*/
}
}
}
private function createZipLabel():void {
zipLabel = new TextField();
zipLabel.x = 50;
zipLabel.y = 50;
addChild(zipLabel);
}
}
}
This example also demonstrates how you would work with either ACCOUNT, DEVICE, GLOBAL, or SHARED properties. For additional support, please check our forums or contact us.
litl now accepting Channel Submissions
by @chuckstarYou can now submit Channels to be reviewed, published, and distributed to litl device users!
We have spent months designing and developing a process that, true to our brand, made it as simple as possible to publish and manage your Flash-based Channels. The process starts with a simple entry of your Channel name and description and includes what may be the most transparent app review process in the industry. Here is what you can do now:
1. Register your Channel name and idea
Whether you've started building your channel or even downloaded the SDK and Simulator, you can register your Channel now. All you need is a developer account and you can "Create a Channel." After you've signed into your developer account, simply click the "Channels" link on the left side navigation and hit the "Create a Channel" button. Fill out the easy form, including Channel name and description. This will let us know of your plans to soon build and publish the channel. While it won't prevent other developers from doing something similar, you can reserve the name and it does help us support you should the Channel idea get us excited!
2. Upload the Channel package and Images
Once you've registered your Channel name/idea, you can continue, or return to the site in the near future, and upload the Channel package. The package consists of your completed .swf file and a few other files you need to round out your Channel. This step also lets you upload screenshots of your Channel in action, which will eventually be featured in the listing of your Channel in our Channel store.
3. Submit your Channel for review
Lastly, you submit your channel to be reviewed by a member of our team. We'll evaluate your channel and make sure it meets checkpoints in our submission guidelines. We have implemented a very friendly and transparent process for giving you feedback on your channel, and should we find anything that needs further attention, you will receive a report card outlining exactly what we suggest you modify so we can get your Channel in the store as soon as possible.
Future features
In the coming months, we'll be implementing new features into our litl OS that support users purchasing Channels. These features will make their first into the Channel submission process, so you can ultimately set a price for your Channel and setup your account to receive payments from your Channel sales.




