Dragging an object

Peter Bogdanoff bogdanoff at me.com
Thu Jul 10 22:03:46 EDT 2014


Thanks, I’ll try it.

pb

On Jul 10, 2014, at 7:01 PM, Jim Hurley <jhurley0305 at sbcglobal.net> wrote:

>> 
>> Message: 19
>> Date: Thu, 10 Jul 2014 17:24:16 -0700
>> From: Peter Bogdanoff <bogdanoff at me.com>
>> To: How to use LiveCode <use-livecode at lists.runrev.com>
>> Subject: Dragging an object
>> Message-ID: <14789523-9AF4-4531-83CF-FF60644D1D89 at me.com>
>> Content-Type: text/plain; charset=windows-1252
>> 
>> Hi,
>> 
>> I want to drag an object around (a group), restricting its Y coordinate (set to be a property, ?yLocation"). I?m using this script inside the object:
>> 
>> on mouseMove
>>  if the mouse is down then
>>     set the loc of me to (item 1 of the mouseLoc,the yLocation of me)
>>  end if
>> end mouseMove
>> 
>> However, after moving it sideways, when I click on it again to move it, every time it jumps back so that its X coordinate is zero relative to the mouseLoc.
>> 
>> This behavior would be fine for a button, but I?m dragging a 3000-pixel-wide group.
>> 
>> How can I drag it by clicking on one side of this group?
>> 
>> I tried using the grab command, but I couldn?t seem to be able to restrict the Y coordinate with that.
>> 
>> Peter
>> UCLA
> 
> Hi Peter,
> 
> Greetings from UCD (retired).
> 
> The mouseMove needs to recognize the initial separation between the mouse at mouseDown the x loc of the object being moved at mouseDown. I call that distance dx. 
> The following will move the button along the initial y coordinate of the button and the x loc of the mouse plus the initial separation dx  
> 
> local y0 ,myName, dx
> 
> on mouseDown
>  put the short name of me into myName
>  put the loc of me into p0
>  put item 2 of p0  into y0
>  put the mouseloc into p1
>  put item 1 of p1 into x1
>  put  item 1 of p0 into x0
>  put x0 - x1 into  dx --The distance between the button loc and the mouse loc
> end mouseDown
> 
> on mouseMove x,y
>   if myName is not empty then
>      set the loc of me to x+ dx,y0
>   end if
> end mouseMove
> 
> on mouseUp
>  put empty into myName
> end mouseUp
> 
> on mouseEnter
>   put "" into myname
> end mouseEnter
> 
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode





More information about the use-livecode mailing list