• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Drag and drop matching game... again (sorry)!

Participant ,
Feb 15, 2017 Feb 15, 2017

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:

Capture1.PNG

This shows the object staying on the main menu:

Capture2.PNG

Thanks,

Jack

Views

311

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Participant , Feb 16, 2017 Feb 16, 2017

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!

Votes

Translate

Translate
LEGEND ,
Feb 15, 2017 Feb 15, 2017

Copy link to clipboard

Copied

Post your drag start code.

Also fix that "requiured".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 15, 2017 Feb 15, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 15, 2017 Feb 15, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 15, 2017 Feb 15, 2017

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Feb 16, 2017 Feb 16, 2017

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines