Drag and drop objects appears in the other scenes. Please help.
Copy link to clipboard
Copied
i'm trying to make a drag and drop game for my assignment. but i'm having some issues. My game have one home page and three game level. The drag and drop is functioning well. when i drag any object and go to other level or home page, the object i dragged will appear on that page. i have four objects in each level, if i drag all or any of the objects, the objects will appear in all other pages. Sometime the exit button in the home page also disappear.
In this Image you can see i dragged all the animals to its target place.
Now I navigated to home page, and the animals that i dragged all appeared here and same thing happening in all other pages
This is the link of my file.
https://drive.google.com/file/d/10jGkVmQV5s5ZecWLig0Veo0oT2Qk9uKh/view?usp=sharing
This is my code below.
stop();
//navigation
HOME2_btn.addEventListener(MouseEvent.CLICK, HOME2Shoot);
function HOME2Shoot(event:MouseEvent):void
{
gotoAndStop(1,"HOME PAGE");
}
FRONT2_btn.addEventListener(MouseEvent.CLICK, FRONT2Shoot);
function FRONT2Shoot(event:MouseEvent):void
{
gotoAndStop(1,"LEVEL 3");
}
BACK2_btn.addEventListener(MouseEvent.CLICK, BACK2Shoot);
function BACK2Shoot(event:MouseEvent):void
{
gotoAndStop(1,"LEVEL 1");
}
/*
RELOAD2_btn.addEventListener(MouseEvent.CLICK, RELOAD2Shoot);
function RELOAD2Shoot(event:MouseEvent):void
{
gotoAndStop(1,"LEVEL 2");
}
*/
// Musics
HOME2_btn.addEventListener(MouseEvent.CLICK, HOME2Sound);
function HOME2Sound(event:MouseEvent)
{
var mySound:ButtonClick = new ButtonClick();
var myChannel:SoundChannel = mySound.play();
}
FRONT2_btn.addEventListener(MouseEvent.CLICK, FRONT2Sound);
function FRONT2Sound(event:MouseEvent)
{
var mySound:ButtonClick = new ButtonClick();
var myChannel:SoundChannel = mySound.play();
}
BACK2_btn.addEventListener(MouseEvent.CLICK, BACK2Sound);
function BACK2Sound(event:MouseEvent)
{
var mySound:ButtonClick = new ButtonClick();
var myChannel:SoundChannel = mySound.play();
}
// drag & drop
var orig1A:Number=Rabbit_mc.x;
var orig1Aa:Number=Rabbit_mc.y;
var orig2B:Number=Horse_mc.x;
var orig2Bb:Number=Horse_mc.y;
var orig3C:Number=Cat_mc.x;
var orig3Cc:Number=Cat_mc.y;
var orig4D:Number=Dog_mc.x;
var orig4Dd:Number=Dog_mc.y;
Rabbit_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheFood);
Rabbit_mc.addEventListener(MouseEvent.MOUSE_UP, item1Release);
Horse_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheFood);
Horse_mc.addEventListener(MouseEvent.MOUSE_UP, item2Release);
Cat_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheFood);
Cat_mc.addEventListener(MouseEvent.MOUSE_UP, item3Release);
Dog_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheFood);
Dog_mc.addEventListener(MouseEvent.MOUSE_UP, item4Release);
Reload2_btn.addEventListener(MouseEvent.CLICK, reset2);
Rabbit_mc.buttonMode=true;
Horse_mc.buttonMode=true;
Cat_mc.buttonMode=true;
Dog_mc.buttonMode=true;
function dragTheFood(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.currentTarget);
item.startDrag();
var topPos:uint=this.numChildren-1;
this.setChildIndex(item, topPos);
}
function item1Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.currentTarget);
item.stopDrag();
if (CarrotZone_mc.hitTestPoint(item.x,item.y)) {
item.x=CarrotZone_mc.x;
item.y=CarrotZone_mc.y;
}
else {
item.x=orig1A;
item.y=orig1Aa;
}}
function item2Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.currentTarget);
item.stopDrag();
if (GrassZone_mc.hitTestPoint(item.x,item.y)) {
item.x=GrassZone_mc.x;
item.y=GrassZone_mc.y;
}
else {
item.x=orig2B;
item.y=orig2Bb;
}}
function item3Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.currentTarget);
item.stopDrag();
if (FishZone_mc.hitTestPoint(item.x,item.y)) {
item.x=FishZone_mc.x;
item.y=FishZone_mc.y;
} else {
item.x=orig3C;
item.y=orig3Cc;
}}
function item4Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.currentTarget);
item.stopDrag();
if (MeatZone_mc.hitTestPoint(item.x,item.y)) {
item.x=MeatZone_mc.x;
item.y=MeatZone_mc.y;
} else {
item.x=orig4D;
item.y=orig4Dd;
}}
function reset2(event:MouseEvent):void {
Rabbit_mc.x=orig1A;
Rabbit_mc.y=orig1Aa;
Horse_mc.x=orig2B;
Horse_mc.y=orig2Bb;
Cat_mc.x=orig3C;
Cat_mc.y=orig3Cc;
Dog_mc.x=orig4D;
Dog_mc.y=orig4Dd;
}
function FoodRelease(event:MouseEvent):void {
var thisItem:MovieClip = MovieClip(event.currentTarget);
thisItem.stopDrag();
if (FishZone_mc.hitTestPoint(thisItem.x,thisItem.y)) {
thisItem.x = FishZone_mc.x;
thisItem.y = FishZone_mc.y;
}
else if (MeatZone_mc.hitTestPoint(thisItem.x,thisItem.y)) {
thisItem.x = MeatZone_mc.x;
thisItem.y = MeatZone_mc.y;
}
else if (CarrotZone_mc.hitTestPoint(thisItem.x,thisItem.y)) {
thisItem.x = CarrotZone_mc.x;
thisItem.y = CarrotZone_mc.y;
}
else if (thisItem==Rabbit_mc) {
event.currentTarget.x = orig1A;
event.currentTarget.y = orig1Aa;
}
else if (thisItem==Horse_mc) {
event.currentTarget.x = orig2B;
event.currentTarget.y = orig2Bb;
}
else {
event.currentTarget.x = orig3C;
event.currentTarget.y = orig3Cc;
}}
Copy link to clipboard
Copied
use removeChild to remove previously dropped items when you go to your other scene. eg call:
function removeObjectF(object:DisplayObject):void{
if(object.stage){
object.parent.removeChild(object);
}
}

