Flex [Bindable] 以及使用方法
来源:互联网 发布:plc编程入门到精通 编辑:程序博客网 时间:2024/05/16 11:17
绑定:
举个例子: 给下面的public变量加上[Bindable]
public var name:String = "";
作为一个public变量,肯定既可以被赋值,也能赋值给别的变量。绑定的作用就是,当name改变的时候(被赋值了),可能通知其它被name影响(赋值给它们)的变量发生改变。这里的“可能”就需要编译器来判断,这就是为什么元数据是给编译器用的原因了。在mxml里用{}的语法的地方就是绑定的对象,比如label={xxx.name},当name变化,label也跟着变化。这样,我们只是很简单的改变了name的值,由于有绑定,界面上的label也跟着自动变化了。
能用的地方
三个地方:类, 变量, getter/setter。是不是public没有关系,private的就只能给自家用呗。用在Class上就是简单的给所有的public属性(包括变量,getter/setter,普通方法)加上[Bindable],可是一般的方法不能用[Bindable]呀,于是一般就能看到flex给了个warning,直接无视:)。变量嘛就是上面讲的,很简单略掉。
用在只读,只写属性(getter/setter)上面
private var content:Array = new Array();
[Bindable]
public function set _content(ct:String):void
{
content = ct.split(SEP);
}
[Bindable]
public function get _wholeText():String
{
if(content.length == 0)
{
return "";
}
else
{
var _w:String = "";
for(var i:int=0 ; i<content.length ; i++)
{
_w += content[i] + "/r/n";
}
return _w;
}
}
Now keep in mind that there’s no way for the compiler to actually tell if the value of a property get function would be different if called, short of doing an extensive code flow analysis of the get function, identifying all the inputs that might be affecting the value of the get function (i.e., member fields, statics, globals that are used in the get function and in any methods, global functions, closures, etc) it might call, and setting up watchers on every one of those to trigger the binding when any of them change. That’s prohibitively difficult, and expensive to do. So the compiler doesn’t try.Instead when you put [Bindable] on a get/set property, the compiler makes it bindable with a little creative rewriting that allows the framework to watch the get function, and dispatch a change event when the get function is triggered. This means that automatic bindable properties don’t work when the get function is computed from multiple values, or when you change its value by setting a backing field, rather than using the set function.It _also_ means that if you have no set function, we can pretty much guarantee that there’s no way automatically bindable get properties will be triggered. a read only propeerty is, to the compiler, completely opaque…at the moment, it has no idea where that value is coming from, and hence will never be able to ‘automatically’ trigger the binding.
private var content:Array = new Array();
[Bindable]
public function set _content(ct:String):void
{
content = ct.split(SEP);
this.dispatchEvent(new Event("_contectChanged"));
}
[Bindable("_contectChanged")]
public function get _wholeText():String
{
if(content.length == 0)
{
return "";
}
else
{
var _w:String = "";
for(var i:int=0 ; i<content.length ; i++)
{
_w += content[i] + "/r/n";
}
return _w;
}
}
- Flex [Bindable] 以及使用方法
- Flex [Bindable] 以及使用方法
- 深入分析Flex [Bindable] 以及使用方法
- 深入分析Flex [Bindable] 以及使用方法
- 深入分析Flex [Bindable] 以及使用方法
- 深入分析Flex [Bindable] 以及使用方法
- 深入分析Flex [Bindable] 以及使用方法
- 深入分析Flex [Bindable] 以及使用方法
- 深入分析Flex [Bindable] 以及使用方法[转]
- 深入分析Flex[Bindable]及使用方法
- FLEX-Bindable
- Flex: Bindable注意事项
- FLEX:Bindable标签
- flex Bindable使用讲解
- FLEX:Bindable标签
- flex-Bindable深入研究
- Flex Bindable的用法
- flex之[Bindable]
- jQuery.ui.1.7.2中文文档(官方文档翻译)
- ASP 常用函数积累
- 条款02:尽量以const, enum, inline 替换 #define
- 常用软件测试工具介绍与分析
- PHP中插件机制的一种实现方案
- Flex [Bindable] 以及使用方法
- 做事随想·时刻准备着
- 08年哈弗校长Faust给毕业生的演讲
- ASP常用函数详解
- 程序员的自我修养: 静态链接的过程
- Android widget—Gallery学习笔记
- linux 2.6 内核学习小结---硬件相关概念
- Java读取xml的四种方式
- String.split()用法的一点经验