Contents
Articles
Behaviors
Books
Director News
Director Web Sites
FAQ
Games
Mailing Lists
News Groups
Project Examples
Reviews
Software
Tools
Useful Web Sites
Utilities
Xtras

Don't miss these
Make URL Shortcut
Hold for X seconds if no input is given
cXtraDateTimePicker
MP3 Cross Fader
Version
Rollover Ink Change
cXtraGraphicIO
playheadSlider
SQLite Xtra
Authoring Authorware
 

 

 

Article Dialogs - Tell Me Something

Added on 8/2/1999

 

Compatibilities:
D7 D8 Mac PC

This item has not yet been rated

Author: MediaMacros (website)

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.

global box, valueList
on createDialog whatTitle, whatPrompt, defaultText , handler
  box = new(xtra "MUI")
  valueList = [#nameField : defaultText]
  boxProp = getWindowPropList(box)
  boxProp[#name] = whatTitle
  boxProp[#callback] = "boxcallback"
  boxProp[#xPosition] = -1
  boxProp[#yPosition] = -1
  boxProp[#width] = 0
  boxProp[#height] = 0
  boxProp[#mode] = #data
  --define the elements
  windowStart = [#value : 0, #type : #windowBegin, #attributes : [], #title : "", #tip : "", #width : 0, #height : 0, #enabled : 1]
  groupHValStart = [#value : 0, #type : #groupHBegin, #attributes : [#centerH], #title : "", #tip : "", #width : 0, #height : 0, #enabled : 1]
  groupHValEnd = [#value : 0, #type : #groupHEnd, #attributes : [], #title : "", #tip : "", #width : 0, #height : 0, #enabled : 1]
  nameLabel = [#value : WhatPrompt, #type : #label, #attributes : [], #title : "Input", #tip : "", #width : 0, #height : 0, #enabled : 1]
  nameField = [#value : valueList[#nameField], #type : #editText, #attributes : [], #title : "NameField", #tip : "tip", #locH : 20, #locV : 24, #width : 200, #height : 210, #enabled : 1]
  okButton = [#type : #pushButton, #attributes : [], #title : "OK", #tip : "OK", #width : 60, #height : 0, #enabled : true]
  cancelButton = [#type : #pushButton, #attributes : [], #title : "Cancel", #tip : "Cancel", #width : 0, #height : 0, #enabled : true]
  windowEnd = [#value : 0, #type : #windowEnd, #attributes : [], #title : "", #tip : "", #width : 0, #height : 0, #enabled : 1]
  --create the box's paramater list
  contentList = [windowStart, nameLabel, nameField, groupHValStart, okButton, cancelButton, grouphValEnd, windowEnd]
  --initialize the box
  Initialize(box, [#windowPropList : boxProp, #windowItemList : contentList])
  --run the box
  test = run(box)
  do(handler & "(valueList)")
end

on boxCallback event, eventData, itemPropList, thisPropList
  case event of
    #itemChanged :
      case itemPropList[#title] of
        "NameField" :
            valueList[#nameField] = itemPropList[#value]
      end case
    #itemClicked:
      case itemPropList[#title] of
        "OK":
            stop(box, 1)
            return valueList
        "Cancel" :
            stop(box, 0)
      end case
  end case
end

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."
end


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"])
  return p_list
end

on mouseUp me
  createDialog(whatTitle, whatPrompt, defaultText , handler)
end


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.

 


Contact

MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA

Send e-mail