【问题标题】:AS3: Loading SWFs in a for loopAS3:在 for 循环中加载 SWF
【发布时间】:2010-02-01 23:58:06
【问题描述】:

我正在尝试在 for 循环中加载外部 SWF,但我遇到了一个非常困扰我的问题:在事件处理程序中,我需要知道已加载的 SWF 的文件名,但我无法获取这。下面的代码显示了我正在尝试做的事情。

有人知道吗?

function loadManySWFs(arrayOfFileNames:Array)
{
    for(var i=0; i<arrayOfFileNames; i++)
    {
        var mLoader:Loader = new Loader();
        var mRequest:URLRequest = new URLRequest(arrayOfFileNames[i]));
        mLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoadComplete);
        mLoader.load(mRequest);
    }

}


function onLoadComplete(e:Event)
{
    // Here I need to know the filename of the SWF that was loaded. How can I do this?

}

感谢您的帮助!

【问题讨论】:

    标签: flash actionscript-3 event-handling closures


    【解决方案1】:

    event.target 将包含相关的LoaderInfo 对象,您可以从中检索 url。

    function onLoadComplete(e:Event):void {
        trace(LoaderInfo(e.target).url);
    }
    

    【讨论】:

    • @maxmc event.target 将是注册事件侦听器的LoaderInfo 对象。编辑修复它。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 2010-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多