简体   繁体   English

Flex中的this.loaderInfo为null

[英]this.loaderInfo is null in Flex

I have a problem with Flex module. 我有Flex模块的问题。 I want to access url variables by this.loaderInfo.url, i call a function in createionComplete handler of module and sometimes it works and sometimes it doesn't. 我想通过this.loaderInfo.url访问url变量,我在模块的createionComplete处理程序中调用一个函数,有时它可以工作,有时它不会。 (Can't access... null). (无法访问... null)。 Any suggestions? 有什么建议?

This function is called in creationComplete handler of module. 在createComplete模块的处理程序中调用此函数。 And although it throws error window, the alert with url shows and contains url of module. 虽然它会抛出错误窗口,但是带有url的警报会显示并包含模块的url。

private function checkModuleUrl():void
{
    var url:String = this.loaderInfo.url;
    Alert.show(url);
}

在Application_COMPLETE事件触发后,最早可以从Application获取loaderInfo。

Since you are using Flex, your best bet would be: 由于您使用Flex,最好的选择是:

Application.application.url

See: Flex™ 3.5 Language Reference 请参阅: Flex™3.5语言参考

EDIT: In that case could you post more of your code especially the creationComplete code and where you call checkModuleUrl. 编辑:在这种情况下,你可以发布更多的代码,尤其是creationComplete代码和你调用checkModuleUrl的地方。 I suspect that the null reference you may be getting is due to the event that sets the loaderInfo instance on your DisplayObject not being dispatched before your call to checkModuleUrl. 我怀疑您可能获得的null引用是由于在调用checkModuleUrl之前设置DisplayObject上的loaderInfo实例未被调度的事件。

尝试一下this.root.loaderInfo

Use BrowserManager try this var bm:IBrowserManager = BrowserManager.getInstance(); 使用BrowserManager试试这个var bm:IBrowserManager = BrowserManager.getInstance(); bm.init(); bm.init(); bm.url; bm.url; for variables after the '#' use bm.fragment 对于'#'之后的变量,使用bm.fragment

There is no 'url' property for modules, the only way I found to get this info is with this function : 模块没有'url'属性,我发现获取此信息的唯一方法是使用此函数:

public static function getModuleUrl(module:Object):String {
    var loaderInfo:LoaderInfo = module.loaderInfo;
    if (loaderInfo)
        return loaderInfo.url;
    else {
        if (module.owner is ModuleLoader) {
            return ModuleLoader(module.owner).url;
        }
    }
    return null;
}

but the result is not guaranteed in which case this returns null. 但结果不能保证在这种情况下返回null。 This code works for me with modules loaded with ModuleManager or ModuleLoader. 这段代码适用于使用ModuleManager或ModuleLoader加载的模块。 Also, remember that modules may be loaded from a byte array in which case a url does not exist. 另外,请记住,可以从字节数组加载模块,在这种情况下,url不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM