Flex 拖/放至拖动代理的精确坐标
我在 Flex(Web)应用程序中添加了自定义拖放功能,除了一个微小的问题外,一切都工作正常。被放置的图像稍微偏离实际的拖动代理。我希望拖放的图像位于与拖动代理相同的位置。我从 VBox 拖动到面板。我似乎无法在实际代理坐标和删除的坐标之间建立联系。非常感谢:)
I added custom dragging and dropping in a flex (web) application and it all works fine except for a teeny weeny problem. The image been dropped drops a bit off the actual drag proxy. I want the image dragged and dropped to be in the exact place as the drag proxy. I dragging from a VBox to a Panel. I just cant seem to make the connection between the actual proxy coordinates and the dropped coordinates. Thanx a lot :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个老问题,但我确信其他人正在寻找此信息。经过大量调试后,我已经确定了一种方法来完成这项工作(Flex 4 ... 3 可能类似)。
问题是用户可以在任何地方抓取原始对象来开始拖动。当您放置对象时,您需要指定它的去向。为了完美地放下它,你需要知道用户在哪里抓住了物体。我无法在传递到 Drop 事件处理程序的 DragEvent 中找到任何对“对象到鼠标”x,y 坐标的引用。然而,此信息是在鼠标按下处理程序中传递的原始 MouseEvent (localX, localY) 中提供的。您需要做的就是保留这些坐标(我将它们存储在被拖动的对象中作为鼠标偏移变量)。当放置事件发生时,只需从 DragEvents currentTarget mouseX 和 mouseY 中分别减去它们即可。不管出于什么原因,我还需要从两个坐标中减去 1 以获得完美的落差。
这是一段代码,希望可以使它更清楚。
希望它可以节省其他人的时间......
This is an old question but Im sure others are looking for this information. After a lot of debugging I have determined a way to make this work (Flex 4 ... 3 may be similar).
The issue is that the user can grab the original object anywhere to start the drag. When you drop the object you need to specify where it goes. To drop it perfectly you need to know where the user grabbed the object. I was unable to find any reference to the "object to mouse" x,y coords in the DragEvent passed into the Drop Event handler. However this information IS provided in the original MouseEvent (localX, localY) passed in the Mouse Down handler. All you need to do is persist these coords (I stored them in the object being dragged as mouse offset variables). When the drop event happens just subtract them respectively from the DragEvents currentTarget mouseX and mouseY. For whatever reason I also needed to subtract 1 from both coords to get the drop perfect.
Here is a chunk of code to hopefully make it clearer.
Hope it saves someone else some time ...