Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-18-2010, 11:06 PM   #1
euniceee
Registered User
 
Join Date: Jul 2010
Posts: 34
Default Problems with startDrag and StopDrag

Hi, I am writing an AS for dragging an object, it manages to drag the object, however it continues to perform the dragging action when I release the mouse. Is there anything problem with my code? Thank you.


Tan.buttonMode=true;
Tan.addEventListener(MouseEvent.MOUSE_DOWN, Drag);
Tan.addEventListener(MouseEvent.MOUSE_UP, Drop);

var boundsArea:Rectangle = new Rectangle (300,0,988,600)

function Drag(event:MouseEvent):void
{
var object = event.target;
object.startDrag(false, boundsArea);
}

function Drop(event:MouseEvent):void
{
var obj = event.target;
obj.stopDrag();
}
euniceee is offline   Reply With Quote
Old 07-18-2010, 11:12 PM   #2
flashGeneral
Senior Member
 
Join Date: Dec 2009
Location: New York
Posts: 188
Default

Try adding:
ActionScript Code:
Tan.addEventListener(MouseEvent.MOUSE_OUT, Drop);
flashGeneral is offline   Reply With Quote
Old 07-19-2010, 01:48 AM   #3
box86rowh
FLEX AND FLASH ARE COOL
 
Join Date: Oct 2005
Posts: 794
Default

I always add the mouse down listener to the dragged item (in your case Tan) then in the mouse down event handler, I add a listener to the stage for mouse up and mouse out that will control the stopping of the dragging. Be sure to then remove these 2 event listeners when you stop the dragging.
box86rowh is offline   Reply With Quote
Old 07-21-2010, 12:53 AM   #4
euniceee
Registered User
 
Join Date: Jul 2010
Posts: 34
Default

Hi I have tried to use both suggested methods, it does perform the drop function at that instant, however the dragging function has been disabled when I clicked on that piece of puzzle again. Is there anything wrong with my code? Thank you.
euniceee is offline   Reply With Quote
Old 07-21-2010, 07:19 AM   #5
vikram_billa
Actionscript is rocking
 
Join Date: Nov 2008
Location: Hyderbad, India
Posts: 185
Send a message via MSN to vikram_billa Send a message via Yahoo to vikram_billa Send a message via Skype™ to vikram_billa
Default

Check with bellow code.

ActionScript Code:
Tan.buttonMode=true; Tan.addEventListener(MouseEvent.MOUSE_DOWN, Drag); var boundsArea:Rectangle = new Rectangle (300,0,988,600) function Drag(event:MouseEvent):void { var object = event.target; object.startDrag(false, boundsArea); Tan.addEventListener(MouseEvent.MOUSE_UP, Drop); stage.addEventListener(MouseEvent.MOUSE_UP, Drop); } function Drop(event:MouseEvent):void { var obj = event.target; obj.stopDrag(); Tan.removeEventListener(MouseEvent.MOUSE_UP, Drop); stage.removeEventListener(MouseEvent.MOUSE_UP, Drop); }
__________________
VIKRAM BILLA
vikram_billa is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:06 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.