Page 1 of 1
constrain grabbed object to the x or y axis? [solved]
Posted: Fri Jul 17, 2015 6:49 pm
by sms5138
Hi Everyone,
I'm trying to an group that can only be moved up and down. until this point i've been doing just fine using the following:
Code: Select all
on mouseDown
grab group "boxes"
end mouseDown
however allows me to grab said group, and move it up, down, left, and right... is there a way to tell it to only allow the y axis, or vertical? has anyone come across this before?
thanks in advance for any assistance you can provide!
-Sean
Re: constrain grabbed object to the x or y axis?
Posted: Sat Jul 18, 2015 12:40 am
by dunbarx
Hi.
Here is a handler from an old thread. I m lazy, and instead of just giving you a method, I am making you do all the work. It actually does much more than you asked for. But make this and play with it. Then see if you can simplify the ideas in it to do what you need.
On a new card, place two line graphics, one vertical and one horizontal, that cross each other. Name the vertical one "vLine". Name the horizontal one "hLine". Make a button and place this in its script:
Code: Select all
on mouseMove x,y
put the left of grc "vLine" into h
put the top of grc "hLine" into v
put H & "," & v into origin
put abs(x-h) into hWindow
put abs(y-v) into vWindow
switch
case vWindow < 10 and hWindow < 10
set the loc of me to origin
break
case vWindow <= 10
set the loc of me to x & "," & v
break
case hWindow <= 10
set the loc of me to h & "," & y
break
case hWindow > 10 and vWindow > 10
set the loc of me to the mouseLoc
break
end switch
end mouseMove
Now put the cursor over the button, and bring it near either of the lines. As I said, this is more than you asked (bargained?) for. Can you see the thinking behind it? Can you make your gadget with only a few lines of code? Write back if you need a hand.
Craig Newman
EDIT: Here is the name of that thread: Snap objects while dragging
Re: constrain grabbed object to the x or y axis?
Posted: Sun Jul 19, 2015 3:12 pm
by sms5138
Hey Craig!
I really appreciate the help! I'm gonna dig into this later today, and see if i can get it working!
Thanks again!
-Sean