I have a VERY simple class that does not work and I would like to know why. Here it is:
[SIZE=2][COLOR=#9900cc]package [/COLOR][/SIZE][SIZE=2]Test{[/SIZE][LEFT]
[LEFT][SIZE=2][COLOR=#0033ff]import[/COLOR][/SIZE][SIZE=2] mx.core.Application;[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0033ff] public[/COLOR][/SIZE]****[SIZE=2][COLOR=#9900cc]class[/COLOR][/SIZE][SIZE=2] Environment{[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0033ff] private[/COLOR][/SIZE]****[SIZE=2][COLOR=#6699cc]var[/COLOR][/SIZE][SIZE=2] CurrentURL:String;[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0033ff] public[/COLOR][/SIZE]****[SIZE=2][COLOR=#339966]function[/COLOR][/SIZE][SIZE=2] Environment(){[/SIZE]
[SIZE=2][COLOR=#0033ff] this[/COLOR][/SIZE][SIZE=2].CurrentURL = mx.core.Application.application.url;[/SIZE]
[SIZE=2][COLOR=#cc6666] trace[/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#990000]"Current URL: "[/COLOR][/SIZE][SIZE=2]+[/SIZE][SIZE=2][COLOR=#0033ff]this[/COLOR][/SIZE][SIZE=2].CurrentURL);[/SIZE]
[SIZE=2] }[/SIZE]
[SIZE=2] }[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]
[SIZE=2]The error message is “TypeError: Error #1009: Cannot access a property or method of a null object reference”. This is because mx.core.Application.application is null. My problem is that when I trace mx.core.Application.application.url in my Flex2 application it is defined, and it is the current Request URI. Why can’t I access it from within my class? Can this be some kind of namespace issue? Why does ActionScript insist on making me mad (rhetorical).[/SIZE]
[SIZE=2]Thanks in advance![/SIZE]
[/LEFT]