Class Point.
Package flash.geom
Class public class Point
InheritancePoint Object
Language version: ActionScript 3.0
Player version: Flash Player 9
The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
So here’s a very short example made in AS3 in wish no matter where your grab the Sprite, it will be dragged from that specific Point.
Heres the example :
Open in New Window
Here’s the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | bear.addEventListener(MouseEvent.MOUSE_DOWN, startbearDrag); stage.addEventListener(MouseEvent.MOUSE_UP, stopbearDrag); bear.addEventListener(Event.ENTER_FRAME, dragbear); var clickOffset:Point = null; function startbearDrag(event:MouseEvent) { clickOffset = new Point(event.localX, event.localY); } function stopbearDrag(event:MouseEvent) { clickOffset = null; } function dragbear(event:Event) { if (clickOffset != null) { bear.x = mouseX - clickOffset.x; bear.y = mouseY - clickOffset.y; } } |

The Dragging and Dropping in Actionscript 3.0 by David Gamez, unless otherwise expressly stated, is licensed under a Creative Commons Attribution-Noncommercial 2.5 Mexico License.














![Validate my RSS feed [Valid RSS]](http://www.cloudfaces.com/swfgeekblogexamples/images/valid-rss.png)


Um…couldn’t you just use the startDrag and stopDrag functions? By default they drag from where you click, don’t they?
Maybe I didn’t explain myself too well, I’m know for that
The difference between doing it this way is that you keep the position of the cursor offset and the sprite relative to each other as the user drags; And the second and more important for it’s flexibility it’s that the dragging it’s not tied to the sprite object but to the Point object that gives us plenty of room for playing with our code.
I am getting the following error:
1120: Access of undefined property bear
Any ideas?
Hi Franky!!
That’s probably because you haven’t give the instance name of “bear” to the MovieClip you’re trying to drag, to do so simple name “bear” that clip or substitute “bear” in the code with the name of your clip.
Hope it’s helps if any trouble comment it here.
Thanks Dave