Thank you, much better!!!

--- In [email protected], "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> It looks like you're not quite handling drag/drop correctly.  
Typically
> you pick up mouseUp and mouseLeave when the drag starts and use 
capture
> phase for mouseUp.  Here's an adjusted sample:
> 
>  
> 
> <?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);
> 
> systemManager.stage.addEventListener(MouseEvent.MOUSE_UP, endDrag, 
> 
> true, 0, true);
> 
> systemManager.stage.addEventListener(MouseEvent.MOUSE_UP, endDrag, 
> 
> true, 0, true);
> 
> systemManager.stage.addEventListener(Event.MOUSE_LEAVE, endDrag2, 
> 
> false, 0, true);
> 
> myCanvas.addChild(myButton);
> 
> }
> 
> private var dragTarget:Button;
> 
>  
> 
> public var mouseStartY:Number;
> 
> private function mouseDownHandler(event:MouseEvent):void{
> 
> if (event.currentTarget is Button && event.buttonDown 
> 
> == true) {
> 
> dragTarget = event.currentTarget 
> 
> as Button;
> 
> mouseStartY = myCanvas.mouseY;
> 
> }
> 
> }
> 
> private function doDrag(event:MouseEvent):void {
> 
> if (event.currentTarget is Button && event.buttonDown 
> 
> == true) {
> 
> dragTarget.setFocus();
> 
> var r:Rectangle = new Rectangle(10,0,
> 
> (myCanvas.width-(dragTarget.width+30)), (700-dragTarget.height));
> 
> dragTarget.startDrag(false, r);
> 
> }
> 
> }
> 
> private function endDrag(event:MouseEvent):void {
> 
> if (dragTarget)
> 
>             dragTarget.stopDrag(); 
> 
> dragTarget = null;
> 
> }
> 
> private function endDrag2(event:Event):void {
> 
> if (dragTarget)
> 
>             dragTarget.stopDrag(); 
> 
> dragTarget = null;
> 
> }
> 
> ]]>
> 
> </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>
> 
>  
> 
>  
> 
> ________________________________
> 
> From: [email protected] 
[mailto:[EMAIL PROTECTED] On
> Behalf Of jmfillman
> Sent: Tuesday, March 11, 2008 3:21 PM
> To: [email protected]
> Subject: [flexcoders] Re: Drag Boundaries
> 
>  
> 
> 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
> <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 [email protected] <mailto:flexcoders%
40yahoogroups.com>
> , "Alex Harui" <aharui@> 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: [email protected] <mailto:flexcoders%
40yahoogroups.com>
> 
> [mailto:[email protected] <mailto:flexcoders%
40yahoogroups.com>
> ] On
> > Behalf Of jmfillman
> > Sent: Tuesday, March 11, 2008 9:07 AM
> > To: [email protected] <mailto:flexcoders%
40yahoogroups.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 [email protected]
> <mailto:flexcoders%40yahoogroups.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 [email protected]
> <mailto:flexcoders%40yahoogroups.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
> > >
> >
>


Reply via email to