Using Flex Image events to show a preloader
Today I wanted to show a simple preloader in an itemRenderer that just contained one Image. The problem was to get the image’s events before it was too late since you just can’t catch the OPEN, PROGRESS or COMPLETE event via MXML (Why did’t they just add the metadata for that?). I have seen quite a few approaches which extended the Image class but I wanted to use a custom Image class (SuperImage) to use it’s caching capabilities. So here is the example, I’m using a normal Image here but you can use any derived class you want, it just has to use the 3 events: (You might use the following as an ItemRenderer)
(Argh! WordPress destroyed the source code, I’ll repost it soon)
That’s it, using states it isn’t too hard to change the UI. If you need cool preloaders go checkout http://www.ajaxload.info – they will generate a gif which you can easily import into the Flash IDE to convert it to swf.