8 Replies Latest reply on Jun 14, 2006 12:44 PM by Newsgroup_User

    Sequentially playing library movie clips

    btkenney
      greetings,

      i am looking for a simple solution to what seems like a simple problem. i have no code to show but i can explain the situation easily.

      i have 10 movie clips sitting in the library of the main movie. i create an empty movie clip programatically (this.createEmptyMovieClip).

      i use attach movie to load the first movie clip call it "mcBox" into the empty movie clip on stage.

      here is where i run into problems. i wish to evaluate the _currentframe and _totalframes of mcBox so when they equal each other to unload mcBox and load the next movie clip.

      thus all the movies would follow each other sequentially. i originally used onEnterFrame to evaluate currentframe and totalframe but could not get the next movieclip to attach and play. I hardcoded the effort but to no avail.

      could someone suggest a good way to achieve sequential play of movie clips from the library?! Basically i want one to play right after the other. just some pointers would be great.
        • 1. Re: Sequentially playing library movie clips
          2m Level 2
          I'd say you are very far in the right direction - if not allready there. It seems you must have made a mistake in the actual implementation as the concept should work. I don't know why you wouldn't attache more code, but that would help solving the problem.
          • 2. Re: Sequentially playing library movie clips
            Wolf_van_Ween Level 1
            You did the right thing it seems. Your problem might stem from the fact that _totalframes is unknown until the movie clip is fully loaded. If you use the MovieClipLoader class, you have a onLoadInit event that fires, when your clip is loaded and it's _totalframes is known.
            If I would do that I wouldn't use an onEnterFrame, but would set an interval, that would periodically check how far the clip has played, and then unload it and load the next one.If you fire this off at the movie's frame rate, it's the same as onEnterFrame, but the control stays in one defined place (in main.swf scope) and doesn't pass to one of the loaded clips. This makes it easier to program the load and unload actions.
            • 3. Re: Sequentially playing library movie clips
              btkenney Level 1
              thanks for the suggestions. i am curious about the interval. what type of interval would you create? what might code would you suggest?

              might gentleman have a suggestion for this? to determine how to iterate through the library i gave up and created an array, still using on enter frame. the array just uses the library movie clip names. it works but creates an endless loop. and would this be any better of a solution.

              thanks
              • 4. Sequentially playing library movie clips
                Wolf_van_Ween Level 1
                Kept most of your initialization code, even though the mcEmpty movieClip is not necessary, you could just as well attach to _root.
                I would name the movieClips something like Box1, Box2, Box3 etc., you could then omit the whole array, you would just need to know how many boxes you have.
                And I've typed the definition of currentMovie:
                var currentMovie:String;
                to make it a bit clearer where your code failed.

                Good luck
                Wolf
                • 5. Re: Sequentially playing library movie clips
                  2m Level 2
                  Wolf did a tremendous job helping you it seems, whereas I was too busy in the last days. So I feel a bit hesitant to point out a small blunder, but for sake of correctness and future reference I'll do:

                  “Your problem might stem from the fact that _totalframes is unknown until the movie clip is fully loaded.”..is true in the way that loaded movies do behave that way – whereas attached movies (from the library) don’t. They are fully available form the frame they are loaded on (usually the first one).
                  And Wolf, I do understand your reasoning about the defined place, but why wouldn’t you just use this.onEnterFrame on _root or a controler clip, made only for that purpose?
                  (Unlike you I would actually prefer onEnterframe, as it makes sure, that it is only fired once perfreame, and the event of the attached clip reaching its last can only occur at that exact interval – so no unnecessary checks are made.) Am I missing something, or is it more a question of personal preference?
                  • 6. Re: Sequentially playing library movie clips
                    Wolf_van_Ween Level 1
                    2m, you're right of course, when I saw his code I realized that he attached the movieClip, and the mistake was rather in his using a string variable to hold the name of the movieClip, and then trying to access properties of the movieClip with a simple dot notation, not evaluating the string... But somehow I was too lazy to point that out :-)
                    As for the onEnterFrame attached to _root, I don't have a problem with that. It's not my personal preference, but rather that I wasn't sure how it will work in detail, specifically the timing: is it always in the order _root.onEnterFrame, _root actions, attached movieClip actions?
                    Wanting something that works for sure I went for the variant I knew ...
                    Besides, too few people know setInterval, which is much more flexible than onEnterFrame, so see this as a didactical move on my side :-)))
                    • 7. Re: Sequentially playing library movie clips
                      2m Level 2
                      @Wolf:
                      is it always in the order _root.onEnterFrame, _root actions, attached movieClip actions?

                      It seems so, and Colin, writer of my bibleand may Flash-prophet says so :-)

                      I know what you mean with "didactical" it is allways the fine line between teaching to advancement and utterly perflexing them. And you do graet as fas as I am worthy of an opinion. Kudos.
                      • 8. Re: Sequentially playing library movie clips
                        Level 7
                        The situation I had called for sequential & frequently changing .swf's
                        that were Public Service Announcements rather than library movie clips.
                        All I have to do is change the swf titles in the array and make sure
                        they are in the same directory and walla... (could be done with an XML
                        file too, probably easier, but that's for the future)

                        But thanks to help from this forum here's what I got working.
                        May be of some value to you...


                        In the Master.swf (only 1 frame)
                        /////////////////////////////////////////////
                        if (init == undefined) {
                        var aSWFs:Array = new Array();
                        var nCurSWF:Number = 0;
                        var aSWFmcs:Array = new Array();

                        // ----------------- Add desired PSA swf's to the array
                        aSWFs.push("Announce1.swf");
                        aSWFs.push("Announce2.swf");
                        aSWFs.push("Announce3.swf");
                        // --------------------- end of array.push()ing

                        var nSWFs:Number = aSWFs.length;
                        for (var n=0; n<=nSWFs; n++) {
                        aSWFmcs.push(createEmptyMovieClip("swf"+n, n));
                        }
                        var mcl:MovieClipLoader = new MovieClipLoader();
                        var Listen:Object = new Object();
                        Listen.onLoadInit = function(target) {
                        nCurSWF++;
                        if (nCurSWF < nSWFs) {
                        // load the next swf
                        mcl.loadClip(aSWFs[nCurSWF], aSWFmcs[nCurSWF]);
                        } else {
                        // done loading... start playing
                        _global.nClips = nSWFs - 1 // to make it zero based
                        _global.nCur = 0
                        _level0.swf0.gotoAndPlay(2);
                        }
                        }
                        mcl.addListener(Listen);
                        mcl.loadClip(aSWFs[0], aSWFmcs[0]);
                        init = 1;
                        }


                        Then in each PSA frame 1 has a 'stop();'
                        and the last frame has ActionScript of:
                        (change the 'else' to stop(); if you don't want them to loop)
                        /////////////////////////////////////////////////////////////////////
                        // if the Current SWF is not the last increment nCurSWF,
                        // else set it to the start
                        if (_global.nCur < _global.nClips) {
                        _global.nCur++;
                        } else {
                        _global.nCur = 0;
                        }
                        _level0["swf"+_global.nCur].gotoAndPlay(2);
                        stop();