PDA

View Full Version : interrupting an image being loaded by a Loader...


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);
}

fpssp
08-26-2008, 10:42 PM
I know that ProgressEvent has a property called "cancelable" and it is set to false by default, meaning you cannot cancel your object event from load.

Maybe try changing that. I'm not sure how you cancel it after you set this flag, never had the need to do it.

Dr.Mabuse
08-26-2008, 11:13 PM
Why not use the online Adobe documentation for the Loader class?

I guess the close() method should do the trick...
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/Loader.html#close()