I`m building a photo slide projector that calls a function using setInterval. But after the tenth call (about after 50 sec) the flash player stops working and crashes.
On the first frame of the main timeline I set the following code:
I like setInterval better than getTimer(), getTimer() is a pain in my … beeep…lol. Well that depends on the situation, in this case I think setInterval is better. I can’t see why your coding freezes, but try this anyway…
Remove the onClipEvent(load) from your movie clip on the stage and have this on the frame…
[AS]// comando para fullscreen
fscommand(“fullscreen”, “true”);
fscommand(“allowscale”, “false”);
// funcao que attacha mc_loadimg e carrega img
function loadimg () {
f2 = Math.floor(random(48));
f4 = Math.floor(random(48));
loadMovie(f4 + “.jpg”, “_root.foto1”);
loadMovie(f2 + “.jpg”, “_root.foto2”);
loadMovie(f2 + “.jpg”, “_root.foto3”);
loadMovie(f4 + “.jpg”, “_root.foto4”);
}
//run the function initially
loadimg();
//use setInterval to run it every 5 seconds after that
setInterval(loadimg, 5000);[/AS]
Set interval works every 5 seconds no matter what, you don’t need to reinitiate it every 5 seconds when the function is run, that isn’t very efficient, so what I did instead was moved the setInterval outside of the function you are calling. This of course would make the viewer have to wait 5 seconds to see the function in the first place, so right before initiating the setInterval I called the function to run it when that frame is hit. That way you get the movies loaded right off the bat AND every 5 seconds after that.
As for inside the function itself I removed the updateAfterEvent(), I saw no need for that in this script since you don’t need anything updated after an event, it will do it anyway. I also don’t think it’s wise to have the same variable names as instance names, it is confusing the coder and maybe to flash, so I changed those. And last put not least, I noticed your script you only used the foto2 and foto4 variables, so I removed foto1 and foto3, no need to run them if they aren’t getting used, you know how to put them back if you need them
Thanks for that!
It`s working better now.
But sometimes no image is loaded. What might be happening?
All the images have their number set from foto1.jpg to foto48.jpg.
I really want to learn how to make this code work in a different way.
Like this: the image is loaded in mc01 and then mc01 is triplicated into those positions and set rotation, alpha, color change. Is it possible to reflect the image as it is possible in photoshop (transform - reflect - horizontal or vertical)?
thanks again! :thumb: