how can i move original source image not imageProxy?
<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 mouseOverHandler(event:MouseEvent):void
{
var dragInitiator:Image=Image(event.currentTarget);
var ds:DragSource = new DragSource();
ds.addData(dragInitiator, "img");
// The drag manager uses the Image control
// as the drag proxy and sets the alpha to 1.0 (opaque),
// so it appears to be dragged across the Canvas.
var imageProxy:Image = new Image();
imageProxy.source = globeImage;
imageProxy.height=15;
imageProxy.width=15;
DragManager.doDrag(dragInitiator, ds, event,
imageProxy, -15, -15, 1.00);
}
// 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.c开发者_Python百科urrentTarget).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="mouseOverHandler(event);"/>
</mx:Canvas>
</mx:Application>
In this example imageProxy (duplicate image) dragging and move . But i want move original source image dragInitiator not imageProxy . how can i do ? i tried like
DragManager.doDrag(dragInitiator, ds, event,
dragInitiator, -15, -15, 1.00); it's moving but deleted ?
Any idea about it?
Looks to me like you are simply trying to move an image around within a canvas, correct? If so, using the DragManager and related mechanisms is overkill in my opinion. You can simply add handlers to your image for mouse down/up and then add a member var "isMouseButtonDown" or some such which you will set to true when the mouse button goes down and set it to false when the mouse button is up. When the mouse goes down, add a handler to your image for mouse move (don't forget to remove the handler when the mouse goes up.) You then update the x/y of your image whenever you get the move event and isMouseButtonDown is true. Pro tip: When adding the handler for mouse move, set the third parameter of addEventListener to true (useCapture), this will make your image move much less jittery. Hope that helps.
精彩评论