MikeTheVike
08-26-2008, 09:55 PM
I'm working on a portfolio site. I have buttons that when pressed load an image to a Loader from a url. This has been working great, hit button, new image appears. I noticed that when I was testing the animation using simulate download. If I have one image loading, then I press another button, the new image will load, but the old one keeps loading. Whatever image takes the longest to load will display last. I want to be able to click a button while the current image is loading, have the current load canceled, and only load the image attached to newest button click. If this doesn't make sense, let me know, I'll try and clarify more. Heres some stripped code showing how I go about this...
var imageLoader:Loader = new Loader();
loadImage();
//this is the default image load that happens at startup
function loadImage() :void {
imageLoader.load(new URLRequest(xml_TSE.category.item.movie[0]));
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imgLoadComplete);
portfolio_window.portfolio_Main.effectContainer.ad dChild(imageLoader);
}
function linkClicked() :void {
// shouldn't this remove the listener?
imageLoader.contentLoaderInfo.removeEventListener( Event.COMPLETE, imgLoadComplete);
//and shouldn't this remove the loader currently loading, making it so it won't load anymore?
portfolio_window.portfolio_Main.effectContainer.re moveChild(imageLoader);
portfolio_window.portfolio_Main.effectContainer.ad dChild(imageLoader);
imageLoader.load(new URLRequest(xml_TSE.category.item.movie[h]));
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imgLoadComplete);
}
function imgLoadComplete() :void {
imageLoader.contentLoaderInfo.removeEventListener( Event.COMPLETE, imgLoadComplete);
}
var imageLoader:Loader = new Loader();
loadImage();
//this is the default image load that happens at startup
function loadImage() :void {
imageLoader.load(new URLRequest(xml_TSE.category.item.movie[0]));
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imgLoadComplete);
portfolio_window.portfolio_Main.effectContainer.ad dChild(imageLoader);
}
function linkClicked() :void {
// shouldn't this remove the listener?
imageLoader.contentLoaderInfo.removeEventListener( Event.COMPLETE, imgLoadComplete);
//and shouldn't this remove the loader currently loading, making it so it won't load anymore?
portfolio_window.portfolio_Main.effectContainer.re moveChild(imageLoader);
portfolio_window.portfolio_Main.effectContainer.ad dChild(imageLoader);
imageLoader.load(new URLRequest(xml_TSE.category.item.movie[h]));
imageLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, imgLoadComplete);
}
function imgLoadComplete() :void {
imageLoader.contentLoaderInfo.removeEventListener( Event.COMPLETE, imgLoadComplete);
}