loading af billeder i 3 størrelser med extern url
Jeg har en xml fil med nogle banner reklamer i. Bannerne har 3 forskellige størrelser hvilket gir mig 3 mulige måder at loade billederne på...3 små...
1 lille og 1 mellem...
1 stort...
i xml filen har jeg defineret en størrelse alt efter hvor mange bloks de fylder, endten 1, 2 eller alle 3 blokke...
i xml filen er der også defineret en url til billedet og en extern url til bannerens side.
Som sådan loader den fint men mit problem ligger i depth's som blir ved med at overskrive hinanden ++ at når random value er lig 1 eller 2 så loader den kun det sidste billede ind. Hvilket jeg tror er fordi watcher_mc som preloader billedet blir overskrevet inden billedet rent faktisk er loadet.
Jeg har også forsøgt mig med en for() for at loade dem en efter en, men så trigger jeg funktionen igen og så bliver nummer 2 aldrig triggeret.
Nogen der kan løse opgaven? Jeg er ret desperat ! :)
<code>
// set random # variables - each must be 0 for first 'while' loop below
var randomNum = 0;
var randomNumLast = 0;
var randVal1_1 = 0;
var randVal1_1Last = 0;
var randVal1_2 = 0;
var randVal1_2Last = 0;
var randVal2_1 = 0;
var randVal2_1Last = 0;
var randVal2_2 = 0;
var randVal2_2Last = 0;
var randVal2_3 = 0;
var randVal2_3Last = 0;
// parent container 1 bloks
var container_b1_mc = this.createEmptyMovieClip("container_b1",0);
container_b1_mc._x = 0;
container_b1_mc.createEmptyMovieClip("loader1_b1_1_mc",2);
container_b1_mc.createEmptyMovieClip("loader2_b1_1_mc",1);
container_b1_mc.loader1_b1_1_mc._x = 0;
container_b1_mc.loader2_b1_1_mc._x = 0;
container_b1_mc.createEmptyMovieClip("loader1_b1_2_mc",4);
container_b1_mc.createEmptyMovieClip("loader2_b1_2_mc",3);
container_b1_mc.loader1_b1_2_mc._x = 180;
container_b1_mc.loader2_b1_2_mc._x = 180;
container_b1_mc.createEmptyMovieClip("loader1_b1_3_mc",6);
container_b1_mc.createEmptyMovieClip("loader2_b1_3_mc",5);
container_b1_mc.loader1_b1_3_mc._x = 360;
container_b1_mc.loader2_b1_3_mc._x = 360;
// parent container 2 bloks
var container_b2_mc = this.createEmptyMovieClip("container_b2",1);
container_b2_mc._x = 0;
container_b2_mc.createEmptyMovieClip("loader1_b2_1_mc",2);
container_b2_mc.createEmptyMovieClip("loader2_b2_1_mc",1);
container_b2_mc.loader1_b2_1_mc._x = 0;
container_b2_mc.loader2_b2_1_mc._x = 0;
container_b2_mc.createEmptyMovieClip("loader1_b2_2_mc",4);
container_b2_mc.createEmptyMovieClip("loader2_b2_2_mc",3);
container_b2_mc.loader1_b2_2_mc._x = 360;
container_b2_mc.loader2_b2_2_mc._x = 360;
// parent container 3 bloks
var container_b3_mc = this.createEmptyMovieClip("container_b3",2);
container_b3_mc.createEmptyMovieClip("loader1_b3_1_mc",2);
container_b3_mc.createEmptyMovieClip("loader2_b3_1_mc",1);
container_b3_mc._x = 0;
// preload watcher
this.createEmptyMovieClip("watcher_mc",100);
// load xml
images_xml = new XML();
images_xml.ignoreWhite=true;
images_xml.onLoad = parse;
images_xml.load("../xml/data.xml");
function parse(success) {
if (success) {
trace('wuw');
imageArray_1 = new Array();
imageArray_2 = new Array();
imageArray_3 = new Array();
var root = this.childNodes[0].childNodes[1];
_global.numPause = Number(root.attributes.timer * 1000);
_global.order = root.attributes.order;
_global.looping = root.attributes.looping;
_global.fadetime = Number(root.attributes.fadetime);
_global.xpos = Number(root.attributes.xpos);
_global.ypos = Number(root.attributes.ypos);
var imageNode = root.lastChild;
var a=0;
var b=0;
var c=0;
while (imageNode.nodeName != null) {
if(imageNode.attributes.bsize == 1) {
imageData = new Object;
imageData.path = '../banner/'+imageNode.attributes.path;
imageData.extpath = '../banner/'+imageNode.attributes.extpath;
imageArray_1[a]=imageData;
a++;
} else if(imageNode.attributes.bsize == 2) {
imageData = new Object;
imageData.path = '../banner/'+imageNode.attributes.path;
imageData.extpath = '../banner/'+imageNode.attributes.extpath;
imageArray_2[b]=imageData;
b++;
} else if(imageNode.attributes.bsize == 3) {
imageData = new Object;
imageData.path = '../banner/'+imageNode.attributes.path;
imageData.extpath = '../banner/'+imageNode.attributes.extpath;
imageArray_3[c]=imageData;
c++;
} else {
trace('err');
}
imageNode = imageNode.previousSibling;
}
// parse array
imageArray_1.reverse();
imageArray_2.reverse();
imageArray_3.reverse();
newArr = new Array(imageArray_1, imageArray_2, imageArray_3);
imageGen(newArr);
} else {
trace('problem');
}
}
// depth swapping
function swapPlace(clip,num,container) {
eval(clip).swapDepths(eval("container_b"+container+"_mc.loader"+num+"_b"+container+"_mc"));
}
function loadImages(data,num, randomValue, container) {
if (i==undefined || i == 2) {
i=2;
createLoader(i,data,num, randomValue, container);
i=1;
} else if (i==1) {
createLoader(i,data,num, randomValue, container);
i=2;
}
}
function createLoader(i,data,num, randomValue, container) {
trace('creating loader for '+randomValue+' mc = ' + container);
thisLoader=eval("container_b"+randomValue+"_mc.loader"+i+"_b"+container+"_mc");
thisLoader._alpha=0;
thisLoader.loadMovie(data[num].path);
watcher_mc.onEnterFrame=function () {
var picLoaded = thisLoader.getBytesLoaded();
var picBytes = thisLoader.getBytesTotal();
if (isNaN(picBytes) || picBytes < 4) {
return;
}
if (picLoaded / picBytes >= 1) {
swapPlace("container_b"+randomValue+"_mc.loader2_b"+container+"_mc",1);
alphaTween = new mx.transitions.Tween(thisLoader, "_alpha", mx.transitions.easing.Regular.easeOut,0,100,_global.fadetime,true);
timerInterval = setInterval(imageGen,_global.numPause,data);
delete this.onEnterFrame;
}
}
}
function imageGen(data) {
randVal = Math.floor(Math.random() * 4);
if(randVal == 0) { randVal++ }
trace('random value = ' + randVal);
if(randVal == 1) {
randomFactor(imageArray_1, randVal);
} else if(randVal == 2) {
randomFactor(Array(imageArray_1, imageArray_2), randVal);
} else if(randVal == 3) {
randomFactor(imageArray_3, randVal);
}
clearInterval(timerInterval);
}
function randomFactor(data, randomValue) {
// random, or sequential?
if (_global.order=="random") {
trace('order value is random');
// choose random # between 0 and total number of images
if(randomValue == 1) {
while (randomNum == randomNumLast) {
randomNum = Math.floor(Math.random() * data.length);
trace('random number is = '+randomNum);
}
loadImages(data,randomNum, randomValue, "1_1");
randomNumLast = randomNum;
loadImages(data,randomNum, randomValue, "1_2");
randomNumLast = randomNum;
loadImages(data,randomNum, randomValue, "1_3");
randomNumLast = randomNum;
} else if(randomValue == 2) {
while (randVal2_1 == randVal2_1Last) {
randVal1 = Math.floor(Math.random() * data[0].length);
trace('randval2_1 number is = '+randVal2_1);
}
while (randVal2_2 == randVal2_2Last) {
randVal2 = Math.floor(Math.random() * data[1].length);
trace('randval2_2 number is = '+randVal2_2);
}
loadImages(imageArray_1,randVal2_1, randomValue, "2_1");
randVal2_1Last = randVal2_1;
loadImages(imageArray_2,randVal2_2, randomValue, "2_2");
randVal2_2Last = randVal2_2;
} else if(randomValue == 3) {
while (randomNum == randomNumLast) {
randomNum = Math.floor(Math.random() * data.length);
trace('random number is = '+randomNum);
}
loadImages(data,randomNum, randomValue, "3_1");
randomNumLast = randomNum;
}
} else if (_global.order=="sequential") {
// start at 0, increment to total number of images, then drop back to zero when done
if (p==undefined || p==data.length && _global.looping=="yes") { p=0; } else { break; }
loadImages(data,p);
p++;
} else {
trace ("order attribute in xml isn't correct - must specify either 'random' or 'sequential'");
}
}
stop();
</code>