
Using Behaviors
453
Gathering information about the draggable layer
When you attach the Drag Layer action to an object, Dreamweaver inserts the
MM_dragLayer()
function into the
head
section of your document. In addition
to registering the layer as draggable, this function defines three properties for each
draggable layer—
MM_LEFTRIGHT
,
MM_UPDOWN
, and
MM_SNAPPED
—that you can use
in your own JavaScript functions to determine the relative horizontal position of
the layer, the relative vertical position of the layer, and whether the layer has
reached the drop target.
Note:
The information provided here is intended for the use of experienced JavaScript
programmers only.
For example, the following function displays the value of the
MM_UPDOWN
property
(the current vertical position of the layer) in a form field called
curPosField
.
(Form fields are useful for displaying continuously updated information because
they are dynamic—that is, you can change their contents after the page has
finished loading—in both Navigator and Internet Explorer.)
function getPos(layername){
var layerRef = MM_findObj(layername);
var curVertPos = layerRef.MM_UPDOWN;
document.tracking.curPosField.value = curVertPos;
}
Instead of displaying the value of
MM_UPDOWN
or
MM_LEFTRIGHT
in a form field,
you could write a function that displays a message in the form field depending on
how close the value is to the drop zone, or you could call another function to show
or hide a layer depending on the value. How you react to the value of
MM_UPDOWN
or
MM_LEFTRIGHT
is limited only by your imagination and your JavaScript skills.
It is especially useful to read the
MM_SNAPPED
property when you have several
layers on the page, all of which must reach their targets before the visitor can
advance to the next page or task. For example, you could write a function to count
how many layers have an
MM_SNAPPED
value of
true
and call it whenever a layer is
dropped. When the snapped count reaches the desired number, you could send
the visitor to the next page or display a message of congratulations.
If you have used the
onMouseOver
event to attach the Drag Layer action to links
within several layers, you must make a minor change to the
MM_dragLayer()
function to prevent the
MM_SNAPPED
property of a snapped layer from being reset to
false
if the mouse pointer rolls over the layer. (This can happen if you have used
Drag Layer to create a picture puzzle, because the visitor is likely to roll the mouse
pointer over snapped pieces while positioning others.) The
MM_dragLayer()
function does not prevent this behavior, because it is sometimes desirable—for
example, if you want to set multiple drop targets for a single layer.
Summary of Contents for 38028779 - Macromedia Dreamweaver - Mac
Page 1: ...macromedia Using Dreamweaver...
Page 148: ...Chapter 4 148...
Page 296: ...Chapter 12 296...
Page 472: ...Chapter 18 472...
Page 512: ...Chapter 21 512...
Page 562: ...Appendix 562...