4 Replies Latest reply on Feb 4, 2007 4:57 PM by dfsdfsdfsdfsd

    Setting Random play of 5 Movieclips

    dfsdfsdfsdfsd
      Hi,

      I have 7 little movieclips named (data_flickr_1_MC through to data_flickr_7_MC).

      What I am trying to do, is when the flash starts, get it to pause for around 10 seconds, then I want the 7 movieclips to play randomly (of eachother) and repeat say every 4 seconds.

      How can i achieve this using actionscript?

      Thanks kindly :)
        • 1. Re: Setting Random play of 5 Movieclips
          MotionMaker Level 1
          Store references to mcs in an array.
          Use setInterval to call a function.

          In the function use the Math.random to select an array index and then play the clip referenced in the array.
          • 2. Setting Random play of 5 Movieclips
            dfsdfsdfsdfsd Level 1
            Ok, I've got a central movie clip named "data_flickr_MC"

            Contained within "data_flickr_MC" are 7 Layers, with 7 individual movieclips. Both the Layers and movieclips are named "data_flickr_1_MC" through to "data_flickr_7_MC".

            Screenshot of Flash Layout (link below) http://www.philtrated.com/stage/flash_help.gif

            In a "scripts" layer I have added the following code :


            // The psuedo code
            var myClips:Array = new Array();
            myClips.push(data_flickr_1_MC);
            myClips.push(data_flickr_2_MC);
            myClips.push(data_flickr_3_MC);
            myClips.push(data_flickr_4_MC);
            myClips.push(data_flickr_5_MC);
            myClips.push(data_flickr_6_MC);
            myClips.push(data_flickr_7_MC);
            function clipPlayer()
            {
            var clip_mc:MovieClip = myClips[ randRange(0, myClips.length-1)];
            }
            intervalId = setInterval(this, "clipPlayer", 4000);


            function randRange(min:Number, max:Number):Number {
            var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
            return randomNum;
            }


            Is this what I should be doing, because currently the animation just plays continuously?

            Thank you kindly :)
            • 3. Re: Setting Random play of 5 Movieclips
              MotionMaker Level 1
              I am guessing a bit at what you are seeing but I suspect you are seeing all the clips playing at the start as the problem.

              If that is the case then consider stops in the animated clips on their first frame and then add a gotoAndPlay(2) on their last frame making frames 2 to the last the animation and frame 1 the parked stopped state.

              then perhaps a simple function for frame 1
              function stopAllClips()
              {
              data_flickr_1.gotoAndStop(1);
              ...
              data_flickr_7.gotoAndStop(1);

              }

              Call the function in clipPlayer.
              function clipPlayer()
              {
              stopAllClips()
              var clip_mc:MovieClip = myClips[ randRange(0, myClips.length-1)];
              clip_mc.gotoAndPlay(2);
              }

              • 4. Re: Setting Random play of 5 Movieclips
                dfsdfsdfsdfsd Level 1
                thank you kindly :)

                I shall try that