Random load swf

I have a bunch of swf’s I want to load into my main movie…

I want one to load, wait 1 minute, then load another.

My question is, what is the easiest way to do this… In MX that is…

In Generator, I know how, but in MX, it is eluding me…

I’m thinking that I use an array (which I have never done before), but that would entail inputting the file names of all 30+ swf’s…

I would like to have some sort of AS that will call the swf’s by a number, then load the next swf, then when there are no more swf’s, it goes back to 1.swf…

Am I asking for 2much?

and if there is a tutorial on this, I haven’t found it… I can’t even see where this has been asked on the forum before…

thanks in advance for any help…

Rev

Couldn’t you use a getTimer(); loop to get your pause, then instead of making an array (which would have all the files), couldn’t you put a rename the thirty files to like flashmovie1.swf, and flashmovie2.swf, etc. At the end of your getTimer(); loop, do this:
[AS]
i++;
_root.container.loadMovie(“flashmovie”+i+".swf");
[/AS]
That would be consecutive, if you wanted random, you could do:
[AS]
i=Math.floor(1+Math.random()*29);
_root.container.loadMovie(“flashmovie”+i+".swf");
[/AS]

Is that what you mean? 'Cause, I’m not sure if that’s what your asking.

I’m not sure…

I’ve never used a getTimer loop…

It sounds okay, but I’m not sure…

can you give me a little more info? AS is not my strong suit…

thanks for the help so far…

Rev

You can also use setInterval if you want to load it every minute.

How are your file names labeled?

If you label them like file1, file2, file3, file4, etc, etc you will not need to use arrays because you can use a random number generator as Freddy showed.

If they all have differerent names like blue, red, orange, green, then you need to store them in an array.

So once we figure out how your files are set up we can figure out how to code it for them to come in.

I can change the names of the files… that is easy. right now they all have their own names… ie… nwb.swf , etc.

Rev

[AS]//varial to hold how many movies are you loading
var totalClips = 30;
function selectMovie() {
//variable to get random numer
//loads random number between 1 (+1 at the end) and 30 (total clips)
var randomNumber = random(totalClips)+1;
//load random movie
//this assumes your movies names are file1, file2, file3, etc
clipToLoadTo.loadMovie(“file”+randomNumber+".swf");
}
//create setInterval
var loadInterval = setInterval(selectMovie, 60000);[/AS]

I commented the code, so if you have any questions feel free to ask, but right now I am going to go over setInterval.

We first define setInterval as a variable. It will still run the setInterval code, but it allows us to target our setInterval later if we ever need to use clearInterval (will explain in a bit).

setInterval works like this…
[AS]setInterval(function, time);[/AS]

The function in this case is called selectMovie. And the time is set to 60000 because setInterval times itself in milliseconds. So 1000 = 1 second. And 60 seconds = 1 minute so 60*1000 = 60000 right? This will then call the function every 60 seconds.

If you ever want to clear your interval to get it to stop running you can use this… [AS]clearInterval(intervalName);[/AS] In our case intervalName would be loadInterval.

Ok, now that I got setInterval explained, lets go over the function.

The function first declare a variable to store a random number from 1 to 30. It then calls a loadMovie script. You know how loadMovie works right? (I assume). Well as you see in our script the movie we load is called “file”+randomNumber. This will take the random number produced in the randomNumber variable and attached it to the end of the word “file” creating it to be like file1, file2, file3, file4, etc, etc. Then of course the “.swf” attaches that to the end so it becomes file1.swf, file2.swf, file3.swf, etc, etc.

I hope that helps.

I thought I understood…

I have 47 swf’s btw…

I want to load them into a blank movie (a place holder in essence)…

Don’t we need to tell it to load into a level or target?

I get no loading whatsoever right now… (I have just used your code in the first and only frame in my main.swf…

thanks for all the comments, it helps a bunch…

Rev

I figured out how to use getTimer(). Even though lost has already did a better job (show off:P ), I want to explain how getTimer() works in case anyone wondered. I put this in a movieClip and it shows a very good example:
[AS]
onClipEvent(enterFrame){
if(getTimer() > myTimer){
myTimer = getTimer()+ 1500;
this._x+=10;
}
}
[/AS]
1500=1.5 seconds (or 1500 milliseconds). Everytime 1.5 seconds elapses the movieClip moves 10 pixels. Whoo-hoo…:crazy:
So in your case, rev, you could create an empty movieClip and put in the code:
[AS]
if(getTimer() > myTimer){
myTimer = getTimer()+ 60000;
i++;
_root.container.loadMovie(“flashmovie”+i+".swf");
}
[/AS]
I hope that works for you, if you use it. And if not, I feel better now - I learned getTimer() - :beam:

*Originally posted by reverendflash *
**I thought I understood…

I have 47 swf’s btw…

I want to load them into a blank movie (a place holder in essence)…

Don’t we need to tell it to load into a level or target?

I get no loading whatsoever right now… (I have just used your code in the first and only frame in my main.swf…

thanks for all the comments, it helps a bunch…

Rev **

[AS]clipToLoadTo.loadMovie(“file”+randomNumber+“.swf”);[/AS]

That line in the script, clipToLoadTo is the empty movie clip that you will be loading to.

Oh, and in case you were wondering, there are 2 ways to write loadMovie…

[AS]loadMovie(“url”, “target”)[/AS] and [AS]target.loadMovie(“url”)[/AS]

okay, now I am feeling really stupid…

I have an empty mc on my stage, with an instance name of hole. I have changed “ClipToLoad” to hole, and nothing still loads…

If I hard code loadmovie file1.swf, into target hole, it works fine…

I am really confused why this doesn’t work…

Rev

Really? I see no reason it doesn’t work.

I tried it out (without creating the movies to load) and got this in the output…

Error opening URL “file:///C|/----/------/-----/file23.swf”

This means that it found the URL and tried to load, but the file didn’t exist (I am not about to create 47 test files :wink: )

I ---- out some folder names.

I’m sorry, can you send me the fla you created, and I can see what I am doing wrong?

thanks, I can’t seem to get it to even look in the right spot…

I feel so lame…

Rev

Yeah, heres my file…

thanks lost…

I had an extra zero (or 2 or 3) for the time interval… I just needed more patience to wait for it to happen…

I am such a lameoid sometimes (I was even sober at the time) …

Thanks again…

Hey! you helped me!

again…

:beam:

Rev

LOL hahaha, I love that. Those images you post are so great.

And yeah, in my example I shortened the interval to 1 second (1000) because I wasn’t going to wait a full minute (60000) to test it :wink: If it works every second or so it will work every 60 seconds or so.

yup, it works just fine.

that is why yours was showing up, and mine wasn’t… yet…

I have changed the names to protect the innocent… or numbers…

thanks again…

Rev

Yay… I help Revvy :beam:

the check is in the mail…

:wink:

Rev

hehe, awww dats okay revvy, me no need checkie from you :beam:

Why am I talking like that? I think I need to be smacked upside the head… will you do the honors?