I had the same question regarding drag and drop and this is an excellent 
answer.  I would expect it to be a little more automatic to drop an element at 
its dragged-to position rather than having to go through this but it's not that 
complex of a solution.


--- In [email protected], dingpeng cao <caodingp...@...> wrote:
>
> you can do this with a trick:
> when you start drag
> remember the mouseX and mouseY.
> code list this:
> // The mouseMove event handler for the Image control
> // initiates the drag-and-drop operation.
> private function mouseMoveHandler(event:
> 
> MouseEvent):void
> {
> var dragInitiator:Image=Image(event.currentTarget);
> var ds:DragSource = new DragSource();
> ds.addData(dragInitiator, "img");
> 
> var point:Point=new Point(dragInitiator.mouseX,dragInitiator.mouseY);
> ds.addData(point, "mouseOffset");
> 
> 
> DragManager.doDrag(dragInitiator, ds, event);
> }
> and when you drop this target, minus mouseOffset.
> code like this:// The dragDrop event handler for the Canvas container
> // sets the Image control's position by
> // "dropping" it in its new location.
> private function dragDropHandler(event:DragEvent):void {
> 
> var ds:DragSource=event.dragSource;
> var p:Point=ds.dataForFormat("mouseOffset") as Point;
> 
> Image(event.dragInitiator).x =Canvas(event.currentTarget).mouseX - p.x;
> Image(event.dragInitiator).y =Canvas(event.currentTarget).mouseY - p.y;
> }
> 
> 
> On Mon, Jul 20, 2009 at 6:28 PM, kk4Nabble <kavya....@...> wrote:
> 
> >
> >
> >
> > Hi all, Am new to flex. Was learning with examples given in flex3 livedoc.
> >
> > http://livedocs.adobe.com/flex/3/html/help.html?content=dragdrop_1.html
> >
> > There i came across this drag and drop example.
> >
> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>
> >
> > <mx:Script>
> > <![CDATA[
> > //Import classes so you don't have to use full names.
> > import mx.managers.DragManager;
> > import mx.core.DragSource;
> > import mx.events.DragEvent;
> > import flash.events.MouseEvent;
> >
> > // Embed icon image.
> > [Embed(source='assets/globe.jpg')]
> > public var globeImage:Class;
> >
> > // The mouseMove event handler for the Image control
> > // initiates the drag-and-drop operation.
> > private function mouseMoveHandler(event:MouseEvent):void
> > {
> > var dragInitiator:Image=Image(event.currentTarget);
> > var ds:DragSource = new DragSource();
> > ds.addData(dragInitiator, "img");
> >
> > DragManager.doDrag(dragInitiator, ds, event);
> > }
> >
> 
> and
> 
> >
> >
> > // The dragEnter event handler for the Canvas container
> > // enables dropping.
> > private function dragEnterHandler(event:DragEvent):void {
> > if (event.dragSource.hasFormat("img"))
> > {
> > DragManager.acceptDragDrop(Canvas(event.currentTarget));
> > }
> > }
> >
> > // The dragDrop event handler for the Canvas container
> > // sets the Image control's position by
> > // "dropping" it in its new location.
> > private function dragDropHandler(event:DragEvent):void {
> > Image(event.dragInitiator).x =
> > Canvas(event.currentTarget).mouseX;
> > Image(event.dragInitiator).y =
> > Canvas(event.currentTarget).mouseY;
> > }
> > ]]>
> > </mx:Script>
> >
> > <!-- The Canvas is the drag target -->
> > <mx:Canvas id="v1"
> > width="500" height="500"
> > borderStyle="solid"
> > backgroundColor="#DDDDDD"
> > dragEnter="dragEnterHandler(event);"
> > dragDrop="dragDropHandler(event);">
> >
> > <!-- The image is the drag initiator. -->
> > <mx:Image id="myimg"
> > source="@Embed(source='assets/globe.jpg')"
> > mouseMove="mouseMoveHandler(event);"/>
> > </mx:Canvas>
> > </mx:Application>
> >
> > here to set drag initiator , Canvas(event.currentTarget).mouseX;
> > this x will be the x during mouse button release .
> >
> > Instead , I want the x and y of the
> > shadow of the image (ie the border of the image). How will i set it?
> > Please help.
> > --
> > View this message in context:
> > http://www.nabble.com/Drag-and-drop-tp24567297p24567297.html
> > Sent from the FlexCoders mailing list archive at Nabble.com.
> >
> >  
> >
> 
> 
> 
> -- 
>            Dingpeng Cao
> Email:   caodingp...@...
>


Reply via email to