How do I implement the EventDispatcher in a regular old class file? I can't seem to get it to work. Here is what I have:
Class File that I'm trying to get to implement EventDispatching as lightweight as possible.
/* imports */
import mx.events.EventDispatcher;
/**
* DatabaseConnection class is used as a wrapper for
* php script invoking.
*/
[Event("connect")]class DatabaseConnection{ // extends EventDispatcher{
private var host:String;
private var port:String;
private var username:String;
private var password:String;
private var phpSendVariables:LoadVars;
private var phpReturnVariables:LoadVars;
/**
* Constructor to create a database connection
* @param host String of the database host
* @param port String of the database port
* @param user String of the username for the database
* @param pass String of the password for the database
*/
function DatabaseConnection(host:String,port:String,user:String,pass:String){
EventDispatcher.initialize(this); this.host = host;
this.port = port;
this.username = user;
this.password = pass;
phpSendVariables = new LoadVars();
phpReturnVariables = new LoadVars();
phpReturnVariables.onLoad = onLoad;
}
/**
* Connect to a specific php script
* @param script String of the script to connect to
*/
function connect(script:String){
phpSendVariables.host = this.host;
phpSendVariables.port = this.port;
phpSendVariables.username = this.username;
phpSendVariables.password = this.password;
phpSendVariables.sendAndLoad(script,phpReturnVariables,"POST");
}
function onLoad(success){
trace("Loaded: "+success);
trace(this["result"]);
dispatchEvent({type:"connect",target:this}); }
}
Here is my fla code where I am trying to use the above class:
var dbconn = new DatabaseConnection("
www.testserver.com","3600","username","password");
var l = new Object();
l.addEventListener("connect",dbconn);
l.connect = function(obj){
trace("BOOOOOB");
}
dbconn.connect("
http://www.shortstopfoodmarts.com/reports/php/test.php");