It seems to be typo error.
private var request:URLRequest;
private var xmlData:XML;
private var loader:URLLoader = new URLLoader();
private function loadXML(event:Event):void
{
xmlData = new XML(event.target.data); //Note here data instead of date.
}
private function load():void
{
request = new URLRequest("http://localhost/demo/TextXmlFile.xml");
request.contentType = "XML";
request.method = URLRequestMethod.POST;
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(request);
}
Reason :
You can only do declare and initialize/instantiate object out side of functions.
Normally compiler expect out side of function should be variable declaration(protected/public/private
). So we can't assign value of those at out of function like
request.contentType = "XML";
request.method = URLRequestMethod.POST;
This is exact place where function comes in. Sometime it is possible with static block
if all neccessary function and variable should be static.
More details about AS3 Static Block https://www.google.co.in/search?q=static+block+in+as3
or Check out SO Can we use static initializers in a Flex Library?
Check docs: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLLoader.html