Im quite sure there is a very simple fix to my problem, but i will explain in as much detail as possible anyway.
Basically im using PHP with MySQL to send information to my flash file using GETs.
Using FlashVars i have managed to get the users ‘id’ with this i can send my questions/searches to a PHP script which access the database and returns the information to the html page.
What i would like to do now is add the information sent back to the html page to a variable inside flash for example:
var usr_name = get_user_name(id) || 'Unknown'; // "Unknown" should just be for offline use.
but this just returns ‘Unknown’
this is the function used:
public function get_user_name(usr_id){
loadData('search.php',"quest=name",'usr_id='+usr_id);
}
private function loadData(page_Name='search.php',get1='g1=1',get2='g2=2',get3='g3=3'):void {
var randomParam:String = "?p=" + Math.floor(Math.random() * (10000000));
var create_URL = (URL + page_Name + randomParam + '&'+ get1 + '&' + get2 + '&' + get3) ;
trace(create_URL);
_loader = new URLLoader();
_request = new URLRequest(create_URL);
_request.method = URLRequestMethod.POST;
_loader.addEventListener(Event.COMPLETE, onLoadData);
_loader.addEventListener(IOErrorEvent.IO_ERROR, onDataFiledToLoad);
_loader.addEventListener(IOErrorEvent.NETWORK_ERROR, onDataFiledToLoad);
_loader.addEventListener(IOErrorEvent.VERIFY_ERROR, onDataFiledToLoad);
_loader.addEventListener(IOErrorEvent.DISK_ERROR, onDataFiledToLoad);
_loader.load(_request);
}
public function onLoadData(e:Event):String {
return(e.target.data);
}
This all seems to works fine its just when i try to do with out the or statement (|| ‘Unknown’) i get this error:
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set text()
at App/frame1()
If i just type the URL into a web browser i get the name outputed.
Im not sure why this is such a problem.
Thanks
Eli
If you expect the above function to return the response string into the variable, then you are wrong.
You have to let the
onLoadDatato fill the variable itself. Try this way: