拖放对象出现在其他场景中

时间:2019-06-24 05:52:08

标签: actionscript-3

我正在尝试为我的任务做一个拖放游戏。但我有一些问题。我的游戏有一个主页和三个游戏级别。拖放功能运行良好。当我拖动任何对象并转到其他级别或主页时,我拖动的对象将出现在该页面上。我在每个级别中都有四个对象,如果我拖动所有或任何对象,则这些对象将出现在所有其他页面中。有时主页上的退出按钮会消失。

这是我文件的链接 https://drive.google.com/open?id=10jGkVmQV5s5ZecWLig0Veo0oT2Qk9uKh

这是我的以下代码。我只上传了拖放部分。

// 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;

}}

I dragged all the animals to its target place.

I navigated to home page, and the animals that i dragged all appeared here and same thing happening in all other pages.

0 个答案:

没有答案