Events

From NSB App Studio
Revision as of 22:02, 8 July 2012 by Brendon (talk | contribs)
Jump to navigation Jump to search

FUNCTION ObjectName_Event[(arglist)]

[statements]

END FUNCTION

Description

Events are triggered by actions in a control. They call functions defined in your app. The events described here are common to all controls. Events that are specific to certain controls are discussed in the documentation for that control.

The name of the procedure, ObjectName_Event, is a combination of the object name and the name of event.

When an event occurs, the event object is created with the following elements. Certain events have additional elements. The events object is global: it is also passed as an argument to event functions.


Table 9: Event Object Elements

Event Comments
altKey Was the "ALT" key pressed?
buttontypheight Returns which mouse button was clicked
clientX Horizontal coordinate of the mouse pointer
clientY Vertical coordinate of the mouse pointer
ctrlKey Was the "CTRL" key pressed?
identifier A unique number assigned to each event
metaKey Was the "meta" key pressed?
relatedTarget Returns the element related to the element that triggered the event
screenX Horizontal coordinate of the mouse pointer
screenY Vertical coordinate of the mouse pointer
shiftKey Was the "SHIFT" key pressed?
bubbles Returns whether event is a bubbling event
cancelable Can an event be cancelled?
currentTarget Returns element whose event listeners triggered the event
eventPhase Returns phase of the event flow
target Returns the element that triggered the event
timeStamp Returns the time stamp, in milliseconds
type Returns the name of the event

Note: If a program does not have a procedure to respond to an event when it is called, no error will occur.

Example

REM show scale and rotate with gesture
width = 100
height = 200
rotation = 0
 
Function imgMario_ongesturechange(e)
  node = e.target
  'scale and rotation are relative,
  'so change image when gesture ends
  node.width=(width * e.scale)& "px"
  node.height=(height * e.scale) &"px"
  node.style.webkitTransform="rotate(" & ((rotation+e.rotation) mod 360) & "deg)"
End Function
 
Function imgMario_ongestureend(e)
  'Update the values for next time
  width = width * e.scale
  height = height * e.scale
  rotation = (rotation + e.rotation) mod 360
End Function

Output

(try this on an iOS device)

Related Items

Methods, properties,Properties