开发者

this.loaderInfo is null in Flex

开发者 https://www.devze.com 2022-12-25 01:33 出处:网络
I have a problem with Flex module. 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. (Ca

I have a problem with Flex module. 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. (Can't access... null). Any suggestions?

This function is called in cr开发者_JS百科eationComplete handler of module. And although it throws error window, the alert with url shows and contains url of module.

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


The earliest you can get the loaderInfo from the Application is after the APPLICATION_COMPLETE event fires.


Since you are using Flex, your best bet would be:

Application.application.url

See: Flex™ 3.5 Language Reference

EDIT: In that case could you post more of your code especially the creationComplete code and where you call 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.


Give this.root.loaderInfo a try.


Use BrowserManager try this var bm:IBrowserManager = BrowserManager.getInstance(); bm.init(); bm.url; for variables after the '#' use bm.fragment


There is no 'url' property for modules, the only way I found to get this info is with this function :

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. This code works for me with modules loaded with ModuleManager or ModuleLoader. Also, remember that modules may be loaded from a byte array in which case a url does not exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消