Flex how to display an image loaded by the Loader class

Development, Flex April 8th, 2008

Since I can never remember how to do this I decided to make this post as a reminder.

If you need to load an image using the Loader class and then display the image as a Flex image here is the code to do it:

var loader:Loader = new Loader();
// The loader context is to check the cross domain policy file.
loader.load(new URLRequest(url), new LoaderContext(true)); 
 
// ...Later after the image is loaded.
var bitmapImage:Bitmap = Bitmap(loader.content);
anImage:Image = new Image();
anImage.source = bitmapImage;

Leave a Reply