I have used dialog boxes in the past for alerts, save dialogs, and basic Ok/Cancel questions, but how do I get a box where a user can input data such as their name or password?
First off, you are going to need an Xtra here. Luckily it comes with Director. If you have ever looked at the MUI Xtra, you probably know it has a lot of potential, but it can be very overwhelming for a new user. If you want to read up on the MUI Xtra and all it can do for you, start with the downloadable documentation from Macromedia. This will give you a base overview of what needs to be defined for a dialog box and how to add elements and return their values.
One of the big errors many people make when first using the MUI Xtra is that they expect it to respond like any other dialog box. If you run a fileSaveAsDialog using the fileXtra, the command returns the name of the file. Not so with the MUI Xtra's custom dialogs. Since the Xtra allows for numerous parameters; you have to create a callback handler to receive any change in the box and save them in a global variable. An easy approach is to first set all of the initial values, run the dialog box, and then allow the callback handler to change the values whenever input is given or a button is pressed, etc. For this example we will need to utilize 4 "items" and 4 other elements. The items are an input field, a description of what to input in the field, an ok button , and a cancel button. The other elements are an item to begin the window, one to begin a horizontal group, one to end the group, and one to signify the end of the windows items. This may should like a lot for one input field, but it isn't too bad once you understand the base properties.
First off we need to define our global variables. We need one to store an instance of the Xtra for the box, and a second for the global list containing the values in the box. After we create the instance of the box we then create a list of parameters for the box itself. This is accomplished through the getWindowPropList function to get the default values, then modified as needed. Once that is done we create a property list for each item in the box and store the lists in one large linear list that is used to initialize the box. Once all the parameters are set we simply run the box and all input will be passed to the predefined callback handler. The callback handler takes the data, modifies the global variable, and runs commands for buttons, etc.
Sounds like a lot? Well it can be at first, but once the structure is down it isn't too bad to change. Below is the basic code for our box. There are 4 parameters that are passed to the box. A title for the box, the prompt instructions in the box, the default value for the prompt, and the handler used with the returned data.
on boxCallback event, eventData, itemPropList, thisPropList
case event of
case itemPropList[#title] of
valueList[#nameField] = itemPropList[#value]
case itemPropList[#title] of
on getBehaviorDescription me
return "This script accepts input for the boxes title(whatTitle), the question or prompt on the box(whatPrompt), the default string for the answer(defaultText) , and the name of a handler to use with the returned list(handler). The first 3 are any string you want to use. For the handler, put the name of the handler without the (), or -- for no handler."
If you follow the script from top to bottom, we generate the properties for the box, then define the properties for each object. The objects are added to the list and the box is initialized and run. Each time the user inputs data or clicks a button the callback handler checks to see what to do with the input. If the "OK" button is clicked it returns the data and the handler is run. If the user clicks cancel then the handler is run with the default data.
What if we want a button to do this? Simple enough. We just create a behavior to assigne the correct paramaters and then send the call for the dialog like so...
property whatTitle, whatPrompt, spriteNum, handler, defaultText
on getPropertyDescriptionList me
p_list = 
p_list.addProp(#whatTitle, [#format : #string, #default : "Enter your password.", #comment : "Dialog Title"])
p_list.addProp(#whatPrompt, [#format : #string, #default : "Please Enter your password.", #comment : "Dialog instructions"])
p_list.addProp(#defaultText, [#format : #string, #default : "Password", #comment : "Default Answer"])
p_list.addProp(#handler, [#format : #string, #comment : "handler to run with returned list.", #default : "--something"])
on mouseUp me
createDialog(whatTitle, whatPrompt, defaultText , handler)
What else can you do with this. Add check boxes, lock the ok button until the data is changed, create drop down menus, and more. This Xtra gives you full control of dialogs, so be creative and play with it. With a little practice you won't ever have to use those boring alerts again.
36 South Court Sq
Newnan, GA 30263