I have made a flash application and in this flash application I have included a jigsaw puzzle. 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:
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: