Jump to content
Search Community

Is there an event that fires if an image already is loaded

Thomas James Thorstensson test
Moderator Tag

Recommended Posts

Im my AssetLoaderProxy I have

 

 

public function handleImageRequested(imgStr:String):void {

trace ("image requested " + imgStr + " matching loader " +_imageDictionary[imgStr]);

loaderNameStr=_imageDictionary[imgStr];

LoaderMax.prioritize(loaderNameStr).addEventListener(LoaderEvent.COMPLETE, handleImageLoaded);

}

 

/////////////// EDIT

Can you do this : it seems to work but only for the first already loaded image ???

 

if (LoaderMax.getLoader(loaderNameStr).status == LoaderStatus.COMPLETED){

trace ("already loaded");

}

 

//////////////////////////////////// SECOND EDIT !

It worked was me and my mediator not agreeing ruling out already loaded checks due to a boolean that was set to false!

 

New question

 

I suppose you can remove an event listener like so

 

LoaderMax.getLoader(loaderNameStr).removeEventListener(LoaderEvent.COMPLETE, handleImageLoaded)

 

I get a warning in Flasbuilder but it seems the code is doing its job!

 

Hum ?

 

 

Thanks

Link to comment
Share on other sites

Yep, your removeEventListener() code should work fine - what's the warning you're getting? It's probably just that getLoader() returns an untyped object so it can't verify whether or not it has a removeEventListener() method. But it does, I can assure you :)

 

Also, as far as dispatching a COMPLETE event if the loader has already finished loading, it actually does. But your code was adding the listener AFTER the event was dispatched. Your prioritize() method automatically called load() which in turn immediately dispatched the LoaderEvent.COMPLETE event (since the loader had already been loaded) but you added the event listener AFTER that. See what I mean? So you could just re-order your code like:

 

public function handleImageRequested(imgStr:String):void {
   trace ("image requested " + imgStr + " matching loader " +_imageDictionary[imgStr]);
   loaderNameStr = _imageDictionary[imgStr];
   var loader:LoaderCore = LoaderMax.getLoader(loaderNameStr); 
   loader.addEventListener(LoaderEvent.COMPLETE, handleImageLoaded);
   loader.prioritize();
}

 

Does that clear things up for ya?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...