I'm trying to figure out how I can show an object's X/Y coordinates while it's being dragged across the stage.
If I have a square located at 0,0 and I drag it to a new location--for example 50,50--I want to show the square's location as it is being dragged, not just when it's dropped. So the coordinate numbers will be constantly changing as the object is dragged.
Right now my code only detects the object's X/Y location when dragging starts and when dragging stops:
import flash.events.MouseEvent;
this.addEventListener(MouseEvent.MOUSE_DOWN, startDragging, true);
this.addEventListener(MouseEvent.MOUSE_UP, stopDragging, true);
function startDragging(e:MouseEvent) {
square1.startDrag();
xDisplay_txt.text = square1.x;
yDisplay_txt.text = square1.y;
}
function stopDragging(e:MouseEvent) {
testStage1.stopDrag();
xDisplay_txt.text = testStage1.x;
yDisplay_txt.text = testStage1.y;
}
Any help is appreciated. Thanks.
You need to call a certain handler, while you are dragging that thing, on a regular basis in order to update the output texts. The simplest way is to use the ENTER_FRAME event that fires, as its name states, every frame.