|
-
AS3 startDrag x y coordinates
Hey guys, not sure if this is possible but i'd like to get the X,Y coordinates of a button I drag. here's my problem:
PHP Code:
backbutton_btn.addEventListener(MouseEvent.MouseDown, backbuttonDown);
backbutton_btn.addEventListener(MouseEvent.MouseMove, backbuttonMove);
public function backbuttonDown(e:MouseEvent)
{
backbutton_btn.startDrag();
}
public function backbuttonMove(e:MouseEvent)
{
trace(backbutton_btn.x +","+backbutton_btn.y);
}
the x and y coordinates remain the same even though i'm clearly dragging my button all over the stage. I did code my own by putting events and whatnot around the button but startDrag seemed smoother and faster. is it even possible?
-
You're doing it wrong. 
Code:
backbutton_btn.addEventListener(MouseEvent.MouseDown, backbuttonDown);
backbutton_btn.addEventListener(MouseEvent.MouseMove, backbuttonMove);
public function backbuttonDown(e:MouseEvent)
{
e.target.startDrag();
}
public function backbuttonMove(e:MouseEvent)
{
trace(e.stageX +","+e.stageY);
}
-
 Originally Posted by illustratedlife
You're doing it wrong.
PHP Code:
backbutton_btn.addEventListener(MouseEvent.MouseDown, backbuttonDown); backbutton_btn.addEventListener(MouseEvent.MouseMove, backbuttonMove);
public function backbuttonDown(e:MouseEvent) { e.target.startDrag(); }
public function backbuttonMove(e:MouseEvent) { trace(e.stageX +","+e.stageY); }
hmmm...this does work, but I still don't understand why the x and y coordinates of my button remain at 0,0 and now I have to rely on the mouse event to report where it is at. maybe what i'm doing isn't the most popular thing, I just think it's cool to drag programmatic buttons around.
-
how about locking a drag and drop object in with boundries?
new to the forum. still somewhat green to AS3. hello all.
i was reading this post (i found while doing a search to answer my question) and thought i'd ask you this here.
how would i lock in an object into set boundries? i can do this in AS2 but can't get it to work in 3.
in a nut shell, i have a ball. i want to drag this ball around the screen, but when it gets to the edge i don't want it to get cut off but instead stop at edge of the ball. essentially the stage is a box.
here's what i got so far:
ball_mc.buttonMode = true;
ball_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
ball_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(event:Event):void
{
ball_mc.startDrag();
}
function drop(event:Event):void
{
ball_mc.stopDrag();
}
so how do i set the boundries in which i want the ball to stay?
thanks!
`shields
-
The LiveDocs are your friend.
In AS3 it's done with a rectangle. Lookup startDrag in the LiveDocs index for the exact syntax.
-
awesome! thanks illustratedlife. that was pretty easy to figure out once you told me what to look for.
-
sorry tried to go back and add this to my previous post but couldn't find the edit button.
so this is what i did:
ball_mc.buttonMode = true;
ball_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
ball_mc.addEventListener(MouseEvent.MOUSE_UP, drop);
var rectangle:Rectangle = new Rectangle(17, 17, 515, 365);
function drag(event:Event):void
{
ball_mc.startDrag(true, rectangle);
}
function drop(event:Event):void
{
ball_mc.stopDrag();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|