房产门户网站模板新媒体营销中常见的知识问答平台有
news/
2025/9/23 22:46:20/
文章来源:
房产门户网站模板,新媒体营销中常见的知识问答平台有,崇明做网站公司,房屋建模软件[Bindable]大概又是Flex用得最多的元数据了。刚开始用用确实好简单#xff0c;效率真是没的说。不过这几天用着却碰到了些问题#xff0c;我自己搜集了些资料#xff0c;想着有必要在blog里总结一下吧。啥是元数据#xff08;metadata#xff09;知道就跳过吧。今天不晓得…[Bindable]大概又是Flex用得最多的元数据了。刚开始用用确实好简单效率真是没的说。不过这几天用着却碰到了些问题我自己搜集了些资料想着有必要在blog里总结一下吧。啥是元数据metadata知道就跳过吧。今天不晓得为什么livedoc.adobe.com这么慢没办法拿不到权威的解释了。我就按自己的理解随便解释一下首先要明白元数据不是语法的一部分而是专门给编译器用的说白了是告诉编译器做某些事情学过java之类的应该知道。那Bindable来讲它的作用是告诉 flex编译器给某些某些东西建立绑定关系flex编译器会在编译过程中给ASflex编译器就是把mxml编译成as再编译到swf也可能直接编译倒swf我这里假设有as这么个环节加一点事件发生和处理之类的代码由此绑定的关系便建立了如果我们用纯粹as3代码来写也是可以实现的就是太太太麻烦。啥是绑定知道继续跳过。举个例子给下面的public变量加上[Bindable][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上面终于讲到关键地方了因为getter和setter很像方法用起来会有点不同。看看这个例子[Bindable]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:int0 ; icontent.length ; i) { _w content[i] \r\n; } return _w; }}原来的设想是content绑定_wholeText可它是不工作的。为什么_wholeText太复杂了被编译器排除在“可能”之外编译器认为没有绑定关系如果只是简单的return content倒是可以的。我这里搜到了一些比较权威的解释。来自http://www.rubenswieringa.com/blog/binding-read-only-accessors-in-flex找到Ely Greenfield讲的。 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. 说白了就是为了降低复杂度和提高效率复杂情况的getter会被忽略。如何解决可以手动建立绑定即[Bindable(eventName)]。把代码改成这样[Bindable]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:int0 ; icontent.length ; i) { _w content[i] \r\n; } return _w; }}这样就避免了编译器去自动识别。自己加上绑定关系当_content被赋值发出_contentChanged事件通知所有被绑定的getter方法执行一遍。这也说明了绑定不过是事件游戏而已flex为用户隐藏了很多底层算法。转载于:https://www.cnblogs.com/panjun-Donet/archive/2010/01/08/1642224.html
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/914135.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!