how can i get a clicked button to play a random internal movie (Not external .swf) for example, out of five different movies?
When you say “internal movie” I’m not sure whether or not you are refering to a linked object from your library, telling a movie clip that’s on the stage to play, jumping to a certain frame, but here’s a general approach:
[AS]movieArray = new Array(“foo1”,“foo2”,“foo3”,“foo4”,“foo5”);
function playMovie(){
randomMovie = movieArray[Math.floor(Math.random()*movieArray.length)];
trace(randomMovie);
// Then make something happen (like one of the following
// some_mc.attachMovie(randomeMovie,“fooMovie”, 1);
// _root.gotoAndStop(randomMovie);
// _root.randomMovie].play();
}[/AS]
Your button should call for the playMovie() function.
You can add any amount of names (frame names, instance names, linkage names) to the array (depending on what you’re trying to do). The first line of the function will randomly select one name whatever the length of the array may be.
Hope this helps.
Actually, I’m still having trouble with this lol (am new to flash sites).
So if I want to have an empty movie clip on my stage and I want it to play my random movies (rm1, rm2, rm3, rm4, and rm5) what do i put on each of my buttons?
This code would go on the main timeline:
[AS]movieArray = new Array(“rm1”,“rm2”,“rm3”,“rm4”,“rm5”);
function playMovie(){
randomMovie = movieArray[Math.floor(Math.random()*movieArray.length)];
trace(randomMovie);
empty_mc.attachMovie(randomMovie, “rmovie”, 1);
}[/AS]
And this code would go on your button:
[AS]on(release){
playMovie();
}[/AS]
The above assumes a few things: You have movie clips in your library with the linkage name rm1 through rm5, that your empty movie clip has the instance name empty_mc, and that your button is on the main timeline.
ok i think i almost ahve it lol
its just when i click my button all i get is an output error saying “undefined”
lol
I’m not sure why that’s happening. When I copied and pasted my code back into Flash it worked. (The only mistake I found was I had one of the curly brackets facing the wrong way in the on(release) code for the button.)
For some reason your randomMovie variable isn’t being set before it traces. Check to make sure the names for the variable and for the array are consistent. A little typo there could cause this kind of a problem.
If you can’t figure it out, copy and paste your code back here (or maybe post the FLA if you can).