Go Back   CodingForums.com > :: Client side development > Flash & ActionScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-18-2009, 12:50 AM   PM User | #1
thesmart1
Regular Coder

 
thesmart1's Avatar
 
Join Date: Dec 2005
Posts: 369
Thanks: 7
Thanked 3 Times in 3 Posts
thesmart1 is an unknown quantity at this point
Calling Private Class Method From Within An Event Handler

I have the following code to call the private class method 'foo' when 'handleConnect' is called (an onConnect handler for an XMLSocket object):
Code:
    private function foo(nameS:String):String {
        trace("HI, " + nameS);
        return "Hi, " + nameS;
    }
    private function handleConnect(success:Boolean) {
        if (success) {
            this.connected = true;
            trace("before");
            trace(this.foo("Bar"));
            trace("after");
        }
    }
The method 'foo' is never being called and the output is:
Quote:
before
undefined
after
Yet 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):
Code:
    public function Uzume(host:String, port:Number) {
        var owner:Uzume = this;
        this.connection = new XMLSocket();
        this.connection.onConnect = function (success:Boolean) {
            owner.handleConnect(success);
        }
        this.host = host;
        this.port = port;
    }
And now I got it working >.<

Last edited by thesmart1; 01-18-2009 at 01:24 AM..
thesmart1 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:06 PM.


Advertisement
Log in to turn off these ads.