apache-flex - 如何使自定义 AS3 类可用于数据绑定(bind)?

标签 apache-flex actionscript-3 data-binding

假设我有一个服装 Action 类。

public class myClass

{
       private var myVariable:ArrayCollection;
...
}

假设我有一个不同的类,它改变了第二个变量,它具有元数据标签 [Bindable]。我必须在这些类中的任何一个中实现哪些方法和事件,以使 myVariable 更改,无论何时更改另一个?

最佳答案

如果您制作 myVariable public,那么你可以使用 [BindingUtils.bindProperty()][1] :

public class MyClass
{
    public var myVariable:ArrayCollection;

    public function MyClass(other:OtherClass) {

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

    }
}

如果您愿意保留 myVariable私有(private)的,那么你可以使用[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");

    }
}

关于apache-flex - 如何使自定义 AS3 类可用于数据绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6158805/

相关文章:

android - MvvmCross MvxBind 语法绑定(bind)到 ViewModel 本身(而不是 ViewModel.Property)

apache-flex - Flex 中 ItemPendingError 背后的设计决策是什么?

apache-flex - 在 Flex 4 列表中处理鼠标单击以查找所选项目(因为 itemClick 消失了)

actionscript-3 - 停止动态类中的某些声音,并排除其他一些声音

java - 另一个注释处理器使用的生成类

c# - 当您将列表 <> 绑定(bind)到数据网格时 - 如何更改列名?

java - 将 Flash/Flex 组件嵌入到 Java 应用程序中

c# - 是否有可能使这个 Flex/Flash 应用程序安全?

actionscript-3 - AS3 Blitting - 复制像素获取一些源图像

flash - 在私有(private)常量上使用 'static' 有什么好处吗?