Creating a prompt dialog

How to

Create a prompt dialog box in your application.

Solution

Construct the prompt dialog box variable in the root of your class

var myPrompt:PromptDialog = new PromptDialog();
// Placing this at the class root allows other 
// application elements to reference it.

Initialize the attributes of your dialog box

// Set title and body text.
myPrompt.title = "User Creation";
myPrompt.message = "Please enter your name:";

// Add buttons.
myPrompt.addButton("Cancel");
myPrompt.addButton("OK");

// Set user prompt placeholder text.
myPrompt.prompt = "Your name here";

// Add a listener for user clicking on a button.
myPrompt.addEventListener(Event.SELECT, promptButtonClicked);

Add the call to display your dialog box where desired

// In this sample it is fine to simply place this call 
// once right after setup to display one time on launch.
myPrompt.show();

Create the function that is called by your dialog box's button selection event

private function promptButtonClicked(event:Event):void{
	// Output index of clicked button.
	trace("Button Clicked Index: " + myPrompt.selectedIndex);

	// If first button was selected.
	if (myPrompt.selectedIndex == 1){
		// Output user input text.
		trace("Welcome "+ myPrompt.text);
	}
}

Build Requirements

You must include the following classes in your project:

import qnx.fuse.ui.dialog.PromptDialog;
import flash.events.Event;

Discussion

When you create a prompt dialog, you create your PromptDialogobject, initialize its properties to whatever values your application requires, and finally call the show() function when you want to display the dialog. To add functionality, add an Event.SELECT listener function to perform any actions that are defined in the function when one of the buttons is selected. You can also reference which of your dialog's buttons was chosen by the user anywhere in the class by using the selectedIndex property, while the text property will return the text that was input into the prompt field by the user.