Dhiraj Girdhar wrote:
Hi Guys,
I am using second option of setInterval, but I am not able to
understand the scope issue here.
If you pass a function, the function is not called as part of its
original class. An example:
class myClass
{
private var myNumber = 5;
public function doSomething()
{
trace("myNumber is " + myNumber);
}
}
With setInterval(doSomething, 1000), you'll trace "myNumber is
undefined" once a second, because the function is not being called as a
method of myClass, so it doesn't have access to the other members of the
class.
With setInterval(this, doSomething, 1000), it works. Or
setInterval(someOtherClassObject, otherFunction, 1000).
Imagine that if you don't specify the parent object of the method, the
method is "uprooted" from the object, and forced to exist as an
anonymous function.
Is there any solution other than Delegates? As, I am working for Flash 6 also.
Before Flash 7, I think people wrote their own Delegate classes. Perhaps
someone can provide sample code. I know that when I worked with Flash 5
and 6, I didn't know about Delegates at all, so I cursed the scope rules
daily.
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders