Type Function Library native.* Return value Object Revision Release 2022.3683 Keywords alert, native alert, alert popup See also native.cancelAlert()
Displays a popup alert box with one or more buttons, using a native alert control. Program activity, including animation, will continue in the background, but all other user interactivity will be blocked until the user selects a button or cancels the dialog.
Native alerts are not part of the OpenGL canvas and do not obey the display object hierarchy, so they will always appear in front of normal display objects including images, text, and vector objects.
Some platforms will not allow multiple alerts. If you have an alert pending and call another alert, the second alert may not show or trigger the alert listener.
native.showAlert( title, message [, buttonLabels [, listener] ] )
String. The title string displayed in the alert.
String. Message string displayed in the alert text.
Listener. The listener function to be called when a user presses any button in the alert box. It can assign an action to each button according to its numerical index: the first button is index 1, the second is index 2, and so on. The listener can be either a function listener or a table listener and the event dispatched to the listener will have the following additional properties:
event.action
represents how the alert was dismissed: "cancelled"
indicates that native.cancelAlert() was called to close the alert, while "clicked"
indicates that the user clicked on a button to close the alert.event.index
is the index of the button pressed. It corresponds to the index in the buttonLabels
parameter.-- Handler that gets notified when the alert closes local function onComplete( event ) if ( event.action == "clicked" ) then local i = event.index if ( i == 1 ) then -- Do nothing; dialog will simply dismiss elseif ( i == 2 ) then -- Open URL if "Learn More" (second button) was clicked system.openURL( "https://solar2d.com/" ) end end end -- Show alert with two buttons local alert = native.showAlert( "Solar2D", "Dream. Build. Ship.", { "OK", "Learn More" }, onComplete )