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.)
// 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();
}