movieClip.currentFrame traces to a different frame than it's displaying
I'm xposting this from the AS3 forum because I'm not quite sure where it belongs.
I have a movieclip on the stage with 3 frames. Each frame has a stop(); in the actions layer. I have double (and triple and quadruple) checked the label names.
There is a button to toggle between the three frames of the movie clip. A Frame 1 button, a Frame 2 button, and a Frame 3 button. The movie clip (there are lots of them) is then spawned with a mouse click. The movie clips are already declared at the beginng. They are not unlimited so I can just have a for loop go through all of them and change the frame number even before they are spawned and added to the display list.
Frame 2 and Frame 3 work just fine. But the button to go to Frame 1 will display Frame 1 on all of the pieces that are already on the stage, but on all new pieces that will be spawned, it just displays whatever other button was pressed last. For instance if I have a movie clip on the stage that's displaying Frame 2 and I hit the buttom for Frame 1, the movie clip will switch to Frame 1. But if I spawn a new movie clip, it will display Frame 2. If I then click back on the Frame 2 button and then again to Frame 1, the movie clip will correct itself.
I can't find where on earth in the code it's going wrong. I've tried using traces but I can't find any problems or inconsistencies. Everywhere I put a trace to tell me what frame the object is at, it traces correctly. I'll click on Frame 1 button, then click on the stage, and it will trace to the output menu that the current spawned movie clip is on Frame 1 when it's very clearly displaying Frame 2.
Does that make any sense?
Here is the code that spawns the movie clip:
ri = Math.floor(Math.random()*(1+PuzzleGlobals.TOTAL_NUMBER_USA));
if (PuzzleGlobals.statesOnBoardUSA == PuzzleGlobals.TOTAL_NUMBER_USA) {
//play BOOP sound indicating no new pieces left
}
else {
if (usaPiece[ri] != null) {
bmc.addChild(this[usaPiece[ri]]); //bmc is the blank movie clip all new spawns are attached to
trace (this[usaPiece[ri]].currentFrame + this[usaPiece[ri]].currentFrameLabel); // 1shape, but displaying 2
if (PuzzleGlobals.currentLevel == "Shape") {
trace (this[usaPiece[ri]].currentFrame + this[usaPiece[ri]].currentFrameLabel); // 1shape, but displaying 2
this[usaPiece[ri]].height = this[usaPuzzle[ri]].height; //this is to match the size of the puzzle pieces
this[usaPiece[ri]].width = this[usaPuzzle[ri]].width;
}
this[usaPiece[ri]].x = e.stageX;
this[usaPiece[ri]].y = e.stageY;
usaPiece[ri] = null;
PuzzleGlobals.statesOnBoardUSA++;
}
else {
addNewPiece(e);
}
}
}
Here is the code for the button switches:
nameLevel.addEventListener(MouseEvent.CLICK, changeLevel);
abbrevLevel.addEventListener(MouseEvent.CLICK, changeLevel);
shapeLevel.addEventListener(MouseEvent.CLICK, changeLevel);
function changeLevel (e:MouseEvent): void {
trackUSAPiece = ["pieceAL", "pieceAK", "pieceAZ", "pieceAR", "pieceCA", "pieceCO", "pieceCT", "pieceDE", "pieceFL", "pieceGA", "pieceHI", "pieceID", "pieceIL", "pieceIN", "pieceIA", "pieceKS", "pieceKY", "pieceLA", "pieceME", "pieceMD", "pieceMA", "pieceMI", "pieceMN", "pieceMS", "pieceMO", "pieceMT", "pieceNE", "pieceNV", "pieceNH", "pieceNJ", "pieceNM", "pieceNY", "pieceNC", "pieceND", "pieceOH", "pieceOK", "pieceOR", "piecePA", "pieceRI", "pieceSC", "pieceSD", "pieceTN", "pieceTX", "pieceUT", "pieceVT", "pieceVA", "pieceWA", "pieceWV", "pieceWI", "pieceWY"]
if (e.target == nameLevel) {
PuzzleGlobals.currentLevel = "Name";
nameLevel.gotoAndStop("Active"); //change appearance of the buttons
abbrevLevel.gotoAndStop("Inactive");
shapeLevel.gotoAndStop("Inactive");
for (var j=0; j<(PuzzleGlobals.TOTAL_NUMBER_USA); j++) { //make all declared movie clips go to the right frame
this[trackUSAPiece
}
}
else if (e.target == abbrevLevel) {
PuzzleGlobals.currentLevel = "Abbrev";
abbrevLevel.gotoAndStop("Active");
nameLevel.gotoAndStop("Inactive");
shapeLevel.gotoAndStop("Inactive");
for (var k=0; k<(PuzzleGlobals.TOTAL_NUMBER_USA); k++) {
this[trackUSAPiece
}
}
else if (e.target == shapeLevel) {
PuzzleGlobals.currentLevel = "Shape";
shapeLevel.gotoAndStop("Active");
nameLevel.gotoAndStop("Inactive");
abbrevLevel.gotoAndStop("Inactive");
for (var l=0; l<(PuzzleGlobals.TOTAL_NUMBER_USA); l++) {
this[trackUSAPiece
}
}
}
Thanks so much! ![]()
Amber
