Events: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
SUB ''ObjectName_Event''[(''arglist'')] <br />
FUNCTION ObjectName_Event[(''arglist'')] <br />
:[''Statements''] <br />
:::[''statements''] <br />
END SUB
END FUNCTION


'''Description'''
'''Description'''


Object events are triggered either programmatically or through user interaction. When an event is triggered, an object calls a SUB procedure in the program. The name of the procedure, ''ObjectName_Event'', is a combination of the object name and the name of event. The optional component, ''arglist'', is a comma-separated list of arguments that may be included in the procedure call by some events.  
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.


'''Table 9: Object Events'''
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'''


{| class="wikitable"
{| class="wikitable"
Line 13: Line 18:
! Event !! Comments
! Event !! Comments
|-
|-
| Change || ComboBox (item selected or text input), ListBox (item selected), TextBox (Text changed)
| altKey || Was the "ALT" key pressed?
|-
|-
| Click ||  
| buttontypheight || Returns which mouse button was clicked
|-
|-
| DblClick || ListBox, TextBox
| clientX || Horizontal coordinate of the mouse pointer
|-
|-
| DropDown || COmboBox, Date
| clientY || Vertical coordinate of the mouse pointer
|-
|-
| GotFocus || Object activated to receive keyboard input
| ctrlKey || Was the "CTRL" key pressed?
|-
|-
| Form_Hide || Generated code – do not modify
| identifier || A unique number assigned to each event
|-
|-
| Form_Load || Called from Form_Show
| metaKey || Was the "meta" key pressed?
|-
|-
| Form_Show || Generated code – do not modify
| relatedTarget || Returns the element related to the element that triggered the event
|-
|-
| Form_Unload || Called from Form_Hide
| screenX || Horizontal coordinate of the mouse pointer
|-
|-
| KeyDown || Keycode, shift as args
| screenY || Vertical coordinate of the mouse pointer
 
|-
Shift=1, 2-CTRL, 4=Alt
| shiftKey || Was the "SHIFT" key pressed?
|-
| bubbles || Returns whether event is a bubbling event
|-
|-
| KeyPress || Char as arg
| cancelable || Can an event be cancelled?
|-
|-
| KeyUp || Keycode, shift as args
| currentTarget || Returns element whose event listeners triggered the event
 
Shift=1, 2-CTRL, 4=Alt
|-
|-
| LostFocus || Object deactivated
| eventPhase || Returns phase of the event flow
|-
|-
| Output_Close || Called when app is closed
| target || Returns the element that triggered the event
|-
|-
| Output_Size || Called when output size is changed or screen rotated
| timeStamp || Returns the time stamp, in milliseconds
|-
|-
| Timer || CheckBox, ComboBox, CommandButton, Frame, HScrollBar, Label, ListBox, OptionButton, TextBox, VScrollBar
| 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.
Note: If a program does not have a procedure to respond to an event when it is called, no error will occur.
Line 54: Line 59:


<pre>
<pre>
REM Object Events Example
REM show scale and rotate with gesture
'Object Events call procedures in theprogram
width = 100
DIM When
height = 200
ADDOBJECT "ComboBox","Combo", 5, 30, 150, 80
rotation = 0
Combo.Style = 2
SUB Combo_DropDown
Function imgMario_ongesturechange(e)
   Combo.Clear
  node = e.target
   Combo.AddItem DATE
  'scale and rotation are relative,
   Combo.AddItem DATEADD("d", 1, DATE)
   'so change image when gesture ends
   Combo.AddItem DATEADD("ww", 1, DATE)
   node.width=(width * e.scale)& "px"
END SUB
   node.height=(height * e.scale) &"px"
SUB Combo_Click
   node.style.webkitTransform="rotate(" & ((rotation+e.rotation) mod 360) & "deg)"
   When = Combo.Text
End Function
   PRINT "Item selected: " & When
END SUB
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
</pre>
</pre>


Line 74: Line 84:


<pre>
<pre>
*
(try this on an iOS device)
</pre>
</pre>



Revision as of 22:02, 8 July 2012

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