cfclient.accelerometer.watch

Watching for change in position

You can get the acceleration data (X, Y, and Z) at regular intervals by watching for the change in device position.

Method summary

 

watch(callback, [options])

  • returns – watchID - String
  • params
    • callback – Function that will be called whenever there is a change in location
    • Options object (Optional)

For instance,

 <cfset watchId=cfclient.accelerometer.watch(callbackfunc)>

The returned watch ID references the accelerometer's watch interval, and can be used with accelerometer.clearWatch to stop watching the accelerometer.

 <cffunction access="public" name="callbackfunc" returntype="void" >
<cfargument name="acceleration">
<!--- Call back function code --->
<cfset writeOutput("acceleration changed X-" & obj.x & " Y-" & obj.y & " Z-" & obj.z & " Timestamp -" &obj.timestamp )><br/>
</cffunction>

The callback function passed to the watch function will be invoked based on the frequency provided in the options object. The callback function will receive an argument 'acceleration' with the following properties:

  • x - Amount of acceleration on the x-axis
  • y - Amount of acceleration on the x-axis
  • z - Amount of acceleration on the z-axis
  • timestamp - The creation timestamp in milliseconds

The 'acceleration' object has the accelerometer data captured at a specific time.

The Options object

The Options object contains the following parameter:

  • frequency – The time delay for invoking the callback function to obtain the Accelerometer data (in milliseconds)

Example

See Using the Accelerometer APIs

 Adobe

Get help faster and easier

New user?