Skip to main content
Inspiring
August 29, 2011
Question

movieClip.currentFrame traces to a different frame than it's displaying

  • August 29, 2011
  • 1 reply
  • 769 views

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:

function addNewPiece (e:MouseEvent): void {
    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].gotoAndStop("wholeName");
        }
    }
    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].gotoAndStop("abbrev");
        }
    }
    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].gotoAndStop("shape");
        }
    }
}

Thanks so much!

Amber

This topic has been closed for replies.

1 reply

Leafcutter
Inspiring
August 29, 2011

This isn't necessarily an answer to why but I have coincidentally had a similar problem this morning with moving between frames of an embedded swf file.

I have an actionscript only project with a swf file embedded using [Embed....].  The swf file has 30+ frames and each frame has symbols exported for actionscript.

When I use gotoAndStop() to move between frames I found that sometimes the correct frame is displayed and sometimes it isn't.  When it isn't displayed correctly the child objects in the frame are also incorrect.  If I loop through all the child objects I started seeing children from other frames.  Once it has failed to display correctly then it subsequently fails every time.

I gave up trying to put the movie clip into the display and instead pre processed it at the start of my project.  I took a copy of the graphics using a bitmapData.draw() and got all the information I needed from the child objects and stored in another data structure.  This seems to work fine so I surmised that it might be a bug and that the problem happens when you display the movie clip and then try and move between frames using gotoAndStop.  It would be interesting to know if anyone has had similer problems with movieclips.

AmbariAuthor
Inspiring
August 29, 2011

As the vectors inside my movie clips are all very complex, using a bitmap draw won't work (unless I am completely not understand your solution, lol).

I think I will file a bug report with Adobe and see if it really is a bug. Thanks!

AmbariAuthor
Inspiring
August 30, 2011

Bug report here in case someone thinks they know what's wrong

https://bugbase.adobe.com/index.cfm?event=bug&id=2953829