加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

关于flex得绑定 [bindable]

发布时间:2020-12-15 04:14:25 所属栏目:百科 来源:网络整理
导读:关于flex得绑定 [bindable] [Bindable] ? 是基于事件的,当原发生改变,会通知到目标对象。 ? 1.可以写在整个类的前面,比如 ? ???? [Bindable] ? ???? public class TextAreaFontControl extends TextArea {} ? ??? 这样会对? TextAreaFontControl 中所有的

关于flex得绑定 [bindable]

[Bindable]?
是基于事件的,当原发生改变,会通知到目标对象。?
1.可以写在整个类的前面,比如?
???? [Bindable]?
???? public class TextAreaFontControl extends TextArea {}?
??? 这样会对? TextAreaFontControl 中所有的public variables 和 public get/set?
?? 绑定?
2.可以写在variables 前面,比如?
?? [Bindable(event="fooChanged")]?
?? public var foo:String;?
3.也可以写在函数前面,?
? [Bindable("myNameChanged")]?
? public function getNmae():String {?
?????? return myName;?
? }?

? public function set myName(myName:String):void {?
???? this.myName = myName;?
???? disPatchEvent(new Event("myNameChanged"));?
? }?

? 这样所有的外部对getNmae的应用在myName改变时都会得到通知?

??? ****************************************************************??? ****************************************************************

?

?

1、在public class定义前[Bindable]元数据标签绑定所有的作为变量定义的public属性,并且所有的public属性都定义有getter和setter方法。在这种情况下,[Bindable]没有参数,例如:[Bindable]public class TextAreaFontControl extends TextArea {}flex编译器自动创建一个事件名叫propertyChange用于所有的公有属性,这些属性可以作为绑定表达式的源。这种定义等同于[Bindable(event="propertyChange")]如果属性值的改变与原来相同,flex并不传递这个事件或更新属性。2、在public,protected 或 private 属性前,格式为:[Bindable]public var foo;3、Before a public,protected,or private property defined by a getter or setter method.你必须同时定义getter和setter方法,以便于使用[Bindable]元数据标签。[Bindable]public function set shortNames(val:Boolean):void {??? ...???????????????}public function get shortNames():Boolean {??? ...}?你可以使用自定义的事件名,如:[Bindable(event="changeShortNames")]public function set shortNames(val:Boolean):void {??? ...??? // Create and dispatch event.??? dispatchEvent(new Event("changeShortNames"));}// Get method.public function get shortNames():Boolean {??? ...}????// Define public vars for tracking font size.??? [Bindable]??? public var maxFontSize:Number = 15;??? [Bindable]??? public var minFontSize:Number = 5;// Define private variable.??? private var _maxFontSize:Number = 15;??? [Bindable(event="maxFontSizeChanged")]??? // Define public getter method.??? public function get maxFontSize():Number {??????? return _maxFontSize;??? }??? // Define public setter method.??? public function set maxFontSize(value:Number):void {??????? if (value <= 30) {??????????? _maxFontSize = value;??????? } else _maxFontSize = 30;??????? // Create event object.??????? var eventObj:Event = new Event("maxFontSizeChanged");??????? dispatchEvent(eventObj);??? }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读