Hi!
Do you want Axure to figure out whether the the user intends to drag horizontally or vertically, and then restrict drag to that direction? That’s possible, but it takes a bit of work. First, some important concepts
- The OnDragStart message fires as soon as Axure senses a drag
- The OnDrag message fires constantly the whole time you’re dragging, whether or not you actually move the dynamic panel within the OnDrag event
- The dynamic panel properties TotalDragX and TotalDragY return how far (in an x or y direction) you’ve dragged since you began dragging – again, whether or not you actually move something in the OnDrag event
We can determine which axis the user intends to drag upon by checking whether the absolute value of TotalDragX is greater than that of TotalDragY (or vice-versa). Unfortunately, it’s not very reliable to test this upon the very first OnDrag message, because a directional trend has not necessarily been established yet. E.g., the first teensy movement may be primarily in the x direction, but a bit later it might straighten out to reveal a predominantly y direction.
So the strategy is this: wait until several OnDrag events have fired before checking if TotalDragX is greater than TotalDragY, and only then start moving the panel along the desired axis. I find by the 4th or so OnDrag message this test is pretty reliable. (Experiment with that number if you like.)
Because of that, we can’t use “move with drag,” as that will start dragging the panel immediately. Instead, we will store the initial position (start x and start y) of the panel OnDragStart, and then on drag, if we’re dragging along the x axis, move the panel to start x + TotalDragX (or to start y + TotalDragY if dragging in the y direction)
Here is some pseudocode:
OnDragStart
set v_dragCount to 0
set v_startX to the panel's x position
set v_startY to the panel's y position
OnDrag
increment v_dragCount
IF v_dragCount equals 4 AND the absolute value of TotalDragX is greater than that of TotalDragY
set v_dragDirection to 'x'
ELSE IF v_dragCount equals 4
set v_dragDirection to 'y'
IF v_dragCount is greater than or equal to 4 and v_dragDirection is 'x'
move panel's x position to v_startX + TotalDragX
ELSE IF v_dragCount is greater than or equal to 4 and v_dragDirection is 'y'
move the panel's y position to v_startY + TotalDragY
Note that you can still put boundaries on the Move to command, to keep if from dragging further in any direction than you want it to.
I updated your file:
Live sample
File: dragLock_rp8.rp (134.9 KB)