Copy link to clipboard
Copied
Hi all,
I was hoping not to post about this again, but trouble has hit again.
On the matching game, when the user matches 2 objects and then presses the back button to go to the main menu, the draggable object stays on the screen.
I thought of removing the event listener but this is already done in the code!
Does anyone know how to stop the object from staying on screen?
This shows the object being matched:
This shows the object staying on the main menu:
Thanks,
Jack
I've made a quick fix.
When the frame loads, all of the objects are made visible and when the back button is pressed I've made them invisible.
Perfecto!
Copy link to clipboard
Copied
Post your drag start code.
Also fix that "requiured".
Copy link to clipboard
Copied
Firstly, well noticed on the bad spelling
So to pickup an object;
function pickupObject(event: MouseEvent): void {
event.currentTarget.startDrag();
event.currentTarget.parent.addChild(event.currentTarget);
objectoriginalX = event.currentTarget.x;
objectoriginalY = event.currentTarget.y;
}
To drop an object;
function dropObject(event: MouseEvent): void {
event.currentTarget.stopDrag();
var matchingTargetName: String = "target" + event.currentTarget.name;
var matchingTarget: DisplayObject = getChildByName(matchingTargetName);
if (event.currentTarget.dropTarget != null && event.currentTarget.dropTarget.parent == matchingTarget) {
event.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);
event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, dropObject);
event.currentTarget.buttonMode = false;
event.currentTarget.x = matchingTarget.x;
event.currentTarget.y = matchingTarget.y;
} else {
event.currentTarget.x = objectoriginalX;
event.currentTarget.y = objectoriginalY;
}
}
Thanks
Copy link to clipboard
Copied
Are you sure you shouldn't be using target instead of currentTarget? I'm no AS3 expert, but that event.currentTarget.parent.addChild(event.currentTarget); line may be ripping the drags out of their container, which would explain why they're not going away.
Copy link to clipboard
Copied
Just tried this and it's still having the same problem;
event.target.parent.addChild(event.currentTarget);
event.target.parent.addChild(event.target);
event.currentTarget.parent.addChild(event.target);
And I tried taking all currentTarget's out, replacing with target and that's not done anything.
PS: I don't know what I should be using, it was suggested by another forum member. I don't know the difference, though I have since googled it but I still don't know
Copy link to clipboard
Copied
I've made a quick fix.
When the frame loads, all of the objects are made visible and when the back button is pressed I've made them invisible.
Perfecto!