views:

79

answers:

1

Hi,

How can I pass a 'set' function as the Function Object argument of another function? eg:

public class IdModel
{
    private var _id:String;

    public function IdModel(source:Source)
    {
        //Create Binding
        BindingUtils.bindSetter(id,source,"id");

    }

    public function get id():String
    {
        return _id;
    }

    public function set id(value:String):void
    {
        _id = value;
    }
}
}

In the example above the 'id' argument is being evaluated and returning a String, so it won't compile with the error: "String is not assignable to argument of type Function".

Thanks

+1  A: 

In this particular case you don't need to; you can use BindingUtils.bindProperty instead:

BindingUtils.bindProperty(this, "id", source, "id");

But if you really want to use bindSetter and a function you can probably do:

BindingUtils.bindSetter(function (arg:*): void { id = arg; }, source, "id");
Markus Johnsson