AS3 URLRequest stored in array needs now to load, how?
Hey guys, I have a bit of code here that pulls, at random, 50 images from a file and pushes them into an array. I now need to pull, at random, 350 times from the array. I'm using a timer in place of the for loop to grab the images from the array. My code works fine as long as I do not use an array and I loop the images straight from the file. But that's very slow and bad form. I think I can do everything except the .load of the array. I can't seem to make it work. I'm getting errors that say "#1009: Cannot access a property or method of a null object reference" or "1067: Implicit coercion of a value of type Array to an unrelated type flash.net:URLRequest". I think I get the point of these messages, but I cannot seem to figure out how to pull the URLRequests back out of the array. Please, any help is much appreciated.
var imgLoader:Loader;
var imgSource:URLRequest;
var imgArrayer:Array = new Array();
var imgNum:uint;
var timer1Count:uint;
var thumbFade:Tween;
var layerCount:uint = 0;
for(var i:uint = 0; i < 50; i++) {
imgNum = Math.random() * _imgCount;
imgSource = new URLRequest("thumbsFinal/img"+imgNum+".jpg");
imgArrayer.push(imgSource);
}
var myTimer:Timer = new Timer(_imgTrTime, _imgTrInt);
myTimer.addEventListener(TimerEvent.TIMER, timedFunction);
myTimer.start();
function timedFunction(e:TimerEvent):void{
imgLoader.load(imgArrayer);
thumbFade = new Tween(imgLoader, "alpha", Regular.easeIn, _thumbFaderB, _thumbFaderF, _thumbFaderSpd, true);
addChildAt(imgLoader, layerCount);
imageAdjust();
timer1Count+开发者_开发知识库+;
layerCount++;
if(timer1Count == _scrnFadeTimer) {
screenFade();
}
else if(timer1Count == _txtDeploy){
textTween();
}
}
this bit might be:
for(var i:uint = 0; i < 50; i++) {
imgNum = Math.floor(Math.random() * _imgCount);
imgSource = new URLRequest("thumbsFinal/img"+imgNum+".jpg");
imgArrayer.push(imgSource);
}
and the bit that pulls 350 times would be:
imgLoader.load(imgArrayer[Math.floor(Math.random() * (imgArrayer.length))]);
called in that timer 350 times
精彩评论