1 person found this helpful
Something doesn't feel right about that line of code. You are declaring it static, but you also have "var" in the same line. Not saying something is wrong, but I have never seen that before. From a program perspective, you are saying that "XML_PATH" won't change, but you are setting it to a variable ? So when this class starts up and is initiated what is file ? What is file. I have a feeling that neither of those are declared and that is why you are having problems.
Thanks for the quick reply UbuntuPenguin,
I understand the statement may seem odd, I don't completely understand it myself as this was some code I inherited and am attempting to use in Flex4. I'll give you the rest of my source but file is declared as an array that I am getting from a string variable that I split from an external interface call. File in this case would be the file name that I am sending to the browser. here is the code in its entirety:
private var pageURL:String = ExternalInterface.call('window.location.href.toString');
private var file:Array = pageURL.split("?")
static public var providerXML:XML = new XML();
static public var XML_PATH:String = file.toString() + '.xml';
static public var XMLPAGE:URLRequest = new URLRequest(XML_PATH);
static public var pathLoader:URLLoader = new URLLoader(XMLPAGE);
public static function xmlLoaded(evtObj:Event):void
providerXML = XML(pathLoader.data);
if you have any suggestions on how to make this cleaner I would most definitely appreciate it. I have tried to remove the static from these vars only to receive errors.
I would try to figure out the INTENT of the code first. It looks like someone was trying to run logic in their instance variable declarations. Everything other than the pageURL declaration I would run in a function, scratch that, I would run it all in a function. They way that code is put together gives me the creeps. Try something like this.
private var _pageURL:String;
private var _urlRequest:URLRequest;
private var _urlLoader:URLLoader;
public function mrClean()
pageURL = ExternalInterface.call('window.location.href.toString');
var xmlPath:String = file.toString().xml; // Where does this come from ?
_urlRequest = new URLRequest(xmlPath);
_urlLoader = new URLLoader( _urlRequest );
_urlLoader.addEventListenter( Event.COMPLETE , someFunction );
I don't know what is going on. I tried the code you posted and I ran into another issue. It tells me that 1) that addListener is an undefined property of flash.util.net and 2) that _urlloader.data is another undefined property. I'm really at a loss here and any suggestions you have would be useful. Thanks in advance.
1 person found this helpful
just to clarify there is no issue with decalring something static var
static does not imply the variable won't change (that's what const is for)
static just indicates the variable belongs to the class not an instance of the class
a typical demonstration for using static var would be to have a counter within a class to count how many times the class has been instantiated.
although i agree that the code its not very well written
Thanks for the help. Just ended up rewriting the code. Thanks.