When a user selects an HTML element in a Dreamweaver document and clicks the Plus (+) button on the Behaviors panel, the following events occur:

  1. Dreamweaver calls the canAcceptBehavior() function in each Action file to see whether this action is appropriate for the document or the selected element.

    If the return value of this function is false, Dreamweaver dims the action in the Actions pop-up menu. (For example, the Control Shockwave action is dimmed when the user’s document has no SWF files.) If the return value is a list of events, Dreamweaver compares each event with the valid events for the currently selected HTML element and target browser until it finds a match. Dreamweaver populates the Events pop-up menu with the matched event from the canAcceptBehavior() function at the top of the list. If no match exists, the default event for the HTML element (marked in the Event file with an asterisk [*]) becomes the top item. The remaining events in the menu are assembled from the Event file.

  2. The user selects an action from the Actions pop-up menu.

  3. Dreamweaver calls the windowDimensions() function to determine the size of the Parameters dialog box. If the windowDimensions() function is not defined, the size is determined automatically.

    A dialog box always appears, with OK and Cancel buttons at the right edge, regardless of the contents of the body element.

  4. Dreamweaver displays a dialog box that contains the BODY elements of the Action file. If the Action file’s body tag contains an onLoad handler, Dreamweaver executes it.

  5. The user fills in the parameters for the action. Dreamweaver executes event handlers that are associated with the form fields as the user encounters them.

  6. The user clicks OK.

  7. Dreamweaver calls the behaviorFunction() and applyBehavior() functions in the selected Action file. These functions return strings that are inserted into the user’s document.

  8. If the user later double-clicks the action in the Actions column, Dreamweaver reopens the Parameters dialog box and executes the onLoad handler. Dreamweaver then calls the inspectBehavior() function in the selected Action file, which fills in the fields with the data that the user previously entered.

Inserting multiple functions in the user’s file

Actions can insert multiple functions—the main behavior function plus any number of helper functions—into the head section. Two or more behaviors can even share helper functions as long as the function definition is exactly the same in each Action file. One way of ensuring that shared functions are identical is to store each helper function in an external JavaScript file and insert it into the appropriate Action files using <SCRIPT SRC="externalFile.js">.

When the user deletes a behavior, Dreamweaver attempts to remove any unused helper functions that are associated with the behavior. If other behaviors are using a helper function, it is not deleted. Because the algorithm for deleting helper functions errs on the side of caution, Dreamweaver might occasionally leave an unused function in the user’s document.

Handling actions that require return value

Sometimes an event handler must have a return value (for example, onMouseOver="window.status='This is a link'; return true"). But if Dreamweaver inserts the "return behaviorName(args)" action into the event handler, behaviors later in the list are skipped.

To get around this limitation, set the document.MM_returnValue variable to the desired return value within the string that the behaviorFunction() function returns. This setting causes Dreamweaver to insert return document.MM_returnValue at the end of the list of actions in the event handler. For an example that uses the MM_returnValue variable, see the Validate Form.js file in the Configuration/Behaviors/Actions folder within the Dreamweaver application folder.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy