什么是[可绑定]意味着动作? [英] What does [Bindable] mean in actionscript?

查看:202
本文介绍了什么是[可绑定]意味着动作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[Bindable]
/**
* Display output of video device.
*/              
public var videoLocal : Video;

任何人都知道?

Anyone knows?

推荐答案

[可绑定] 是一个你可以在弯曲动作code使用几个meta标签。它可以应用到被标记在任何范围属性,或方法。它不能被用于静态类成员。

[Bindable] is a one of several meta tags that you can use in flex ActionScript code. It can be applied to properties, or methods that are marked in any scope. It cannot be used with static class members.

的关键在于使用的 [可绑定] meta标签是理解,当你用它是什么引擎盖下回事。基本上使用数据绑定是添加事件侦听器,并分派事件类型速记。

The key to using the [Bindable] meta tag is understanding what is going on under the hood when you use it. Essentially using data binding is a type of shorthand for adding event listeners and dispatching events.

有在 [可绑定] 标记的两种基本形式。第一个是刚刚的 [可绑定] 其次是VAR /属性声明。二是 [可绑定(事件=eventname已)] 后跟一个VAR /属性声明,一个函数/方法的声明或二分之一的一个getter / setter方法​​声明。

There are two basic forms of the [Bindable] tag. The first is just [Bindable] followed by a var/property declaration. The Second is [Bindable(event="eventname")] followed by either a var/property declaration, a function/method declaration or one half of a getter/setter declaration.

我先解释一下再记法,因为其他建立在相同的概念,但与更多的简写。

I'll explain the longer notation first since the other builds on the same concept but with even more shorthand.

在使用 [可绑定(事件=eventname已)] 你实际上讲这个无功/性能/功能/方法(称之为实例成员)编译器是'可'以被用作源数据绑定。你也告诉它当实例成员的值已失效/更改,并且它需要重新读取,该eventName的事件将被调度。
在这个较长的形式这一切都在做什么。你的显影剂是负责实际调度每当值需要在结合用户要更新的eventName的事件。

When you use [Bindable(event="eventname")] you are essentially telling the compiler that this var/property/function/method (call this the instance member) is 'available' to be used as the source for data binding. You are also telling it that when the value of the instance member has been invalidated/changed and it needs to be re-read that the "eventname" event will be dispatched.
In this longer form this all you are doing. You the developer are responsible for actually dispatching the "eventname" event whenever the value needs to be updated in the binding subscribers.

使用数据绑定的真正的效率来自于订阅端。典型的符号,你会在MXML中看到的是值={instance.propertyName}:当您使用符号的 {} 你告诉编译器执行以下操作:

The real efficiency of using data binding comes on the subscribing side. The typical notation you will see in MXML is value="{instance.propertyName}" When you use the notation { } you are telling the compiler to do the following:

  1. 创建一个事件侦听器,监听到的可绑定元标记命名事件
  2. 在事件监听器再次读取instance.propertyName和更新此值

如果您使用更短的形式 [可绑定] ,然后你财产的/ var前添加标签,编译器填补了空白,并增加了部分附加功能,使属性可绑定。基本上你是在告诉编译器的添加你需要这个属性绑定的事件和方法
现在的方式去思考什么样的编译器在引擎盖下会做的就是这个。

If you use the shorter form [Bindable], and you add the tag before a property/var, the compiler fills in the blanks and adds some additional functionality to make the property bindable. Essentially you are telling the compiler "add the events and methods you need to make this property bindable"
Now the way to think of what the compiler will do under the hood is this.

  1. 请您变种的专用版本
  2. 创建一个事件来触发结合
  3. 创建一个getter函数与原来的VAR的范围和名称调用时返回变种的私人VERSON。
  4. 创建一个setter函数与原来的VAR的范围和名称调用时,设置变种的私人版本和调度触发事件。

在本质上,编译器会做很多为你的工作。

In essence the compiler will do much of the work for you.

    [Bindable]
    public var xyz

等同于

    private var _xyz:String;

    [Bindable(event="updateXYZValue")]
    public function get xyz():String{
        return _xyz;
    }

    public function set xyz(newxyz:String):void{
        _xyz = newxyz;
        dispatchEvent(new Event("updateXYZValue"));
    }

在这些唯一的功能上的差异在于,在第​​一个实例;

The only functional differences in these is that in the first instance;

  1. 您不知道会被分派到触发绑定
  2. 事件的名称
  3. 在没有办法更新基础值的没有的触发数据绑定
  1. you do not know the name of the event that will be dispatched to trigger the binding
  2. there is no way to update the underlying value without triggering the data binding

这第二个示例还演示了 [可绑定] meta标签中的一个特例。这是当你把它应用到你需要的只是把它应用到一个或另一个相同的变量名定义一个getter / setter方法​​对,这将适用于两者。通常情况下,你应该在getter上设置它。

This second example also demonstrates one special case of the [Bindable] meta tag. This is that when you are applying it to a getter/setter pair defined for the same variable name you need only apply it to one or the other, it will apply to both. Typically you should set it on the getter.

您可以使用一个函数/方法或者符号但是如果你没有指定一个事件的结合将永远不会被触发,所以如果你想绑定到一个函数,你应该送花儿给人指定事件。另外,也可以通过层叠标记来指定多个触发事件。如:

You can use either notation on a function/method however if you do not specify an event the binding will never be triggered so if you are trying to bind to a function you should alway specify an event. It is also possible to specify more than one triggering event by stacking the tag. eg.

    [Bindable(event="metaDataChanged")]
    [Bindable(event="metaObjectUpdated")]
    public function readMyMetaData():MetaDataObject{
        var myMetaDataObject:MetaDataObject;
            .
            .
            .

        return myMetaDataObject;
    }

这将presume了别的地方,你的类,你会分派此的 metaDataChanged 的事件或 metaObjectUpdated 的,当你想触发绑定的事件。

This would presume that somewhere else you your class you will dispatch this metaDataChanged event or the metaObjectUpdated event when you want trigger the binding.

另外请注意,这个符号可以配合任何实例成员的结合对任何事件的实例将调度。即使是继承的事件是你自己不产生如FrameEnter,的OnChange,等等...

Also note that with this notation you can tie the binding of any instance member to any event that the instance will dispatch. Even inherited events that you yourself do not generate such as FrameEnter, OnChange, etc...

数据绑定,也可以安装和运行过程中被破坏。如果您有兴趣在此就来看看在mx.binding.utils类。

Data bindings can also be setup and destroyed during runtime. If you are interested in this take a look at the mx.binding.utils classes.

这篇关于什么是[可绑定]意味着动作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆