简体   繁体   English

拖放项目到位后如何隐藏它们

[英]How can I hide drag and drop items once they have been dragged into place

I have made a flash application and in this flash application I have included a jigsaw puzzle. 我制作了一个Flash应用程序,并且在此Flash应用程序中包含了一个拼图游戏。 The application is wrote on one timeline and certain frames are used as different pages within the application. 该应用程序写在一个时间轴上,并且某些帧用作应用程序内的不同页面。

The problem is once the jigsaw drag and drop are moved the pieces are displayed on all frames instead of just the one jigsaw puzzle frame I created. 问题是一旦移动了拼图拖放操作,碎片就会显示在所有框架上,而不仅仅是我创建的一个拼图框架。

How can I make these drag and drop items not be shown on the other frames? 如何使这些拖放项目不显示在其他框架上?

Here is the code I have used for the jigsaw puzzle. 这是我用于拼图的代码。

var hitArray:Array = new Array(Tar1_mc,Tar2_mc,Tar3_mc,Tar4_mc,Tar5_mc,Tar6_mc);
var dropArray:Array = new Array(Piece1_mc,Piece2_mc,Piece3_mc,Piece4_mc,Piece5_mc,Piece6_mc);
var positionsArray:Array = new Array();

for (var i:int = 0; i < dropArray.length; i++)
{
dropArray[i].buttonMode = true;
dropArray[i].addEventListener(MouseEvent.MOUSE_DOWN, mdown);
dropArray[i].addEventListener(MouseEvent.MOUSE_UP, mUp);
positionsArray.push({xPos:dropArray[i].x, yPos:dropArray[i].y});
}
function mdown(e:MouseEvent):void
{
e.currentTarget.startDrag();
setChildIndex(MovieClip(e.currentTarget), numChildren - 1);
}
function mUp(e:MouseEvent):void
{
var dropIndex:int = dropArray.indexOf(e.currentTarget);
var target:MovieClip = e.currentTarget as MovieClip;
target.stopDrag();
if (target.hitTestObject(hitArray[dropIndex]))
{
    target.x = hitArray[dropIndex].x;
    target.y = hitArray[dropIndex].y;
}
else
{
    target.x = positionsArray[dropIndex].xPos;
    target.y = positionsArray[dropIndex].yPos;
}
}
reset_btn.addEventListener(MouseEvent.CLICK, backObjects);
function backObjects(e:MouseEvent):void
{   for(var i:int = 0; i < dropArray.length; i++){      
    if(dropArray[i].x == hitArray[i].x && dropArray[i].y == hitArray[i].y){         
        dropArray[i].x = positionsArray[i].xPos;
        dropArray[i].y = positionsArray[i].yPos;      
    }   
}
}

Thank you in advance for any help provided. 预先感谢您提供的任何帮助。

You should really try and use external classes when creating games. 在创建游戏时,您应该真正尝试并使用外部类。 But to fix your problem you can remove the pieces from the stage when you go to a certain frame. 但是要解决您的问题,您可以在移至特定框架时从舞台上取下碎片。 So in the frame you want them to dissapear you could write the following: 因此,在框架中您希望他们消失,您可以编写以下内容:

for(var i:int = 0; i < dropArray.length; i++){
    if(this != null && this.contains(dropArray[i])){
     removeChild(dropArray[i]);
    }
}

if you need to come back to this frame however, you could toggle the visiblabilty property of each puzzle piece. 但是,如果您需要回到此框架,则可以切换每个拼图的可见性属性。 you would loop through but would just change the visibilty like so: 您会循环浏览,但只会更改可见性,如下所示:

dropArray[i].visible = false;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM