PDA

View Full Version : Sample: Drag / Drop Object


Desmond
09-22-2005, 10:04 AM
This example illustrates how to use the On Mouse Move and On Mouse Button events to effectively drag and drop an object around your application.

Skills Used:
On Enter, On Leave, On Mouse Move, On Mouse Button, GetPos.

pjborg
03-29-2006, 11:09 AM
The example works great for one object, but if you want to drag and drop multiple objects those that are higher up in the z-order "steal" the cursor from those lower down. One workaround is to put the following in the page's "On Mouse Button" event:
if e_Type == 0 and sObject then
nOrigX = e_X;
nOrigY = e_Y;
tProps = Button.GetProperties(sObject);
nPos = Button.GetPos(sObject);
bReady = true;
else
bReady = false;
end
and put this in the page's "On Mouse Move" event:
if not System.IsKeyDown(1) then
bReady = false;
end

if sObject and bReady then
nChangeX = e_X - nOrigX;
nChangeY = e_Y - nOrigY;
Button.SetPos(tProps.ObjectName, nPos.X + nChangeX, nPos.Y + nChangeY);
end
The objects still retain their z-order, and those lower down move behind those further up, but at least you can move them around. If z-order could be changed at runtime that would work better, but I don't think that's possible. If there are better ways to drag and drop multiple objects on a page I'd love to hear about it. Thanks.

Desmond
03-29-2006, 11:19 AM
Hello,

You can set Z-Order dynamically at runtime with AMS60:
http://www.indigorose.com/webhelp/ams60/Program_Reference/Actions/Page.SetObjectZOrder.htm

Desmond.

pjborg
03-29-2006, 11:28 AM
Thanks! I thought I'd looked everywhere for that. Nope! :o

Desmond
03-29-2006, 11:55 AM
You're most welcome.

kelwyn
04-14-2006, 03:23 PM
Hi I tried this template which works excellent and would be good for a test I am trying to design, but when I changed the buttons for graphics and pasted all the code into the relevant parts I kept getting an error message.

on mouse move, line 8:attempt to index global'npos'(a nil value)

Any ideas as this would really help me out, thanks.

ejmlab
12-15-2007, 05:14 PM
I'm not sure if this will work for your purposes but if you use the button maker you can import your image, create a button and then use the code to drag and drop the new button object on the page.

nitrobry
01-04-2008, 06:35 PM
Hi
You can also do the same with Images

Change Button to Image



if e_Type == 0 and sObject then
nOrigX = e_X;
nOrigY = e_Y;
tProps = Image[/COLOR].GetProperties(sObject);
nPos = Image.GetPos(sObject);
bReady = true;
else
bReady = false;
end

And put this in the page's "On Mouse Move" event:


if not System.IsKeyDown(1) then
bReady = false;
end

if sObject and bReady then
nChangeX = e_X - nOrigX;
nChangeY = e_Y - nOrigY;
Image.SetPos(tProps.ObjectName, nPos.X + nChangeX, nPos.Y + nChangeY);
end

Gelson
09-11-2009, 06:09 PM
Image example!

rexzooly
09-12-2009, 12:18 PM
very useful thanks :yes

boku
11-03-2009, 09:55 PM
Sorry for reliving this thread but I'm having difficulty running this. I want to move a window based on a hotspot having the mouse clicked in it ... but it shakes like crazy...any tips guys?

rexzooly
11-06-2009, 07:13 AM
Not seen this problem can you post a demo APZ feller and i see if it does that this end?

boku
11-06-2009, 07:22 AM
Hey Rex,

I learnt something instead. I didn't realise that if you disabled images they became skin as such and I could drag my form around no problems.

Thanks though :)

rexzooly
11-06-2009, 07:39 AM
Hey Rex,

I learnt something instead. I didn't realise that if you disabled images they became skin as such and I could drag my form around no problems.

Thanks though :)

I didn't even know what thanks for the heads up lol :cool:yes