我有以下代码
///Get BitmapData from library in SWC
var ClassReference:Class = getDefinitionByName(products[i].producticon+"Data") as Class;
// Create new BitmapData Instance From it
var bitMapS:BitmapData = new ClassReference();
// Create new Class that contains Bitmap Data
var IconBitmap:Class = new AndroidAsset(bitMapS) as Class;
// Get String name from Class
var s:String = getQualifiedClassName(IconBitmap);
trace(s);
我在跟踪中得到null。如何创建一个我可以参考此位图的动态类,类似于您从类和嵌入式媒体中引用类的方式?
答案 0 :(得分:0)
我不确定我是否完全理解你的问题,但听起来你想要一种方法来获得这种位图数据的副本,其方式类似于创建类的新实例。如果是这种情况,你可以这样做:
//grab the name of the asset as a string
var bitmapDataAssetName:String = products[i].producticon+"Data";
//get the asset definition from the SWC
var CustomBitmapDataClass:Class = getDefinitionByName(bitmapDataAssetName) as Class;
//store it in an associative array or dictionary for use later
var myBitmaps:Array = [];
myBitmaps[bitmapDataAssetName] = CustomBitmapDataClass;
//then instantiate new bitmaps from the class definition that's stored in your array
var testBitmapData:BitmapData = new (myBitmaps[bitmapDataAssetName] as Class)() as BitmapData;
因此,在实际使用场景中,您的符号定义数组将是某些BitmapManager类或其他内容的成员变量。然后,如果您想要从应用程序的任何位置访问它,只需将其设为单例,并且可以通过以下调用从您的SWC实例化新的库资源:
var localBitmapData:BitmapData = new (BitmapManager.instance.definitions[theNameOfTheBitmapIWant] as Class)() as BitmapData;
或者,更好的方法是将方法添加到BitmapManager,如
public function getBitmapAsset(assetName:String):BitmapData {
var symbolDefinition:Class = myBitmaps[bitmapDataAssetName] as Class;
return new symbolDefinition() as BitmapData;
}
所以你可以这样打电话:
var localBitmapData:BitmapData = BitmapManager.instance.getBitmapAsset("theNameOfTheBitmapIWant");
希望有所帮助(如果你开始提问的话):P