PDA

View Full Version : Simple function question...


VideoGeek
07-29-2008, 09:20 PM
For some reason, I'm stuck. I'm trying to load in a URL via a very simple XML document, but I don't seem to be able to access the var I've set up outside the function I've created.

Here's what I have:


var xmlAppLoader:URLLoader = new URLLoader();
var xmlAppRequest:URLRequest = new URLRequest("application_pointer.xml");
xmlAppLoader.load(xmlAppRequest);
xmlAppLoader.addEventListener(Event.COMPLETE, appDataLoaded);

var xmlData:XML;
var appPath:String;

function appDataLoaded(event:Event):void {
xmlData = new XML(xmlAppLoader.data);
trace(xmlData); //<------------this properly traces out the contents of my XML file just fine.
appPath = new String(xmlData.app_path);
trace(appPath); //<--------- this properly traces out the XML element I need it to, namely - the url of our media server.

}
trace(appPath); //<---------------this returns "null"


Here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<app>

<app_path>rtmp://WebFlash.its.uncc.edu/vod</app_path>

</app>


I can't seem to figure out how to get access to my appPath variable outside of this function. Elsewhere in my code, I need to use it to point to the right folder on my media server. I thought that declaring it before my function like I did would do the trick, but I'm having no luck.

Any help would be appreciated!

Thanks...

VideoGeek
07-31-2008, 08:34 PM
So i got that I need to remove "new" from my statement appPath = new String(... inside my function, but I still get a null value when I try to access that var outside the function:


var xmlAppLoader:URLLoader = new URLLoader();
var xmlAppRequest:URLRequest = new URLRequest("application_pointer.xml");

xmlAppLoader.load(xmlAppRequest); xmlAppLoader.addEventListener(Event.COMPLETE, appDataLoaded);

var xmlData:XML;
var appPath:String;

function appDataLoaded(event:Event):void {
xmlData = new XML(xmlAppLoader.data);
trace(xmlData); //<------------this properly traces out the contents of my XML file just fine.
appPath = String(xmlData.app_path);
trace(appPath); //<--------- this properly traces out the XML element I need it to, namely - the url of our media server.
}

trace(appPath); //<---------------this returns "null"