GUI Events Reference
OnClick
This event only applies to FlexSim registered controls. It is fired when the user clicks anywhere inside of the control. This includes when the user clicks the mouse and when the user releases the mouse. There are two access variables for this event:
- "c" is a reference to the control node.
- "i" is a click code: 2 means left mouse button down, 3 means left up, 4 means right down, 5 means right up, and 1 means double-click.
Some commands that you might use within the OnClick are: cursorinfo() or selectedobject().
OnClose
This event contains text data with flexscript code that will be executed when the window is closed.
OnDrag
This event allows you to execute code when an object is dragged from the icongrid onto another view. The event should have text data with flexscript code. Within the function, c gets access to the icongrid, i gets access to the view on which it was dropped, dropx(), dropy(), and dropz() get the drop location if the view is a ortho, perpective, or planar view. dropnodefrom() gets access to the object that was dragged, and dropnodeto() gets access to the object it was dropped onto if one exists. Please note that if no OnDrag event exists, then a copy of the object will be made in the dropped view's focus or in the dropnodeto() if it exists.
OnDraw
This event is fired when the window is drawn. This occurs frequently during a simulation, such as when the window is resized, the model is running, or you click on the window.
OnDrop
This event only applies to FlexSim registered controls. It is fired when the user drags an object from an icon grid and drops it on the view. The attribute should have text data containing flexscript code that fires when the object is dropped. Within the function, you have access to the object that was dragged with dropnodefrom(), and the object that it was dropped onto with dropnodeto().
OnKeyDown
This event only applies to FlexSim registered controls. It is fired when the control has keyboard focus and the user presses a key on the keyboard. There is one access variable, namely c, which is a reference to the control node. You can also query what key went down using lastkeydown(), or query whether any key is down with iskeydown().
OnKeyUp
This event only applies to FlexSim registered controls. It is fired when the control has keyboard focus and the user presses a key on the keyboard. There is one access variable, namely c, which is a reference to the control node. You can also query what key went down using lastkeydown(), or query whether any key is down with iskeydown().
OnKillFocus
This event is fired when the window that the event is applied to loses keyboard focus meaning that you from being able to type in the window to not being able to type in the window because you have clicked on a different window.
OnMenuPopup
This event is executed after the menu is created but before it draws the menu so that you can check or gray out menu items using the commands menucheck() or menugray().
OnMouseButtonDown
This event only applies to FlexSim registered controls. It is fired when the user presses the left mouse button in the view. There is one access variable, namely c, which is a reference to the control node.
OnMouseButtonUp
This event only applies to FlexSim registered controls. It is fired when the user releases the left mouse button in the view. There is one access variable, namely c, which is a reference to the control node.
OnMouseWheel
This event only applies to FlexSim registered controls. It is fired when the control has keyboard focus and the user scrolls the mouse wheel. The control also needs to have an OnMouseWheelDelta event with number data. When the user scrolls the mouse wheel, FlexSim will set the value of the OnMouseWheelDelta value according to how much the user has scrolled, and then will call the OnMouseWheel function. Within the function, c accesses the OnMouseWheel event itself.
OnMouseWheelDelta
This event is used as described in the OnMouseWheel event above.
OnOpen
This event allows you to specify flexscript functionality that will fire when the window is opened. It is fired when the window is initially opened, as well as when the window is restored after a compile, as well as when the window is "redirected" to point to a new object if the user switches the window to point to another object. You may use this trigger to initialize settings in controls that may not have a coldlink.
OnPreDraw
Executed before an OnDraw event. See OnDraw for more information.
OnPreOpen
This event allows you to execute functionality before the window is created. The OnPreOpen is fired after the tree structure for the window is created, but before the window itself is initialized. Unlike OnOpen, it is not executed after a compile or when the window is redirected. You could use the OnPreOpen to modify the structure of the window before it is opened, such as adding or removing tab windows, or adding or removing any controls from the tree structure of the window.
OnPress
The OnPress event specifies code that will be executed when the button is pressed. It should have text data containing flexscript code. Within the code, c accesses the button view.
OnSelect
The OnSelect event is a trigger that fires when the user selects an option in the combobox, the user drags the locator of a tracker to a given position, or when a tab page is selected for a tabcontrol. The event should have text data with flexscript code specifying what to do when the user selects the option. Within this trigger you will want to access the value of the itemcurrent attribute to find out which option the user selected. For the Tracker, within the function, c will access the tracker control while for the Tabcontrol c accesses the tabcontrol view. For a tabcontrol, use get(itemcurrent(c)) to get the currently selected page.
OnSize
This event is executed when the window gets re-sized.
OnStick
This event is executed on joystick or 3D mouse events (moving the joystick or pressing buttons on the joystick or 3D mouse).
Not Recommended Events
The following events are not recommended, but may still work.
OnActivateNotify
Executed when you change the active window. This event may only work on palette windows. An example of this event can be found in the Tree Navigation window. When a 3D view is selected with the Tree Navigation window open, options in the Tree Navigation window are grayed out. However, when a tree window is selected, those options become active (un-grayed) again.
OnDropfile
Executed when a file is dragged on top of the window and then dropped onto it.
OnDropNode
This event should contain text data and defines flexscript code that will be executed when the user holds a key down while click-dragging from one object drawn in the view to another.
OnListen
Executed on any event happening: after dispatch, when event has been removed. To set up listening, you add a "listeners" attribute to the object you want to listen to (Object A). This listeners attribute should have subnodes that are couplings to the object(s) that you want to listen from (Object B). Before an event fires on Object A, Object B's OnPreListen event function will fire. After an event first on Object A, Object B's OnListen event function will fire. You can also filter events by adding a subnode with number data below Object B's coupling node. The number data should be a bitwise sum of the bitshifted event codes you want to listen for. If the coupling has no subnode, the object will default to listening to every event. To help you with the OnPreListen and Onlisten event functions, you may consider using the listenerinfo(int info) command. The information returned is information that was passed to the event you are listening to. Info 1 will return the engine event code. Engine event codes have macros such as SM_MESSAGE and SM_DRAW. Info 2 and 3 return pointers to associated.
OnMessage
Executed when the GUI object receives a message that was sent from another object in the model.
OnPreListen
Executed on any event happening: before dispatch, when event is still in list. Refer to OnListen for a more detailed description.
OnTimerEvent
Executed on timer event. Executed on an event that was created with createevent(). This occurs in numerous objects, one example is the Processor finishing its process.
OnUndo
Executed on content-defined undo action. When you call the createundorecord(.,.,UNDO_CUSTOM); command you create a document that records the most recent changes that were made to the model. Then when you undo something (Ctrl z) you can use the OnUndo event to reference that information and undo what was done or perform some other function.