Help With Set Interval Code

Hey Guys -

I am working on a site and am using the setInterval code to load random swf’s into a holder. The swf’s seem to load speratically and is usally after you leave the home page and return. Can you help out. Below is the code

var homeads:Array = new Array;
var lastAd:String = “”;
function Shuffle(a,b):Number {
return Math.round(Math.random()*2)-1;
}
function homeAdsLoad (){
if (homeads.length == 0){
homeads = Array( “homeads/proam.swf”,
“homeads/retail.swf”,
“homeads/drsigframes.swf”,
“homeads/products.swf”,

                    "homeads/hyperhills.swf").sort(Shuffle); 
    while (lastAd == homeads[homeads.length-1]){
        homeads = homeads.sort(Shuffle);
    }
    lastAd=homeads[0];
    trace("--");
}
newAd = homeads.pop();
trace("newAd :"+newAd);
_root.pages.holder_mc.loadMovie(newAd, newAd, 100); 
newAd._x = 0; 
newAd._y = 0;

}
homeAdsLoad();
setInterval( homeAdsLoad, 6500 );

Thanks

instead of “loadMovie” you’ll probably need to use “loadClip” with a MovieClipLoader.

As far as i know loadMovie isn’t supposed to work with loading swf’s. Load clip also allows additional functionality such as .onLoadComplete and .onLoadProgress these will probably be useful for debugging.

BNNS

I usually use the loadMovie so how in the code above can I use the loadClip like you described?

take the following line of code for example.
_root.pages.holder_mc.loadMovie(newAd, newAd, 100);

_root.pages.holder_mc - is your holder or container mc,
newAd - is your target

for loadClip you’ll probably need to use a similar format to the following code.

var mcMovieLoader = new MovieClipLoader();
mcMovieLoader.onLoadComplete = function(target_mc:MovieClip) {
trace(“something”)
};//this function is not essential but provides added benefits
mcMovieLoader.loadClip(newAd, _root.pages.holder_mc);

something like that should work test it out in seperate .fla so you can get used to the functionality.

loadMovie does work with SWFs. What do you mean it loads speratically? I tested it and it works fine.

If you first go to the site it loads smoothly but once you click on a page like news and go back to the home page it kind of jumps at a weird timing. I am refering to the small swf’s in the bottom right corner above the broseldesign logo.

Thanks for any help you guys can give. And loadMovie does load swf’s

can you provide us with a link please? lol.

loadMovie was origionally not designed to work with swf’s you’re right i do apologies for my mistake. When you refer to the fact that the movie of “.swf” loads sporadically it could have something to do with the size of the file, the larger it is the longer to load. or depend on where it’s being served from.

You can test out loadClip and that function will give you the ability to detect when the swf has finished loading. or even the amount of progress being made.

The drawback with loadMovie is that there is no callback function, there is no way to know when the file is done loading. sadly the simple facts of life.

Both do the same thing, one is more powerful and slightly harder to use. I’ll point you in the right direction in the event you decide to check it out.

loadClip is a function from a class called “MovieClipLoader”:
var mcLoader = new MovieClipLoader();
mcLoader.onLoadComplete = function(){trace(“files done loading and this is a callback function”);}
mcLoader.loadClip(“target:string”, target:Object);

BNNS

ha sorry guys here is the link. http://www.hyperbicycles.com . I would love to learn the loadClip class as you describe bnns. What approach should I take?

Ok I think I know whats going on. When I first visited, the bottom right pictures are moving along smoothly. You go to another page and then back to home. It starts to seem to go a little faster. You go to another page and come back to home…Now they are all jumpy and looking funky. The reason is because When you first arrive on your home page, you have your interval set.

You go to another page and come back which sets another interval. You now have two intervals going calling the same function. You go to another page and come back home. You now have 3 intervals going and now its all jacked up.

Simple solution:
first set your setInterval to a variable like:


homeInterval = setInterval( homeAdsLoad, 6500 );

next anytime you navigate away from the home page, make sure you clear the interval. ie:


clearInterval(homeInterval);

that should do it man

I tried that before and it didn’t work. I placed the code on my “transition” frame which plays after you click away from the home page. On that frame I put

clearInterval( homeAdsLoad );
trace(“clear interval”);

It shows up in the output panel but it is still jumpy. Any suggestions?