Click to go to the home page.

This Document
"Drag Element" Behavior
Public Handler

See Also
"Drag Element b" parent script
"Cursor Control" Behavior

"6: Handle" behavior

 

Site Nav

css drop down menu by Css3Menu.com

Drag Element

The "Drag Element" Behavior

Click to go to top of this section. What it does

Makes an element of a multi-sprite draggable. When you attach this to a Window Element or Menu Element, when the user mouses down on the element, they can drag the element around as long as you also have a copy of the "Drag Element b" parent script in a cast. If you don't have a copy of this in a cast, WFS will remind you to do it because the "Drag Element" behavior needs the "Drag Element b" parent script.

You can configure the "Drag Element" behavior so that the element is constrained in its movement within a rectangle related to the position of the background sprite of the multi-sprite that the element is part of. By WFS convention, the background element of a multi-sprite is the element below the Manager in the Score.

When you make an element draggable, you may wish to also drop the "Cursor Control" behavior on the element and configure that behavior so that it is set to "Drag and Drop" so the cursor indicates to the user that the element is draggable. You don't have to do this, but it is sound interface design.

This behavior is used in scene 13 of the demo. To find it used in the demo DIR file, open the DIR, display the Score, then open the WFS 4 cast in the Cast window, right-click on the "Drag Element" behavior, and select "Find in Score".

Click to go to top of this section. What to attach it to

Attach "Drag Element" to Window Elements or Menu Elements (not to Managers). Window Elements and Menu Elements have the "4: Window/Menu Element" behavior attached to them.

Click to go to top of this section. "Drag Element b" parent script

If you use the "Drag Element" behavior, drop a copy of the "Drag Element b" parent script into a cast. You don't need to do anything else concerning this script. You just need one copy of it in some cast.

Click to go to top of this section. Parameter Dialog Box

Parameter Dialog Box for the "Drag Element" behavior

If you leave the first box checked, then the element will be brought to front on mousedown. This doesn't bring the window it's part of to front. Whether the window it's part of is brought to front depends on the configuration of the Window Manager's Parameter Dialog Box. If the top box in the graphic to the right is not checked, the element is not brought to front on mouseDown..

If you leave the second box unchecked, then you'll be able to drag the element around without constraints. If you check this box, then the element will be constrained in its motion by the margins you define in the next four boxes. These margins are relative to the background element of the window that the element you've dropped the behavior on is part of.

If you check the top box and leave the others at 0, then the element will be constrained in its movement to be within the background sprite of the multi-sprite the element is part of.

Positive values among the last four parameters are like margin settings. Negative values make the constraints move beyond the constraining window's border.

In the graphic, the check box is checked, so constraints are in effect. The Left Margin is set to 20. This means that the element will not be able to be dragged farther left than 20 pixels to the right of the window's left.

The Top Margin is 0, so the element will be draggable no higher than the window's top.

The Right Margin is -50, so the element will be draggable 50 pixels to the right of the window's right border, ie, negative values expand the border.

Click to go to top of document. Public Handler

wfsSetDragConstraints BringElementToFrontWhenDragging, constrainToWindow, theLeft, theTop, theRight, theBottom

Function

wfsSetDragConstraints allows you to change the constraints on the fly. You don't need to call this unless, after the sprite becomes instantiated, you want to change the constraints you've configured.

Parameters

BringElementToFrontWhenDragging: This boolean determines whether the element will be brought in front of all other WFS elements when you drag it (TRUE) or not (FALSE)..

constrainToWindow: This is a boolean that determines whether the element is constrained in its movement by the multi-sprite it's an element of (TRUE) or unconstrained in its movement (FALSE).

theLeft: This is an integer. It is only relevant if you have specified constrainToWindow to be TRUE. Positive values for theLeft determine how far to the right of the left border of the constraining window the constraint will be. Negative values for theLeft let the user move the element further to the left than the constraining window's left border.

theTop: Same sort of idea as for theLeft only theTop determines the constraint concerning top vertical movement.

theRight: Same sort of idea as for theLeft only theTop determines the constraint concerning movement to the right

theBottom: Same sort of idea as for theLeft only theTop determines the constraint concerning vertical movement down.

Example

In the below examples, suppose that the "Drag Element" behavior is attached to sprite 7.

sprite(7).wfsSetDragConstraints(TRUE, 0,0,0,0)

The above constrains sprite 7 to moving within the area defined by the background of the multi-sprite that sprite 7 is an element of.

sprite(7).wfsSetDragConstraints(FALSE, 0,0,0,0)

The above makes sprite 7 unconstrained in its draggability.

sprite(7).wfsSetConstraints(TRUE, 10,10,10,10)

The above constrains sprite 7 to moving within a rectangle that is 10 pixels inside the border of the window sprite 7 is part of.

sprite(7).wfsSetConstraints(TRUE, -10,-10,-10,-10)

The above constrains sprite 7 to moving within a rectangle whose perimeter is 10 pixels outside the border of the window sprite 7 is part of.

 

Click to go to the home pageDrag Element