Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Flash: Stop motion blocks gotoAndPlay

  1. Sep 5, 2008 #1
    I think I found a bug in Flash. It spans from CS3 to MX and perhaps earlier.

    I did a stop motion animation of me turning the pages of a scrap book (frames of a video recording). Then I put labels on each frame where a page is completely turned and did some actionscript (gotoAndPlay) so that I can choose from which page to start and to which page to arrive.

    The problem is that gotoAndPlay does not actually go to the required frame. Instead it goes through all frames and only after that will the play head go to that frame. This only happens when images are used, when flash drawings are used, it will works just fine. And the weird thing is that when only the first half of the key frames between labeled frames are used, it works just fine.

    Here's the fla file (flash 08): http://rapidshare.com/files/141420616/scrapbook.fla.html

    Here's how it works:
    Layer 'code' contains actionscript and labels, layer 'animation' contains the stop motion pictures.
    First frame of layer 'code' contains 2 variable initializations. currState holds the current page of the scrapbook and nextState holds the destination page (both zero based). There are 3 pages in all. A switch statement makes a gotoAndPlay to the required frame depending on currState (this is the part which doesn't work).
    After the play head is on the frame with the start page, each labeled frame will contain actionscript to check if nextState matches the page on that frame and execute stop() if so.

    I hope this is enough information to help you. If you need anything else just ask.
    Last edited by a moderator: Apr 23, 2017
  2. jcsd
  3. Sep 7, 2008 #2


    User Avatar
    Science Advisor

    This behavior is not exactly a bug, it happens because when the code in your first frame gets executed the remaining frames (which contain large images) haven't yet loaded. What ends up happening is that, your gotoAndPlay call will fail (flash hasn't yet loaded the named frame) and movie will continue to play. The movie continues to play because that's the default behavior - when the movie starts it will play unless you have a stop() action in the first frame - and also because gotoAndPlay calls play().

    You can fix this first by putting a stop action in your first frame and then moving your switch statement into the onEnterFrame event which gets executed a few times a second. Inside that event you'd check to see if the movie has finished loading and only then let control go to the switch statement. Try putting the following code in the first frame:
    Code (Text):

    currState = 2;
    nextState = 2;
    _root.onEnterFrame = function(){
        if(_root.getBytesLoaded() >= _root.getBytesTotal()){
            switch (_root.currState) {
                case 0: gotoAndPlay("closed"); break;
                case 1: gotoAndPlay("page1"); break;
                case 2: gotoAndPlay("page2"); break;
                case 3: gotoAndPlay("page3"); break;
                    throw "error";
            _root.onEnterFrame = null;
  4. Sep 8, 2008 #3
    It works!! Now why would that happen if I'm not using simulate download?

    Thanks sooooo much! I've posted this on 4 foraa and this is the only one I got an answer from... PF rulez!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Flash: Stop motion blocks gotoAndPlay
  1. XHTML (Flash) (Replies: 2)