views:

488

answers:

4

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 creationComplete 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);
}
A: 

Give this.root.loaderInfo a try.

poke
still same, firt x times no problem and then.. Cant...
Viliam Husár
+1  A: 

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.

Saheed
this is URL of application not module.
Viliam Husár
A: 

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

Prashant Dubey
A: 

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.

ozeebee