Bits & Bytes

Loading an Image Into a Bitmap in Actionscript 3.0

The code below shows how to load a remote image and store it in a Bitmap object (this works for local images too). We begin by creating a Loader object, setting the callback function OnImageLoad() to get called when the image is done loading, and then calling the load() function to load the image. The OnImageLoad() function casts the loaded content to a Bitmap, where the BitmapData is used to create a new Bitmap that is added to the stage for display.

const ksXoaXLogo:String = "";

var qLoader:Loader = new Loader();
qLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, OnImageLoad);
qLoader.load(new URLRequest(ksXoaXLogo));
function OnImageLoad(e:Event):void {
    var qTempBitmap:Bitmap 	= qLoader.content as Bitmap;
    var qBitmap:Bitmap		= new Bitmap(qTempBitmap.bitmapData);

Tags: , , , , , , , ,

Michael Hall

By: Michael Hall

Leave a Reply



© 2007–2022 LLC. All rights reserved.