Dear Team,
             I have developed a dragging application. There is a small
error that I cannot fix however. When I drag the plane very fast the
mouse does not stay with the confines of the object like the startDrag
and stopDrag functions available in AS3. As you already know
startDrag and stopDrag functions are not available in Away-3D.Can you
tell me how to fix the problem.

The two classes used are show. A class that uses DraggingClass is
given after the code od DraggingClass

package
{
        import away3d.cameras.*;
        import away3d.containers.*;
        import away3d.core.base.Object3D;
        import away3d.events.MouseEvent3D;

        import flash.display.*;
        import flash.events.*;


        public class DraggingClass extends Sprite
        {
                protected var _camera : HoverCamera3D;
                protected var _view : View3D;
                protected var mouseDown:uint = 0;
                protected var overPlane:uint = 0;//Used to check whetehr mouse 
is
over the object.

        public function DraggingClass()
        {
                super();
                _createView();
        }

        public function onMouseDown(object:Object3D):void
        {
                mouseDown = 1;
                object.addEventListener(MouseEvent3D.MOUSE_MOVE,onMouseMove)
                object.addEventListener(MouseEvent3D.MOUSE_OUT,onMouseOut)
        }

        public function onMouseMove(eve : MouseEvent3D) : void
        {

                var obj : Object3D = eve.object;

                if(mouseDown == 1 && overPlane == 1)
                {
                obj.x = eve.sceneX;
                obj.y = eve.sceneY;

                }

                obj.addEventListener(MouseEvent3D.MOUSE_UP,onMouseUp)
                obj.addEventListener(MouseEvent3D.MOUSE_OUT,onMouseOut)


        }

        public function onMouseOut(eve:MouseEvent3D):void
        {
                var obj : Object3D = eve.object;
                obj.useHandCursor = false;
                overPlane = 0;
                mouseDown = 0;
        }

        public function onMouseUp(eve:MouseEvent3D):void
        {
                mouseDown = 0;

        }

        public function onMouseOver(object:Object3D):void
        {
                overPlane = 1;
                object.useHandCursor = true;
                object.addEventListener(MouseEvent3D.MOUSE_OUT,onMouseOut)
                trace("Over the plane");
        }


        protected function _createView() : void
        {

                _camera = new HoverCamera3D();
                _camera.distance = 1000;
                _camera.tiltAngle = 10;
                _camera.panAngle = 180;

                _view = new View3D();
                _view.x = 400;
                _view.y = 300;
                _view.camera = _camera;
                addChild(_view);
                addEventListener(Event.ENTER_FRAME, _onEnterFrame);
        }


        protected function _onEnterFrame(ev : Event) : void
        {

                _camera.hover();
                _view.render();
        }


  }
}


A class that creates a plane. An instance of DraggingClass is created
and used to access the functions in DraggingClass.



package
{
                import away3d.cameras.*;
                import away3d.containers.*;
                import away3d.core.base.Object3D;
                import away3d.events.MouseEvent3D;
                import away3d.primitives.Plane;

                import flash.display.*;
                import flash.events.*;


                public class DragPlane extends Sprite
                {
                        protected var drag:DraggingClass = new DraggingClass();
                        protected var _camera : HoverCamera3D;
                        protected var _view : View3D;
                        protected var plane:Plane;

                public function DragPlane()
                {
                        super();
                        _createView();
                        _createScene();

                }


                protected function _createView() : void
                {
                        _camera = new HoverCamera3D();
                        _camera.distance = 1000;
                        _camera.tiltAngle = 10;
                        _camera.panAngle = 160;

                        _view = new View3D();
                        _view.x = 400;
                        _view.y = 300;
                        _view.camera = _camera;
                        addChild(_view);
                        addEventListener(Event.ENTER_FRAME, _onEnterFrame);
                }


                protected function _onEnterFrame(ev:Event) : void
                {
                        //_camera.panAngle += (stage.mouseX - 
stage.stageWidth/2) / 100;
                        _camera.hover();
                        _view.render();
                }

                protected function _createScene():void
                {

                        var plane : Plane = new Plane();
                        plane.width +=100;
                        plane.yUp = false;
                        _view.scene.addChild(plane);

                        
plane.addEventListener(MouseEvent3D.MOUSE_DOWN,_onMouseDown);
                        
plane.addEventListener(MouseEvent3D.MOUSE_OVER,_mouseOver)
                }

                protected function _onMouseDown(eve:MouseEvent3D):void
                {

                        var obj1 : Object3D = eve.object;
                        drag.onMouseDown(obj1);
                }

                protected function _mouseOver(eve:MouseEvent3D):void
                {

                        var obj : Object3D = eve.object;
                        drag.onMouseOver(obj);
                }


  }

}

Reply via email to