I never have a use for self refencing.. maybe thats just me, feels like
a dirty hack.
Just create reference to your class. You will need that a lot ...
function connect ()
{
mySocket = new XMLSocket ();
var _obj = this;
mySocket.onXML = function ()
{
_obj.handleIncoming();
}
}
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Jim
Phelan
Sent: Friday, 25 November 2005 2:27 PM
To: 'Flashcoders mailing list'
Subject: RE: [Flashcoders] OOP newbie question
Hi,
The problem here is scope. When you call parseMessages, you doing it in
the
scope of the mySocket object (where the method doesn't exist.)
There's a pretty simple workaround for this using the Delegate utility
that
comes with Flash.
At the top of your class file, do this : import mx.utils.Delegate;
Change this line: mySocket.onXML = handleIncoming;
To this: mySocket.onXML = Delegate.create(this,handleIncoming);
And that should solve your problem. Basically you're creating a proxy
function on the XMLSocket object that then invokes the handleIncoming
function on your OSC object. There are other ways to do this, but I
think
the Delegate method is generally considered the best practice.
Hope that helps,
Jim
-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of hbruyere
Sent: Thursday, November 24, 2005 10:19 PM
To: Flashcoders@chattyfig.figleaf.com
Subject: [Flashcoders] OOP newbie question
Hi,
Here is a OOP newbie question.
I have a class (see below)..
Everything works fine. but the method "handleIncoming" can not access ()
or
maybe even find) the method "parseMessages".
If I give the complete path to the instance of the OSC class (made in my
fla
- for example "_root.OSC_Obj.parseMessages (xmlIn);" ) it works.
How should I code this to make it works ?
class OSC
{
var mySocket : XMLSocket;
//
//
public function OSC ()
{
connect ();
}
//
//
function connect ()
{
mySocket = new XMLSocket ();
mySocket.onXML = handleIncoming;
}
//
//
function handleIncoming (xmlIn)
{
parseMessages (xmlIn);
}
//
function parseMessages (node)
{
actions......
}
}
Thanks for your attention,
//h
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders