ActionScript-3 – How to “Cancel” Drag in Flex?

Once I call DragManager.acceptDrag, is there a way to “not accept” the drag? Suppose I have a view that can accept drag and drop, but only in certain areas. Once the user drags one of the areas, I call DragManager.acceptDrag(this) (from the DragEvent.DRAG_OVER handler), but if the user moves out of this area , I want to change the status of the drag to not accept and show DragManager.NONE feedback. However, calling DragManager.acceptDrag(null) and DragManager.showFeedback(DragManager.NONE) does not seem to have any effect. Once I accept the drag setting I can’t seem to change the feedback type.

Just to make it clear: the area that the user should be able to put down is not a component or even a display object, in fact they are just the range in the text of the text field (such as selection) If they are their own components I can solve it by letting each of them accept the drag event individually. I think I can create a proxy component floating on the text to simulate it, but if it is not necessary, I would rather not do it .

I have managed to make it work in AIR and browsers now, but can only put the proxy component above the text range, you should be able to discard things. This way I get the correct feedback, and The descent is automatically cancelled at the drag exit.

This is the strangest thing about D&D in AIR:

DragManager.doDrag(initiator, source, event, dragImage, offsetX, offsetY);

In browser-based Flex, offsetX and offsetY should be negative numbers (so say the document, it works fine). However, it works exactly the same in AIR The code must make the offset positive. The same number but positive. This is very, very strange.

I have tested more and how @maclema works, but if you are in AIR It doesn’t work in AIR. It seems that drag and drop in AIR is different. It’s really weird, because not only the feedback is not displayed correctly, and it’s impossible not to accept it, but the coordinates are also completely closed. I’m just in the browser instead of AIR. Trying my app, drag and drop is completely broken.

Also, skipping the dragEnter handler works well in AIR, but it breaks everything when running in the browser.

div>

Do you only use the dragEnter method? If you try to refuse the drag while still dragging the same component, you need to use the dragEnter and dragOver methods at the same time.

Look at this example:




import mx.core.DragSource;
import mx.managers.DragManager;
import mx. events.DragEvent;

private function onDragEnter(e:DragEvent):void {
if (e.target == lbl) {

if (e.localX trace("accept");
DragManager.acceptDragDrop(this);
}
else {
DragManager.acceptDragDrop(null );
}
}
}

private function doStartDrag(e:MouseEvent):void {
if (e.buttonDown) {
var ds:DragSource = new DragSource();
ds.addData("test", "text");

DragManager.doDrag(btn, ds, e);
}
}
]]>



Once I call DragManager.acceptDrag, is there a way to “not accept” drag verb: move? Suppose I have a view that can accept drag and drop, but only in certain areas. Once the user drags one of the areas, I call DragManager.acceptDrag(this) (from the DragEvent.DRAG_OVER handler), but if the user moves out of this area , I want to change the status of the drag to not accept and show DragManager.NONE feedback. However, calling DragManager.acceptDrag(null) and DragManager.showFeedback(DragManager.NONE) does not seem to have any effect. Once I accept the drag setting I can’t seem to change the feedback type.

Just to make it clear: the area that the user should be able to put down is not a component or even a display object, in fact they are just the range in the text of the text field (such as selection) If they are their own components I can solve it by letting each of them accept the drag event individually. I think I can create a proxy component floating on the text to simulate it, but if it is not necessary, I would rather not do it .

I have managed to make it work in AIR and browsers now, but can only put the proxy component above the text range, you should be able to discard things. This way I get the correct feedback, and The descent is automatically cancelled at the drag exit.

This is the strangest thing about D&D in AIR:

DragManager.doDrag(initiator, source, event, dragImage, offsetX, offsetY);

In browser-based Flex, offsetX and offsetY should be negative numbers (so say the document, it works fine). However, it works exactly the same in AIR The code must make the offset positive. The same number but positive. This is very, very strange.

I have tested more and how @maclema works, but if you are in AIR It doesn’t work in AIR. It seems that drag and drop in AIR is different. It’s really weird, because not only the feedback is not displayed correctly, and it’s impossible not to accept it, but the coordinates are also completely closed. I’m just in the browser instead of AIR. Trying my app, drag and drop is completely broken.

Also, skipping the dragEnter handler works well in AIR, but it breaks everything when running in the browser.

p>

Do you only use the dragEnter method? If you try to refuse the drag while still dragging the same component, you need to use the dragEnter and dragOver methods at the same time.

Look at this example:




import mx.core.DragSource;
import mx.managers.DragManager;
import mx. events.DragEvent;

private function onDragEnter(e:DragEvent):void {
if (e.target == lbl) {

if (e.localX trace("accept");
DragManager.acceptDragDrop(this);
}
else {
DragManager.acceptDragDrop(null );
}
}
}

private function doStartDrag(e:MouseEvent):void {
if (e.buttonDown) {
var ds:DragSource = new DragSource();
ds.addData("test", "text");

DragManager.doDrag(btn, ds, e);
}
}
]]>



Leave a Comment

Your email address will not be published.