开发者

How do I make Custom AS3 Classes accessible for data-binding?

开发者 https://www.devze.com 2023-03-08 18:02 出处:网络
A开发者_StackOverflowssume i have a costum actionscript class. public class myClass { private var myVariable:ArrayCollection;

A开发者_StackOverflowssume i have a costum actionscript class.

public class myClass

{
       private var myVariable:ArrayCollection;
...
}

Suppose also that i have a different class, that changes a second variable, which has the metadatatag [Bindable]. What methods and events do i have to implement in either of these classes, to make myVariable change, whenever the other is changend?


If you make the myVariable public, then you can just use [BindingUtils.bindProperty()][1]:

public class MyClass
{
    public var myVariable:ArrayCollection;

    public function MyClass(other:OtherClass) {

        BindingUtils.bindProperty(this, "myVariable", other, "propertyName");

    }
}

If you prefer to keep myVariable private, then you can use [BindingUtils.bindSetter()][2]:

public class MyClass
{
    private var myVariable:ArrayCollection;

    public function MyClass(other:OtherClass) {

        BindingUtils.bindSetter(
            function(newVal:*):void {
                this.myVariable = newVal;
            }, other, "propertyName");

    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号