Make function wait for MySQL

I am new at AS3…
I got an example of ASQL from
Now I am trying to create a function that can be called and return the Data from the database.
Problem is the function returns a value before the SQL is loaded.
Can anyone help? Here is the code:

package src{
	import flash.display.Sprite;
	import src.mysql_query;

	public class logon_main extends Sprite {
		private var Data:Array = new Array;
		private var my_query:String = new String;
		public function logon_main() {
			btnSubmit_1.addEventListener(MouseEvent.CLICK, btnSubmitclick);
		 function btnSubmitclick(m:MouseEvent):void {
			my_query = ( "SELECT * FROM users u where userName='"+edtName_1.text+"'" );
			Data = mysql_query.getData(my_query);
package {
	import pl.mooska.asql.*;

	public class mysql_query {

		public function mysql_query() {
		public static function getData(my_query:String):Array {
			var connector:Asql=new Asql;//creating instance of asql
			var Data:Array=new Array;




			connector.connect("MySQL-Server","User","Password","db_name",3306);//connecting to the server //arguments are host, user, pass, database, and port

			function handleConnect(evt:SQLEvent):void {
				trace("ASQL is connected");
				connector.query(my_query);//The query
			function handleError(evt:SQLError):void {
				trace("Error catched " + evt.text);
			function handleData(evt:SQLEvent):void {
				trace("Final data received");
				Data =;
			return Data;