Copy link to clipboard
Copied
Hello, I'm making a game in which I have some drag and drop items that they can be multiplied as many as you want. This items have to stay in the scene and I also have a bin in the menu where If you drag them they have to disappear.The problem is that I tried with multiple coordinates and they disappear also in the scene in the moment that I'm dragging them out of the menu. So, my question is:What could be wrong? Is the issue in the code?
Thank you for taking the time to help me. It's my first game in AS3 so I'm not so familiar with the codes.
import flash.display.Sprite;
import flash.events.MouseEvent;
DDB1.addEventListener(MouseEvent.MOUSE_DOWN, createDDB1);
var _DDB1:Sprite;
function createDDB1(evt:MouseEvent){
_DDB1 = new DDB1MC();
_DDB1.x = evt.stageX;
_DDB1.y = evt.stageY;
_DDB1.rotation = evt.currentTarget.rotation;
_DDB1.transform.colorTransform = evt.currentTarget.transform.colorTransform
addChild(_DDB1);
_DDB1.startDrag(false);
_DDB1.addEventListener(MouseEvent.MOUSE_DOWN, dragDDB1);
stage.addEventListener(MouseEvent.MOUSE_UP, dropDDB1);
}
function dragDDB1(evt:MouseEvent){
evt.stopPropagation();
_DDB1 = evt.currentTarget as Sprite;
_DDB1.startDrag(false);
stage.addEventListener(MouseEvent.MOUSE_UP, dropDDB1);
}
function dropDDB1(e:MouseEvent):void {
_DDB1.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP,dropDDB1);
if (_DDB1.x>700 || _DDB1.x < 755 || _DDB1.y < 240 || _DDB1.y > 155) {
_DDB1.removeEventListener(MouseEvent.MOUSE_DOWN, dragDDB1);
_DDB1.parent.removeChild(_DDB1);
}
_DDB1 = null;
}
Chances are that the problem lies in the following line:
if (_DDB1.x>700 || _DDB1.x < 755 || _DDB1.y < 240 || _DDB1.y > 155) {
That line essentially says if(the object is anywhere) due to using the OR ( || ) operator. If any one of those things is true then the condition is satisfied, which becxause they overlap will always be true for at least two of them. If that is supposed to be restricting the object to within an area you likely want to all of those conditions to be satsified. So in that
...Copy link to clipboard
Copied
Chances are that the problem lies in the following line:
if (_DDB1.x>700 || _DDB1.x < 755 || _DDB1.y < 240 || _DDB1.y > 155) {
That line essentially says if(the object is anywhere) due to using the OR ( || ) operator. If any one of those things is true then the condition is satisfied, which becxause they overlap will always be true for at least two of them. If that is supposed to be restricting the object to within an area you likely want to all of those conditions to be satsified. So in that case you need to use the AND operator ( && ).
Copy link to clipboard
Copied
It worked, thank you so much !
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now