# Custom Dragger with TimerEvent. Drag from original position

**URL:** <https://forum.kirupa.com/t/custom-dragger-with-timerevent-drag-from-original-position/286040>\
**Category:** Uncategorized\
**Created:** [April 9, 2009, 2:38am UTC](https://forum.kirupa.com/t/custom-dragger-with-timerevent-drag-from-original-position/286040 "2009-04-09T02:38:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nineteen](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/nineteen/32/2679_2.png) [@Nineteen](https://forum.kirupa.com/u/Nineteen)\
**Post date:** [April 9, 2009, 2:38am UTC](https://forum.kirupa.com/t/custom-dragger-with-timerevent-drag-from-original-position/286040/1 "2009-04-09T02:38:23Z")

</div>

Hi,

I prefer to build custom drag functions using the TimeEvent etc. Below I have some code where as when I click on a MovieClip it fires the imageStartDrag function which then begins the imageDrag function consecutively.

Currently when I click and drag it moves the image fine, however it is snapping to the far left of the image.

What I would like is to be able to click and drag so that the image drags from it’s original point. My brain is a bit confused, what do I edit in ‘imageLoader.x = mouseX;’ to have it starting from it’s original position and moving. (Note, I’m only testing with the X Axis atm, later it will use the Y Axis too.)

```auto

// Image StartDrag Handler.
        private function imageStartDrag(e:MouseEvent):void {
            // Start Timer.
            nImageDragTimer.start();
            // Drag Listener.
            nImageDragTimer.addEventListener(TimerEvent.TIMER, imageDrag);
            // onReleaseOutside Equivalent.
            stage.addEventListener(MouseEvent.MOUSE_UP, imageStopDrag);
        }
        
        // Image StopDrag Handler.
        private function imageStopDrag(e:MouseEvent):void {
            // Stop Timer.
            nImageDragTimer.stop();
            // Drag Listener.
            nImageDragTimer.removeEventListener(TimerEvent.TIMER, imageDrag);
            // onReleaseOutside Equivalent.
            stage.removeEventListener(MouseEvent.MOUSE_UP, imageStopDrag);
        }
        
        // Image Drag Handler.
        private function imageDrag(e:TimerEvent):void {
            // Calculate Original MouseX Pos.
            var nImageLoaderX:Number = imageLoader.x;
            var nImageLoaderY:Number = imageLoader.y;
            trace(nImageLoaderX + ' : Mouse X = ' + mouseX);
            imageLoader.x = mouseX;
            // Smooth Dragging.
            e.updateAfterEvent();
        }

```
