i am noob in actionscript 3 and so i have a problem and i want your help. I have one function “Login” and function “_urlSended” inside of function “Login”. So i want that sub function returned value as a parent function. I just want that script to work
<![CDATA[
function onButton1click():void {
Label1.text = Login('irakli', 'password1');
}
public function Login(username:String, password:String){
var loader:URLLoader = new URLLoader();
var request:URLRequest = new URLRequest('http://localhost/hosting/index.php');
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.username = username;
variables.password = password;
request.data = variables;
//handlers
loader.addEventListener(Event.COMPLETE, _urlSended);
loader.load(request);
function _urlSended(e:Event){
var loader:URLLoader = URLLoader(e.target);
return loader.data;
}
}
]]>
A few things – firstly, we generally reserve Uppercase variables for Class names in AS.
The problem with your code is that you set up a listener and respond to that listener within the same block. You are attempting to return data back to the listener, as it was the calling object, but listener objects have no way of handling it. So make another function, and deal with your data outside of
function login: