BindEvent(Event, @Callback() [, Window [, Object [, EventType]]])Description
Bind an event to a callback. It's the way to handle events in SpiderBasic. An event can be unbound with UnbindEvent().
Event The event to bind. Custom events are also supported, when using PostEvent(). Possible Events are:#PB_Event_Menu : a menu has been selected #PB_Event_Gadget : a gadget has been pushed #PB_Event_Timer : a timer has reached its timeout #PB_Event_CloseWindow : the window close gadget has been pushed #PB_Event_SizeWindow : the window has been resized #PB_Event_MoveWindow : the window has been moved #PB_Event_ActivateWindow : the window has been activated (got the focus) #PB_Event_DeactivateWindow: the window has been deactivated (lost the focus) #PB_Event_RightClick : a right mouse button click has occurred on the window. This can be useful to display a popup menu #PB_Event_LeftClick : a left mouse button click has occurred on the window #PB_Event_LeftDoubleClick : a left mouse button double-click has occurred on the window #PB_Event_Loading : a new item has been loaded. It needs a specific event callback, see below for more information. #PB_Event_LoadingError : an error occured when loading an item. It needs a specific event callback, see below for more information. #PB_Event_RenderFrame : a new frame is ready to be rendered. FlipBuffers() has to be called to trigger this event. #PB_Event_SizeDesktop : the deskop has been resized. For example, it can be the browser window which has been resized, or the device orientation which has been changed. @Callback() The callback procedure to call when the event occurs. It has to be declared like this:Procedure EventHandler() ; Code EndProcedureRegular functions like EventGadget(), EventWindow(), EventMenu(), EventType() and EventData() are available within the callback to get more information about the event.
If the event is #PB_Event_Loading or #PB_Event_LoadingError, the callback has to be declared like this:Procedure EventLoading(Type, Filename$, ObjectId) ; Code EndProcedureThe 'type' argument will be one of the following value:#PB_Loading_Image : The item is an image loaded with @loadimage() #PB_Loading_Sound : The item is a sound loaded with @loadsound() #PB_Loading_Sprite: The item is a sprite loaded with @loadsprite() #PB_Loading_Xml : The item is a XML object loaded with @loadxml() #PB_Loading_JSON : The item is a JSON object loaded with @loadjson()The 'Filename$' argument will be the original filename as specified in the load command. The 'ObjectId' argument is the object number, as specified in the load command.
Window (optional) The #Window number to bind the event to. The event will be dispatched only when occurring on this window. #PB_All can be specified to bind the event to all windows. Object (optional) The object number to bind the event to. It can be a gadget or menuitem number. #PB_All can be used to bind the event to any objects. EventType (optional) The event type to bind the event to. For a full list of supported type, see EventType(). #PB_All can be used to bind the event to any type.
Procedure SizeWindowHandler() Debug "Size event on window #" + EventWindow() EndProcedure OpenWindow(0, 100, 100, 200, 200, "Resize test", #PB_Window_SizeGadget | #PB_Window_SystemMenu) BindEvent(#PB_Event_SizeWindow, @SizeWindowHandler())
BindGadgetEvent(), BindMenuEvent(), UnbindEvent()