I have several bitmaps in my flash library that I have exported for Actionscript. Now depending on the Flashvars I receive I want to load the corresponding library bitmap.
How do I load a bitmap class dynamically?
Basically, to attach bitmap from the library you would do this:
import flash.display.BitmapData;
import flash.display.Bitmap;
var bmp:BitmapData = new ClassNameOfTheBitmap(0, 0);
var img = new Bitmap(bmp);
addChild(img);
But since you don't know the class name, you'll have to create the class dynamically like this:
import flash.display.BitmapData;
import flash.display.Bitmap;
var classNameFromFlashvars:String = "xxx";
var cls:Class = getDefinitionByName(classNameFromFlashvars) as Class;
var bmp:BitmapData = new cls(0, 0) as BitmapData;
var img = new Bitmap(bmp);
addChild(img);
In this case, the class name in the linkage properties of the image would be xxx.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With