How to drag a mesh ??

Software: Away3D 4.x

aeki, Member
Posted: 24 November 2012 07:50 PM   Total Posts: 73

Hi all

I would like to have in my scene the possibility to move an object by dragging it with the mouse.

I have implemented this by listening the MouseEvent3D.MOUSE_MOVE.

Basically, I did something like this :

aDraggableMesh:Mesh;

aDragableObject.addEventListener(MouseEvent3D.MOUSE_MOVE onMeshMouseMove);

private function 
onMeshMouseMove(event:MouseEvent3D):void{
 
// To move the mesh along the X axis only
 
aDraggableMesh.event.scenePosition.x;

The problem with this is that the mouse cursor has to stay over the mesh i want to drag.

If the mouse moves quickly and the cursor leaves the object, the onMeshMouseMove listener is’nt trigerred anymore and the drag stop.

How can I ensure that when a drag has started, it will continue till the mouse button is down, even if the mouse cursor leave the object?

   

Avatar
Fabrice Closier, Administrator
Posted: 24 November 2012 08:09 PM   Total Posts: 1265   [ # 1 ]

Take a look at Drag3D class, it will probably fix your problems.
All you need to do is set a boolean in your code, and on enterframe if true, drag3dInstance.update();

   

aeki, Member
Posted: 24 November 2012 08:35 PM   Total Posts: 73   [ # 2 ]

I had a look a Drag3D class.

If i understand well, you suggest to move the “dragging” code

aDraggableMesh.event.scenePosition.x

to the EnterFrame listener instead of the MeshMouseMove listener to avoid the problem of the mouse leaving the object?

   

Avatar
Fabrice Closier, Administrator
Posted: 25 November 2012 12:31 AM   Total Posts: 1265   [ # 3 ]

No I mean, change your code and use what is made for this:

add mouse down mouseEvent3d to mesh
on mouseEvent3D down, set boolean “isDragging” to true
set drag3d object to Drag3D instance. (and plane if you have not done that yet)
add stage mouseEvent mouse up.
on mouseup set boolean to “isDragging” to false;
on enterframe if isDragging drag3d.update();

done

   

aeki, Member
Posted: 25 November 2012 06:25 PM   Total Posts: 73   [ # 4 ]

Perfect !

Thanks a million!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X