- Introduction
- Becoming an Apple Certified Developer
- Registering an iPhone and Other Apple Testing Devices
- Creating App IDs
- Creating a Developers Provisioning Profiles
- Creating and Publishing an iPhone App
- Controlling the Accelerometer
- Saving Images to the Camera Roll
- Understanding the Limits of Flash
- Identifying Devices to Deploy an Ad Hoc App
- Creating an Ad Hoc Distribution Profile
- Packaging an Ad Hoc App
- Packaging an App for the iTunes App Store
- Using iTunes Connect to Publish an App
- Using Screen Orientation in an App
- Using Geolocation in an App
- Using Multitouch in an App
Controlling the Accelerometer
With the release of the Flash Player 10.1 and Adobe Integrated Runtime, AIR 2.0, the Flash team added several new core API features (New!). Access to a devices Accelerometer is one of those. The role of the Accelerometer is to detect when you move your phone. The Accelerometer is a listener that is triggered when it is used. The following example adds an Accelerometer listener to your iPhone App.
Add an Accelerometer Listener
- Create a new iPhone App and add the necessary development properties in the iPhone settings.
- Add a dynamic text field to the Stage with the name myTextField in the Properties panel.
- Create a new layer on the Timeline with the named Actions, and then select the Actions layer.
- Open the Actions panel.
- Add code to import the libraries for the Accelerometer to work correctly:
import flash.events.AccelerometerEvent import flash.sensors.Accelerometer;
- Add code to create a new Accelerometer object:
var acc1:Accelerometer = new Accelerometer()
- Add a boolean object to test if the Accelerometer works or not:
var isSupported:Boolean = Accelerometer.isSupported; checksupport();
- Add a function that contains the event listener, which waits for the Accelerometer to be triggered:
function checksupport():void { if (isSupported) { myTextField.text = "Accelerometer feature supported"; acc1.addEventListener (AccelerometerEvent.UPDATE, updateHandler); } else { myTextField.text = "howdy "; } }
- Add a function that posts a message to the text field to tell what direction the device has moved to:
function updateHandler(evt:AccelerometerEvent):void { myTextField.text = String("at: " + evt.timestamp + "\n" + "acceleration X: " + evt.accelerationX + "\n" + "acceleration Y: " + evt.accelerationY + "\n" + "acceleration Z: " + evt.accelerationZ);
- Publish and package your file into an iPhone App and test it on your iPhone.
The Accelerometer gives you new ways for your customers to interface with your applications beyond touchscreen controls. The Accelerometer works great on the iPhone but the same code can be used for Adobe AIR apps running on Google’s Android OS, Palm’s WebOS and RIM’s BlackBerry phones. Yes, that’s right. Develop one App and have it deployed to multiple mobile devices.