In AS2 you can do:

Function.prototype.bind = function(object) {
 var __method = this;
 return function() {
   __method.apply(object, arguments);
 }
}

//////

class x {
    function setFocusHandler() {
        var func = function() {
            trace("this="+this) // scope is class x
        }
        label.onKillFocus = func.bind(this);
    }
}

////

But this is just a variation on the Delagate.create(this, func) pattern

-David R

On 11/20/05, Nicolas Cannasse <[EMAIL PROTECTED]> wrote:
> > hi nicolas,
> >
> > how hard would it be to create a scope method for functions? the method
> > would take whatever you give it and put that function in to that scope.
> > for example,
> >
> > class x {
> >     function setFocusHandler() {
> >         // label.owner = this;
> >         // set scope using the scope function part of Function class
> >         label.onKillFocus.scope(this)
> >         label.onKillFocus = function() {
> >             trace("this="+this) // scope is class x
> >         }
> >     }
> > }
> >
>
> Not this way because it's not typable, but you'll be able to do the
> following in haXe :
>
> label.onKillFocus = button.onClick;
>
> (*only* if onClick is declared as a function)
>
> This is like method closures in AS3, but it will work also for
> Player6-7-8 :)
>
> Nicolas
>
> _______________________________________________
> osflash mailing list
> [email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>

_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to