Xenozip
09-27-2003, 11:40 PM
I'm trying to create a puzzle-style flash game that involves 5 pieces and 5 targets. I plan on adding more pieces and targets later.
I also want a dynamic text to display weather the piece was placed in the right spot or not. Actually, I want the target movie clips to advance a frame if the piece is in the correct spot, and to advance two frames if it's not. However, a dynamic text is fine for now.
I've looked through the sample quizes and the actionscript tutorial puzzle for help on how to make a puzzle. I also checked the drag&drop tutorials located on this site. Still, I seem to be advancing very slowly, and now I'm totally stuck.
Here's what I have so far :
// Actions for Frame 1 (main timeline)
function strDrag(whichP) {
xCor = _root[whichP]._x;
yCor = _root[whichP]._y;
startDrag(_root[whichP], true, 31, 31, 450, 350);
}
function sNap(whichP) {
stopDrag();
if (eval(_root[whichP]._droptarget) == _root.B1) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else if (eval(_root[whichP]._droptarget) == _root.B2) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else if (eval(_root[whichP]._droptarget) == _root.B3) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else if (eval(_root[whichP]._droptarget) == _root.B4) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else if (eval(_root[whichP]._droptarget) == _root.B5) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else {
_root[whichP]._x = xCor;
_root[whichP]._y = yCor;
}
}
function checkIt(whichP) {
testTxt = "x"+eval(_root[whichP]._droptarget)._x;
testTwo = "y"+eval(_root[whichP]._droptarget)._y;
if (_root[whichP]._x == 440 && _root[whichP]._y == 40) {
if (_root[whichP]._name=P1) {
anS = "P1 is on B1!";
}
if (_root[whichP]._name != P1) {
anS = "Incorrect placement!";
}
}
}
I have one piece currently set up in the main timeline that is an MC named "P1", inside that clip is another movieclip "Piece Actions".
// Actions for "Piece Actions" MC located in "P1" MC
_visible = false;
_parent.onPress = function() {
_root.strDrag(_parent._name);
};
_parent.onRelease = function() {
_root.sNap(_parent._name);
_root.checkIt(_parent._name);
};
The puzzle will snap the piece back to its original position if the piece is not dropped on a target.
If the piece is dropped on any of the targets 2-5, the clip will react like it's supposed to by displaying the current pieces _x and _y positions, however the "incorrect" will not display. Also, if the piece is placed on Target1, the text will display properly (both "P1 is on B1" and the _x and _y positions). After that, however, if I click anywhere in the movie, the entire thing will attempt to drag.
If I remove the last few lines of code :
// Last few lines of code in main timeline (within checkIt() function)
if (_root[whichP]._x == 440 && _root[whichP]._y == 40) {
if (_root[whichP]._name=P1) {
anS = "P1 is on B1!";
}
if (_root[whichP]._name != P1) {
anS = "Incorrect placement!";
}
}
The clip will then work perfectly fine.
It's only untill I add that If/Then statement that the whole thing goes haywire.
I attached the FLA. I could really use any suggestions on how to get it to work.
That last If/Then statement is supposed to make it so that if Piece1 is on Target1, the dynamic text will display that information, otherwize if Piece1 is not on Target1, the dynamic text will display "Incorrect".
I really would appreciate some help here (I'm totally stumped).
I also want a dynamic text to display weather the piece was placed in the right spot or not. Actually, I want the target movie clips to advance a frame if the piece is in the correct spot, and to advance two frames if it's not. However, a dynamic text is fine for now.
I've looked through the sample quizes and the actionscript tutorial puzzle for help on how to make a puzzle. I also checked the drag&drop tutorials located on this site. Still, I seem to be advancing very slowly, and now I'm totally stuck.
Here's what I have so far :
// Actions for Frame 1 (main timeline)
function strDrag(whichP) {
xCor = _root[whichP]._x;
yCor = _root[whichP]._y;
startDrag(_root[whichP], true, 31, 31, 450, 350);
}
function sNap(whichP) {
stopDrag();
if (eval(_root[whichP]._droptarget) == _root.B1) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else if (eval(_root[whichP]._droptarget) == _root.B2) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else if (eval(_root[whichP]._droptarget) == _root.B3) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else if (eval(_root[whichP]._droptarget) == _root.B4) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else if (eval(_root[whichP]._droptarget) == _root.B5) {
_root[whichP]._x = eval(_root[whichP]._droptarget)._x;
_root[whichP]._y = eval(_root[whichP]._droptarget)._y;
} else {
_root[whichP]._x = xCor;
_root[whichP]._y = yCor;
}
}
function checkIt(whichP) {
testTxt = "x"+eval(_root[whichP]._droptarget)._x;
testTwo = "y"+eval(_root[whichP]._droptarget)._y;
if (_root[whichP]._x == 440 && _root[whichP]._y == 40) {
if (_root[whichP]._name=P1) {
anS = "P1 is on B1!";
}
if (_root[whichP]._name != P1) {
anS = "Incorrect placement!";
}
}
}
I have one piece currently set up in the main timeline that is an MC named "P1", inside that clip is another movieclip "Piece Actions".
// Actions for "Piece Actions" MC located in "P1" MC
_visible = false;
_parent.onPress = function() {
_root.strDrag(_parent._name);
};
_parent.onRelease = function() {
_root.sNap(_parent._name);
_root.checkIt(_parent._name);
};
The puzzle will snap the piece back to its original position if the piece is not dropped on a target.
If the piece is dropped on any of the targets 2-5, the clip will react like it's supposed to by displaying the current pieces _x and _y positions, however the "incorrect" will not display. Also, if the piece is placed on Target1, the text will display properly (both "P1 is on B1" and the _x and _y positions). After that, however, if I click anywhere in the movie, the entire thing will attempt to drag.
If I remove the last few lines of code :
// Last few lines of code in main timeline (within checkIt() function)
if (_root[whichP]._x == 440 && _root[whichP]._y == 40) {
if (_root[whichP]._name=P1) {
anS = "P1 is on B1!";
}
if (_root[whichP]._name != P1) {
anS = "Incorrect placement!";
}
}
The clip will then work perfectly fine.
It's only untill I add that If/Then statement that the whole thing goes haywire.
I attached the FLA. I could really use any suggestions on how to get it to work.
That last If/Then statement is supposed to make it so that if Piece1 is on Target1, the dynamic text will display that information, otherwize if Piece1 is not on Target1, the dynamic text will display "Incorrect".
I really would appreciate some help here (I'm totally stumped).