This.loaderInfo is null in Flex

I have a problem with the Flex module. I want to access the url variables this.loaderInfo.url, I call the function in the createionComplete module handler, and sometimes it works, and sometimes not. (Unable to access ... null). Any suggestions?

This function is called in the makeComplete module handler. And although it gives an error window, a warning with url shows and contains the module url.

private function checkModuleUrl():void { var url:String = this.loaderInfo.url; Alert.show(url); } 
+4
source share
5 answers

The earliest thing you can get is loaderInfo from the application after the APPLICATION_COMPLETE event is fired.

+5
source

Since you are using Flex, the best choice would be:

 Application.application.url 

See: Flex β„’ 3.5 Language Reference

EDIT: In this case, you could place more of your code, especially the createComplete code, and where you call checkModuleUrl. I suspect that the null reference you can get is related to an event that sets up an instance of loaderInfo on your DisplayObject, which is not dispatched before your call to checkModuleUrl.

+1
source

Give this.root.loaderInfo try.

0
source

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

0
source

There is no url property for modules, the only way to find this information with this function is:

 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 it returns null. This code works for me with modules loaded by ModuleManager or ModuleLoader. Also, remember that modules can be loaded from an array of bytes, in which case the URL does not exist.

0
source

Source: https://habr.com/ru/post/1305323/


All Articles