View Full Version : Resolved Calling Private Class Method From Within An Event Handler

01-18-2009, 01:50 AM
I have the following code to call the private class method 'foo' when 'handleConnect' is called (an onConnect handler for an XMLSocket object):

private function foo(nameS:String):String {
trace("HI, " + nameS);
return "Hi, " + nameS;
private function handleConnect(success:Boolean) {
if (success) {
this.connected = true;
}The method 'foo' is never being called and the output is:

afterYet if I make 'handleConnect' public and call it from the first frame, it works just fine. Anyone know why it's not calling 'foo' when 'handleConnect' is called on an XMLSocket onConnect event?

EDIT: I found in the Flash help an article about event handler scope and learned that the scope is not the event handler method's parent object but rather the object that threw the event. From this information and some provided sample code, I decided to try this code in my constructor (yes, the class is called Uzume):

public function Uzume(host:String, port:Number) {
var owner:Uzume = this;
this.connection = new XMLSocket();
this.connection.onConnect = function (success:Boolean) {
this.host = host;
this.port = port;
}And now I got it working >.<