Alex, I assumed as much. The problem I'm encountering is that sporadically when you move the mouse outside of the container, you sometimes can't ever get the mouse back over the dragging item, effectively, making it perpetually floating, with no way to stop the drag. This happens most often if you scroll the container, while the item is still being dragged. Drag the button to the right, with the mouse leaving the drag area, release the mouse and then click to scroll the canvas. Try and go back into the drag area and drag the button. You have to work at it to get the mouse back over the button so you can complete the drop. Now I can add a mouse_out event listener to stop the drag event to prevent this, but was hoping for a better alternative.
<?xml version="1.0"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" backgroundColor="white" initialize="initApp();"> <mx:Script> <![CDATA[ import mx.core.DragSource; import mx.managers.DragManager; import mx.controls.Button; private function initApp():void{ var myButton:Button = new Button; myButton.width = 100; myButton.height = 50; myButton.y = 0; myButton.label = "Test Button"; myButton.setStyle("left", 300); myButton.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler, false, 0, true); myButton.addEventListener(MouseEvent.MOUSE_MOVE, doDrag, false, 0, true); myButton.addEventListener(MouseEvent.MOUSE_UP, endDrag, false, 0, true); myCanvas.addChild(myButton); } public var mouseStartY:Number; private function mouseDownHandler(event:MouseEvent):void{ if (event.currentTarget is Button && event.buttonDown == true) { var dragTarget:Button = event.currentTarget as Button; mouseStartY = myCanvas.mouseY; } } private function doDrag(event:MouseEvent):void { if (event.currentTarget is Button && event.buttonDown == true) { var dragTarget:Button = event.currentTarget as Button; dragTarget.setFocus(); var r:Rectangle = new Rectangle(10,0, (myCanvas.width-(dragTarget.width+30)), (700-dragTarget.height)); event.target.startDrag(false, r); } } private function endDrag(event:MouseEvent):void { event.target.stopDrag(); } ]]> </mx:Script> <mx:Canvas id="myCanvas" width="500" height="300" backgroundColor="#FFFFFF" borderStyle="solid" verticalScrollPolicy="on" horizontalScrollPolicy="off" click="trace (myCanvas.verticalScrollPosition)"> <mx:HRule x="0" y="700"/> </mx:Canvas> </mx:Application> --- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote: > > There's no way to control the mouse cursor position. > > > > Flex does not use startDrag and handles its own dragging so it can > handle the mouse up outside the stage. See the code in Panel.as > > > > ________________________________ > > From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On > Behalf Of jmfillman > Sent: Tuesday, March 11, 2008 9:07 AM > To: flexcoders@yahoogroups.com > Subject: [flexcoders] Re: Drag Boundaries > > > > Excellent!! > > That resolves limiting the dragged item to the rectangle, however, > the mouse still can leave the drag area. If the mouse button is > released outside of the rectangle, the mouse_move and mouse_up events > does not fire (as expected), and you can be left with a floating > item, in this case, a button. So, can I keep the mouse within the > same rectangle, only while dragging? > > --- In flexcoders@yahoogroups.com <mailto:flexcoders% 40yahoogroups.com> > , "iilsley" <iilsley@> wrote: > > > > > > The 2nd argument to startDrag is of type 'Rectangle' . > > > > try: > > var r:Rectangle = new Rectangle > (10,0,myCanvas.width,myCanvas.height); > > event.target.startDrag(false, r); > > > > > > --- In flexcoders@yahoogroups.com > <mailto:flexcoders%40yahoogroups.com> , "jmfillman" <jmfillman@> wrote: > > > > > > Well that's what I thought, but when I change this: > > > > > > event.target.startDrag(); > > > > > > to this: > > > > > > event.target.startDrag(false, 10, 0, myCanvas.width, > myCanvas.height); > > > > > > I get the following error: > > > > > > ArgumentError: Error #1063: Argument count mismatch on > > > flash.display::Sprite/startDrag(). Expected 0, got 5. > > > > > > > > > --------- > > > > startDrag(lockCenter:Boolean = false, bounds:Rectangle = > null):void > > >