views:

56

answers:

2

Hello everyone,

I just would like to know how can I dynamically change a label's values while on mousedown. I basically have a mousedown event and I also have two labels in my application. What I would like to happen is to get the current x and y position of my mouse pointer as I move my mouse through the screen and changing the values of the labels into the values of the current x and y coordinates of the mouse pointer.

protected function object_mouseDownHandler(event:MouseEvent):void
{
    curX = this.mouseX;
    curY = this.mouseY;
}

<s:Label x="278" y="60" text="{curY}"/>
<s:Label x="278" y="80" text="{prevY}"/>

The above code is what I currently have with my labels receiving the value from curX and curY.

If anyone knows how I can achieve this, please feel free to share me some thoughts.

Thanks a lot. :)

EDIT:

Okay now, I got it working with the following code:

protected function application1_mouseMoveHandler(event:MouseEvent):void
{
    curX = event.stageX;
    curY = event.stageY;
}

However, what this code does is that it records the coordinates of my mouse as it moves across the screen. What i want now to do is just to get the coordinates of the mouse while event is on mouseDown. What i'm thinking is to call the mouseDown event and ask it if the mouse is currently down, if it returns true, then i'll start recording. However, i don't quite seem to know how i'll implement this. Help me anyone please? Thanks.

A: 

what you probably want to do is add a MOUSE_DOWN event listener and a MOUSE_UP event listener that adds or removes (respectively) the MOUSE_MOVE/ENTER_FRAME event you have there, therefore you know that every time the event fires the mouse button will be down.

shortstick
A: 
private function application_addedToStage_eventHandler():void
{
    stage.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
    stage.addEventListener(MouseEvent.MOUSE_UP, onUp);
}
private function onDown(e:Event):void
{
    stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
private function onUp(e:Event):void
{
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
}
private function onMove(e:Event):void
{
    this.curX = event.stageX;
    this.curY = event.stageY;
}
Amarghosh