4 Replies Latest reply on Dec 12, 2007 1:43 PM by the_voder

    Very Basic Functions Question

      Hi,

      apologies for this being a very basic question, but I rarely use Flash. About once a year, however, I am called upon to do some sort of (usually very simple) Flash-based project for the students I assist. This time it's a simple random slideshow.

      The setup is this:
      * I have a movieClip called 'slides_MC' containing all the slide photos, on consecutive frames.
      * This movieClip is placed inside another movieclip named slideshowRand_MC.
      This is given an instance name of topslide_mc, and faded up and down with alpha keyframes.

      The idea is that, when the slides mc is faded right down, some Actionscript causes the slides movie to jump to, and stop playing on a random frame, so random slides are faded up, then down again, then swapped.

      I need to apply some actionscript to particular keyframes so that the swap is performed at the correct time.

      This is my attempt at a reusable function to do the swapping. It's placed in a keyframe on the root timeline:

      // Go to and stop at random frame in slides movieclip
      function goRandom(mc) {
      // Number of slides in slides movieclip
      var slides = 22;
      // Random number between 1 and number of frames in slides movieclip
      var randFrame = Math.ceil(Math.random() * slides);
      mc.goToAndStop("slide_" & randFrame);
      }

      This function is called from keyframes in slideshowRand_MC:

      _root.goRandom(this.slideshow_rand_mc.topslide_mc);

      I know this is really basic stuff, but can anyone tell me why this isn't working.
      I've tried adding a breakpoint in the goRandom function, but it doesn't look like it ever gets called.

      Any assistance very gratefully accepted.

      Alex
        • 1. Re: Very Basic Functions Question
          Bob Pierce Level 1
          "_root.goRandom(this.slideshow_rand_mc.topslide_mc);"

          There's a typo in that line - if it's in your code, it won't work!
          • 2. Re: Very Basic Functions Question
            Level 1
            Hi Bob, thanks for getting back to me.

            quote:

            Originally posted by: Bob Pierce
            "_root.goRandom(this.slideshow_rand_mc.topslide_mc);"

            There's a typo in that line - if it's in your code, it won't work!


            Ah, true. The typo actually happened when I was re-writing the code in post. The actual code in the movie is

            _root.goRandom(this.topslide_mc);

            This is attached to a keyframe of the container movie-clip containing the slides MC.

            I've put the fla file on our server.
            slideshow_random.fla.zip

            If you, or someone else could download it and help me find out what I'm doing wrong, I'd be ever-so grateful. I'm sure it's something really obvious. Without being very familiar with Flash and Actionscript, it's hard to explain things, and much easier to show you the actual Flash file.

            The 2 functions are on a keyframe on frame 1 of the root timeline. The 'goRandom' function is supposed to be called from a keyframe in 'slideshowRand_MC'. I envisaged calling the random pause function from another keyframe in the same movieclip.


            Thanks again,

            Alex
            • 3. Re: Very Basic Functions Question
              Bob Pierce Level 1
              gotoAndStop(), not goToAndStop(). It seems unlikely and a bit picky, but that was the problem. The colour coding helps to highlight this sort of error. I initially added couple of traces to check firstly that the goRandom() function was being called and that the correct mc was being passed in, and secondly that a valid slide number was being generated.

              • 4. Re: Very Basic Functions Question
                Level 1
                Oh.. THAT typo. I missed that one completely!!
                That's great; it works fine now.

                Thanks very much for your help!

                Cheers,

                Alex