Skip to main content
Inspiring
November 19, 2008
Question

playing random movies

  • November 19, 2008
  • 4 replies
  • 626 views
Hi,
I was looking for tutorials on this but each script, and tutorial didnt work for me. I've got three movieClips on my main stage, movie1, movie2, and movie3 (its the instance too). Very predictable.
Not on load but rather I'd like each one to play in a random sequence. Maybe movie1 plays first, followed by movie3, not 1, 2, 3.

I tired this:
num = random(3)+1;
movie = "movie" + num;
movie.gotoAndPlay(2);

I've got a stop(); on the first frame inside each movie clip.

Thanks

This topic has been closed for replies.

4 replies

Inspiring
November 21, 2008
you're welcome, good luck.
Inspiring
November 20, 2008
you are tracing the the fairies mc's..you have fairy1, fairy2, fairy3.. your random code wants to play fairy4. You do not have Fairy4, resulting in your undefined message in output panel.

change your multiplier from 3 to 2, as I have stated in the first place.

math.random() returns one of two values. either 0 or 1.
you are multiplying by 3, which would be fine, if you weren't adding 1 to it.

what is happening here, is that Flash is looking for Fairy4 because the random equation is:
(1 * 3) + 1 = 4
Inspiring
November 20, 2008
Sketchsta, thanking you kindly for your support. My fairies are behaving the way i want them. I may add more for more variations, and now i understand the maths... Should be easy.

Thanking you again
Graham
Inspiring
November 20, 2008
Yes the code i gave you works to play one of the 3 movies at random.
Depending on what you want to accomplish, you may want to create a function with that code, and call it at the end of each movie, so that another can start.

What are you tracing. that returns a 'undefined' message?
Inspiring
November 20, 2008
Hi Sketchsta, Thanks again. The undefined thing was a miss spelling in instances. Please take a peek at the .fla I've attached. What I've done is turn the code into a function and have it return from the end of each movie to call the function to play the next movie. What is not happening is yes, the undefined thing is there again and ends the whole sequence of movies playing. Fairy1, and then Fairy2 plays but then it says undefined and it stops.

I've checked that all of the instances are spelt correctly, and the code is calling the movies labels ok... it's just one fairy fails to play and the whole thing stops.

Thanks for the help
Inspiring
November 19, 2008
Hi Graham Howe

Try this.

var num = Math.round((Math.random() * 2) + 1);
var movie = eval("movie"+num);
movie.gotoAndPlay(2);
Inspiring
November 19, 2008
Hi Sketchsta,

Thanks for the help. I've given it a go, and the movie clips won't move but thats because I've got a stop(); on the first frame inside each clip movie1, movie2 ...

This code should be tell either movie 1, 2, or 3 to go to and play frame 2, right?

Thanks
Inspiring
November 19, 2008
Hi all, I've uploaded my .fla to seek help. I've got the random to work kind of but an 'unidentified' error is traced. One of my fairies does turn up?

download .fla

Any help is much appreciated