Workaround for Cached URL Images in Flex
// July 21st, 2008 // Flex, Web Development
Just this past week I had found myself wrestling with a Flex application that can crop images on the fly, and display in two different places and two different sizes, a thumbnail of the new image.
One of the biggest headaches in the process was Flash’s caching of the previous URLs when another one has been added in its place. Clearly this causes an inconsistency in ‘what you see is what you get’ (WYSIWYG). So I had to find a solution.
The Image component in Flex has a cachePolicy property (inherited from UIComponent) that will ensure the component’s bitmap values are not cached, but straight URLs are not affected by this.
However, I found a workaround after a good deal of searching the net, and poking and prodding through the nooks and crannies of Flex.
Initially I was going to generate a bitmap of every image brought into the application, but the overhead would have been outrageous, and the simplicity of the program is the service call to generate the new cropped image and return the URL. But it turns out that by adding a random-numbered query string to the end of the incoming URL, the extra value will force the retrieval of the new image.
It worked like a charm, and the only drawback is that all images, changed or unchanged, are re-retrieved with every refresh of the display (in my case, when a component is set to visible, it makes a service call to populate data).
In my case, the value for the URL is kept in in a value object and in the get accessor for its value, I did the following:
1 2 3 4 | public function get urlValue():String { return _urlValue + "?" + Math.random(); } |

Thanks!
I was having this same problem, and was thinking it was going to be one of those horrible niggling issues that would take hours to resolve.
But with a little help from Google and a lot from you I can now move on to some real work.
I had the same problem in updating app chat image. Your simple tip saved my time!
Great idea but it did not work for me. I have a SOAP service that generates images according to user parameters. I write the new image to the servers hard drive and return the URL, the same URL every time. What seems to be the caching of Flex does not bring in the new image every time. I have tried setting the mx:Image components cachePolicy and cacheAsBitmaps properties but these have not effect. If I generate images with unique names (the random number tagged onto the file name) then everything works fine. The drawback is that there are a lot of images generated and cleanup routines will have to implemented for this to work in production. Any other suggestions welcome.