Forum Moderators: open

Message Too Old, No Replies

loading data into flash from external file

then using this data throught AS3

         

dgsk387

3:22 am on Jan 17, 2008 (gmt 0)

10+ Year Member



//Create the URLLOader instance
var myLoader:URLLoader = new URLLoader()
//the data will come as URL-encoded variables
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES
//Load using an URLRequest, even beeing local
myLoader.load(new URLRequest("test.php"))
//onLoad handler listener
myLoader.addEventListener(Event.COMPLETE, onDataLoad)
//Error handling
myLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError)
myLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError)
//Could be an error or just a message
myLoader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus)
//add a listener for the complete event

function onDataLoad(evt:Event){
Title_txt.text = evt.target.data.Title;
}

//error callbacks
function onIOError(evt:IOErrorEvent){
trace("IOError: "+evt.text)
}
function onHTTPStatus(evt:HTTPStatusEvent){
trace("HTTPStatus: "+evt.status)
}
function onSecurityError(evt:SecurityErrorEvent){
trace("SecurityError: "+evt.text)
}

The above code grabs a piece of data from a file called test.php:
<?php
echo "Title=hello";
?>

It works perfectly, but I want to be able to set the value (evt.target.data.Title;) to a variable and use the variable outside of the onDataLoad function. How do I create a global ActionScript variable that holds the data from the external file so I can then use that variable outside of the function?