I can’t seem to figure this out. I’ve read about the scoping problems. I’ve seen senocular’s tutorial even. However, I can’t seem to figure out what’s wrong with this implementation.
*Note: I don’t use XML, so I prototyped the onData to get rid of the XML parsing part.
If you could help me fix this I would be very grateful. I’ve been looking at it and testing it for like two days now.
class NetworkingManager {
public var mySocket:XMLSocket;
function NetworkingManager() {
//variable to access this while inside an event
var nmObj:NetworkingManager = this;
this.mySocket = new XMLSocket();
this.mySocket.connect("localhost", 3333);
this.mySocket.onConnect = function(success) {
if (success) {
trace("Server connection established!");
} else {
trace("Server connection failed!");
}
nmObj.printData("HERE IN THE ON CONNECT")
};
this.mySocket.onClose = function() {
trace("Server connection lost");
};
this.mySocket.prototype.onData = function(msg:String):Void {
trace("DATA"+msg);
nmObj.printData(msg);
};
}
public function Ping():Void {
mySocket.send("ping");
}
public function printData(msg:String):Void {
trace("DATA: "+msg);
}
}