Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
CHAPTER 4 Exploring the APIs Now that you know how to create a new application in your choice of layout options and know how to request application permissions, it is time to explore the ways in which your application can interact with the iOS operating system. The AIR 2.7 release includes access to many iOS features. These include the accelerometer, the GPS unit, the camera, the camera roll, the file system, and the multitouch screen. Accelerometer The accelerometer is a device that measures the speed or g-forces created when a device accelerates across multiple planes. The faster the device is moved through space, the higher the readings will be across the x, y, and z axes. Let's review the code below. First, you will notice there is a private variable named accelerometer declared of type flash.sensors.Accelerometer . Within application Complete of the application, an event handler function is called, which first checks to see whether the device has an accelerometer by reading the static property of the Accelerometer class. If this property returns as true, a new instance of Accelerometer is created and an event listener of type AccelerometerEvent.UPDATE is added to handle updates. Upon update, the accelerometer information is read from the event and writ- ten to a TextArea within the handleUpdate function. The results can be seen within Figure 4-1: 47