Finding left and top postition of a shape after a drag and drop

Problem: I would like to find the left and top position of a drag and drop object after the shape has been moved, but the functions .left() and .top() only return the position the shape started at

ActivePresenter Version: 7.5.8

OS: Win 10

Notes: -

Hi Scott,

You can use .translate() function to get the dragged distance (relative to the original position):

  var dragObject = prez.object('object name');
  var dragDistance = dragObject.translate();
  var left  = dragObject.left() +  dragDistance.translateX;
  var top = dragObject.top() +  dragDistance.translateY;

Regards

That’s great, many thanks

Hi Toan,

I tried this code with version 9 and it only gives me the original position.

Also, just out of curiosity; I could do without the dragDistance variable and just use

this.translate().translateX

, right?

Thanks, Rolf

Hi Rolf,

left() and top() will give the original position, translate() will give the distance from the new position (after dragging) to the original position.

Yes, you can use translate().translateX directly without the dragDistance variable.

Regards

1 Like

Thanks, Toan,

I see my problem now - I had the drag source on revert.

However, I do need the revert. Is there a way to make sure that the drag distance is checked first and the revert is done after that.

I know how to do that manually (see Hang’s reply from June 29). I just thought maybe there was a JS way to postpone the revert that AP provides, check whether the drop was correct and revert if it was incorrect.

Thanks, Rolf

P.S.: Just a bit of context.
I’m trying to create a template for basic functionalities of point-and-click adventures for teaching purposes. I am currently working with a basic inventory, which includes drag and drop, e.g. drag the key over the door to unlock the door, etc.
For the envisaged user the template should be as simple as possible, i.e. the inventory object icon is in the masterslide and the drop target is an object on a given slide.
On drag start, I check whether the slide contains the relevant drop target and get its dimensions and size. On drag end, I check whether the new position (left + translateX, etc.) falls within the area covered by the object. This works well, if I do not have the revert and, of course, does not work if the revert box is checked. Hence, the question.

Sorry for my many and long posts.

Hi Rolf,

Unfortunately, it’s not possible with the revert option.
In this case, you should not use the revert option that ActivePresenter provides and implement it using your own script.

Regards

Thanks, Toan. Best, Rolf