动态加载给定文件名的图像

时间:2012-02-25 22:19:05

标签: actionscript-3

我有以下代码遍历节点的XMLList:

function determineFacilities(facilities:XMLList, item:MovieClip) {
    for(var i:int = 0; i > facilities.length(); i++) {
        if(Boolean(facilities[i].text()) == true) {
            var imgName:String = facilities[i].nodeName + ".png";
            // need to load and position image here
        }
    }
}

如果当前节点的文本为真,那么我需要加载一个与节点同名的图像(加上扩展名)并定位它。

我将如何做到这一点?

感谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

var bitmap:Bitmap;

var loader:Loader = new Loader();
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
    loader.load(new URLRequest(imgName));

function onComplete (event:Event):void
{
    bitmap = Bitmap(LoaderInfo(event.target).content)
    bitmap.x = yourX;
    bitmap.y = yourY;
    addChild(bitmap)
}

摘自:How do you load a bitmap file into a BitmapData object?