|
|
(15 intermediate revisions by 4 users not shown) |
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. |
| | |
| | |
| | '''Event Object Elements''' |
|
| |
|
| {| class="wikitable" | | {| class="wikitable" |
| |- | | |- |
| ! Event !! Comments | | ! Element !! Comments |
| | |- |
| | | altKey || Was the "ALT" key pressed? |
| | |- |
| | | button || 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? |
| |- | | |- |
| | Change || ComboBox (item selected or text input), ListBox (item selected), TextBox (Text changed) | | | relatedTarget || Returns the element related to the element that triggered the event |
| |- | | |- |
| | Click || | | | screenX || Horizontal coordinate of the mouse pointer |
| |- | | |- |
| | DblClick || ListBox, TextBox | | | screenY || Vertical coordinate of the mouse pointer |
| |- | | |- |
| | DropDown || COmboBox, Date | | | shiftKey || Was the "SHIFT" key pressed? |
| |- | | |- |
| | GotFocus || Object activated to receive keyboard input | | | bubbles || Returns whether event is a bubbling event |
| |- | | |- |
| | Form_Hide || Generated code – do not modify | | | cancelable || Can an event be cancelled? |
| |- | | |- |
| | Form_Load || Called from Form_Show | | | currentTarget || Returns element whose event listeners triggered the event |
| |- | | |- |
| | Form_Show || Generated code – do not modify | | | eventPhase || Returns phase of the event flow |
| |- | | |- |
| | Form_Unload || Called from Form_Hide | | | target || Returns the element that triggered the event |
| |- | | |- |
| | KeyDown || Keycode, shift as args | | | timeStamp || Returns the time stamp, in milliseconds |
| | |- |
| | | type || Returns the name of the event |
| | |} |
|
| |
|
| Shift=1, 2-CTRL, 4=Alt
| | Here are some of the events that can occur: |
| | |
| | '''Events''' |
| | |
| | {| class="wikitable" |
| | |- |
| | ! Event !! Comment |
| | |- |
| | | onblur || When a control loses focus. |
| | |- |
| | | onclick || When a control is clicked on. Not as quick as ontouchstart. Also, on a device with an on screen keyboard, this event opens the keyboard in a Textbox. |
| | |- |
| | | ondeviceorientation || When the device is rotated to face in a different direction. |
| | |- |
| | | onfocus || When a control receives focus. |
| | |- |
| | | onfocusin || When a control receives focus. |
| | |- |
| | | onfocusout || When a control loses focus. |
| | |- |
| | | ongesturechange || When the gesture is changed. Additional Event Object Elements are scale, which is the result of a pinch, and rotation, which is the result changing the angle of the fingers. (iOS only) |
| | |- |
| | | ongestureend || Like ongesturechange, scale and rotation are set. (iOS only) |
| | |- |
| | | ongesturestart || When two fingers touch the screen. (iOS only) |
| | |- |
| | | onmousedown || When contact is made. |
| | |- |
| | | onmousemove || When contact is moved in the control. |
| | |- |
| | | onmouseout || When contact leaves the control. |
| |- | | |- |
| | KeyPress || Char as arg | | | onmouseup || When contact is removed. |
| |- | | |- |
| | KeyUp || Keycode, shift as args | | | onorientationchange || When the device is changed between portrait and landscape. |
| | | |- |
| Shift=1, 2-CTRL, 4=Alt
| | | onresize || When a control is resized. |
| |- | | |- |
| | LostFocus || Object deactivated | | | ontouchstart || When a control is touched. |
| |- | | |- |
| | Output_Close || Called when app is closed | | | ontouchend || When a control is no longer touched. |
| |- | | |- |
| | Output_Size || Called when output size is changed or screen rotated | | | ontouchmove || When a touch moves. Element touches[0] has positioning elements for first finger, [1] for the second. The touches element has elements to describe the touch: touches[0].clientX has the x position of the touch. |
| |- | | |- |
| | Timer || CheckBox, ComboBox, CommandButton, Frame, HScrollBar, Label, ListBox, OptionButton, TextBox, VScrollBar | | | onvisibilitychange || When the user switches to a different app or browser page. |
| |} | | |} |
| Note: If a program does not have a procedure to respond to an event when it is called, no error will occur.
| |
|
| |
|
| '''Example'''
| | == Example == |
|
| |
|
| <pre> | | <tabber> |
| REM Object Events Example
| | JavaScript= |
| 'Object Events call procedures in theprogram
| | <syntaxhighlight lang="JavaScript"> |
| DIM When
| | // show scale and rotate with gesture |
| ADDOBJECT "ComboBox","Combo", 5, 30, 150, 80
| | |
| Combo.Style = 2
| | width = 100; |
| SUB Combo_DropDown
| | height = 200; |
| Combo.Clear | | rotation = 0; |
| Combo.AddItem DATE | | |
| Combo.AddItem DATEADD("d", 1, DATE) | | imgMario.ongesturechange = function(e) { |
| Combo.AddItem DATEADD("ww", 1, DATE) | | node = e.target; |
| END SUB
| | //scale and rotation are relative, |
| SUB Combo_Click
| | //so change image when gesture ends |
| When = Combo.Text | | node.width=(width * e.scale) + "px"; |
| PRINT "Item selected: " & When | | node.height=(height * e.scale) + "px"; |
| END SUB
| | node.style.webkitTransform="rotate(" + ((rotation+e.rotation*1)%360) + "deg)"; |
| </pre> | | } |
| | |
| | imgMario.ongestureend = function(e) { |
| | //Update the values for next time |
| | width = width * e.scale; |
| | height = height * e.scale; |
| | rotation = (rotation + e.rotation*1)%360; |
| | } |
| | </syntaxhighlight> |
| | |-| |
| | BASIC= |
| | <syntaxhighlight lang="vb.net"> |
| | 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 |
| | </syntaxhighlight> |
| | </tabber> |
|
| |
|
| '''Output'''
| | == Output == |
|
| |
|
| <pre> | | <pre> |
| *
| | (try this on an iOS device) |
| </pre> | | </pre> |
|
| |
|
| '''Related Items'''
| | == Related Items == |
| | |
| | [[properties and methods|Properties and Methods]] |
|
| |
|
| [[methods|Methods]], [[properties,Properties]] | | [[Category:Language Reference]] |
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.
Event Object Elements
Element |
Comments
|
altKey |
Was the "ALT" key pressed?
|
button |
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
|
Here are some of the events that can occur:
Events
Event |
Comment
|
onblur |
When a control loses focus.
|
onclick |
When a control is clicked on. Not as quick as ontouchstart. Also, on a device with an on screen keyboard, this event opens the keyboard in a Textbox.
|
ondeviceorientation |
When the device is rotated to face in a different direction.
|
onfocus |
When a control receives focus.
|
onfocusin |
When a control receives focus.
|
onfocusout |
When a control loses focus.
|
ongesturechange |
When the gesture is changed. Additional Event Object Elements are scale, which is the result of a pinch, and rotation, which is the result changing the angle of the fingers. (iOS only)
|
ongestureend |
Like ongesturechange, scale and rotation are set. (iOS only)
|
ongesturestart |
When two fingers touch the screen. (iOS only)
|
onmousedown |
When contact is made.
|
onmousemove |
When contact is moved in the control.
|
onmouseout |
When contact leaves the control.
|
onmouseup |
When contact is removed.
|
onorientationchange |
When the device is changed between portrait and landscape.
|
onresize |
When a control is resized.
|
ontouchstart |
When a control is touched.
|
ontouchend |
When a control is no longer touched.
|
ontouchmove |
When a touch moves. Element touches[0] has positioning elements for first finger, [1] for the second. The touches element has elements to describe the touch: touches[0].clientX has the x position of the touch.
|
onvisibilitychange |
When the user switches to a different app or browser page.
|
Example
// show scale and rotate with gesture
width = 100;
height = 200;
rotation = 0;
imgMario.ongesturechange = function(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*1)%360) + "deg)";
}
imgMario.ongestureend = function(e) {
//Update the values for next time
width = width * e.scale;
height = height * e.scale;
rotation = (rotation + e.rotation*1)%360;
}
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
Properties and Methods