Log in

View Full Version : Randomize flash background



davelf
10-01-2010, 07:12 AM
How to make a randomize flash background?
I have a script to randomize image



<style type="text/css">
body {
background-repeat:no-repeat;
background-position:center top;
}
</style>

<script type="text/javascript">

var num;
var temp=0;
var speed=20000; /* this is set for 5 seconds, edit value to suit requirements */
var preloads=[];

/* add any number of images here */

preload(
'images/bg_home_1.jpg',
'images/bg_home_6.jpg',
'images/bg_home_7.jpg'
);

function preload(){

for(var c=0;c<arguments.length;c++) {
preloads[preloads.length]=new Image();
preloads[preloads.length-1].src=arguments[c];
}
}

function rotateImages() {
num=Math.floor(Math.random()*preloads.length);
if(num==temp){
rotateImages();
}
else {
document.body.style.backgroundImage='url('+preloads[num].src+')';
temp=num;

setTimeout(function(){rotateImages()},speed);
}
}

if(window.addEventListener){
window.addEventListener('load',rotateImages,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',rotateImages);
}
}
</script>


But it don't work when i try to change the image / .jpg with flash / .swf
Thx in advanced...

davelf
10-07-2010, 02:53 AM
so is there any suggestion, i try a lot of different thing to make this work. But it always fail.

i still use image random, till i found the flash randomize script

this is my website, if you need some clue about the problem:)

http://www.imaxxo.net/aryaduta

Thx in advanced