Skip to main content
Inspiring
February 10, 2017
Answered

Draggable object back to original position when already there is an object at the drop area.

  • February 10, 2017
  • 1 reply
  • 599 views

I'm a newbie about flash, especially actionscript.

So the scenario is something like: I have 3 pairs of shoes, 2 ties, and 4 scouts.

I already made the 3 pairs of shoes and 2 ties draggable to any scouts (as the drop area).

But the problem is, I want to make it clear, that the user only may put a pair of shoes and a tie on 1 scout.

Because what I have now is, when already exist a pair of shoes and a tie on a scout, the user still can drop other on it.

Please help me, I've been surfing through internet and many forums but still can't solve this one. Many thanks before.

Here is my code for one of my movie clip

on (press)

{

  if (!this.isLocked)

  startDrag(this);

}

on (release) {stopDrag();

if(this._droptarget=="/anak1")

{

  this._x=193,75;

  this._y=358,90;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

}

else if(this._droptarget=="/anak2")

{

  this._x=324,25;

  this._y=358,90;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

}

else if(this._droptarget=="/anak3")

{

  this._x=453,75;

  this._y=358,90;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

}

else{

  this._x=600,20;

  this._y=342,8;

}

}

This topic has been closed for replies.
Correct answer ratna_282017

Solved!

I hope this help for you who has the same problem.

anak1,2,3 is the instance name for the scouts.

dasianak1 is a var that happen when already there exist a tie in scout 1 (anak1), and so on to 2,3

on (press)

{

  if (!this.isLocked)

  startDrag(this);

}

on (release)

{

stopDrag();

if(this._droptarget=="/anak1" && _parent.dasianak1 == false)

{

  this._x=216;

  this._y=401,95;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

  _parent.dasianak1 = true;

}

else if(this._droptarget=="/anak1" && _parent.dasianak1 == true)

{

  this._x=925,50;

  this._y=408,95;

}

else if(this._droptarget=="/anak2" && _parent.dasianak2 == false)

{

  this._x=346;

  this._y=401,95;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

  _parent.dasianak2 = true;

}

else if(this._droptarget=="/anak2" && _parent.dasianak2 == true)

{

  this._x=925,50;

  this._y=408,95;

}

else if(this._droptarget=="/anak3" && _parent.dasianak3 == false)

{

  this._x=476;

  this._y=401,95;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

  _parent.dasianak3 = true;

}

else if(this._droptarget=="/anak3" && _parent.dasianak3 == true)

{

  this._x=925,50;

  this._y=408,95;

}

else

{

  this._x=925,50;

  this._y=408,95;

}

}

1 reply

ratna_282017AuthorCorrect answer
Inspiring
February 18, 2017

Solved!

I hope this help for you who has the same problem.

anak1,2,3 is the instance name for the scouts.

dasianak1 is a var that happen when already there exist a tie in scout 1 (anak1), and so on to 2,3

on (press)

{

  if (!this.isLocked)

  startDrag(this);

}

on (release)

{

stopDrag();

if(this._droptarget=="/anak1" && _parent.dasianak1 == false)

{

  this._x=216;

  this._y=401,95;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

  _parent.dasianak1 = true;

}

else if(this._droptarget=="/anak1" && _parent.dasianak1 == true)

{

  this._x=925,50;

  this._y=408,95;

}

else if(this._droptarget=="/anak2" && _parent.dasianak2 == false)

{

  this._x=346;

  this._y=401,95;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

  _parent.dasianak2 = true;

}

else if(this._droptarget=="/anak2" && _parent.dasianak2 == true)

{

  this._x=925,50;

  this._y=408,95;

}

else if(this._droptarget=="/anak3" && _parent.dasianak3 == false)

{

  this._x=476;

  this._y=401,95;

  var efeksound:Sound = new Sound();

  efeksound.attachSound("plopp");

  efeksound.start();

  var isLocked = true;

  _parent.dasianak3 = true;

}

else if(this._droptarget=="/anak3" && _parent.dasianak3 == true)

{

  this._x=925,50;

  this._y=408,95;

}

else

{

  this._x=925,50;

  this._y=408,95;

}

}