The following code loads 3 swf files randomly 1 at a time in the same div. How can i track which swf loads at a particular time in PHP or javascript b'se i want to use IF statements somewhere like if($i==1) where $i is a variable equal to one when 1.swf loads & $i==2 when 2.swf loads.
function loadFlash(){
function getRandomFilename()
{
var names = [
'1.swf',
'2.swf',
'3.swf'
];
var r = Math.floor(Math.random() * names.length);
return names[r];
}
var flashvars = {};
var params = {wmode:"opaque"};
var attributes = {};
swfobject.embedSWF(getRandomFilename(), "SWF_Output", "900", "120", "8.0.0", false, flashvars, params, attributes);
}
Mob ... Thanks in advance
Edit your code like this:
function loadFlash(){
function getRandomFilename() {
var names = [
'1.swf',
'2.swf',
'3.swf'
];
var r = Math.floor(Math.random() * names.length);
return [names[r], r];
}
var flashvars = {};
var params = {wmode:"opaque"};
var attributes = {};
var file = getRandomFilename();
swfobject.embedSWF(file[0], "SWF_Output", "900", "120", "8.0.0", false, flashvars, params, attributes);
//file[0] will be the file name ('1.swf' - '3.swf')
//file[1] will be the array index (0 - 2)
}
You won't be able to access names[r]
outside of the getRandomFilename
function (out of scope)