- 浏览: 1560122 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (571)
- Flex (301)
- AIR (5)
- ComPiere (8)
- ExtJS (15)
- SAP (0)
- jBPM (3)
- Java-Hibernate (5)
- Java-Spring (10)
- XML (2)
- java-web (30)
- db2 (2)
- websphere (4)
- Google (5)
- 虚拟机 (10)
- eclipse (8)
- Win2003 (11)
- Ubuntu (27)
- VMware (4)
- CentOS (3)
- JSON (1)
- Oracle (15)
- SilverLight (1)
- 大事记 (6)
- VirtualBox (5)
- Solaris (10)
- AIX (6)
- 云计算 (10)
- MacOS (4)
- iOS (1)
- SQLite (1)
- Activiti (1)
- jdk (5)
- hadoop (8)
- Ant (4)
- PhoneGap (2)
- JavaScript (11)
- jQuery (1)
- FireFox (1)
- HBase (2)
- sqoop (0)
- ffmpeg (7)
- mencode (0)
- jdbc (1)
- SQLServer (1)
- 组件平台 (12)
- struts2 (4)
- intellj (4)
- android (1)
- ExtJS4 (1)
- 色卡司 (1)
- Linux (3)
- ExtJS5 (1)
- zookeeper (2)
- maven (1)
- Java (6)
- vpn (0)
- squid (1)
- MySQL (2)
- webpackage (1)
- antd (1)
- lucene (1)
最新评论
-
qq_24800465:
请问这里的库从哪下载啊
ffmpeg所有的编码器(encoders) -
neusoft_jerry:
貌似这里没用到StreamingAMFChannel哦,只是用 ...
Flex BlazeDS 推送技术 -
anyone:
感谢你的博文,看了受益匪浅
记住这个IntelliJ IDEA的编译设置 -
keren:
现在还有什么应用需要用flex来开发的?
flex tree的展开,关闭,添加、删除子节点 -
neusoft_jerry:
简洁明快,好贴好贴!楼主V5!
flex tree的展开,关闭,添加、删除子节点
覆盖核心 UIComponent 方法
Whenever I am working on a Flex project, it is quite seldom that I have been able to take an out of the box component and have it do EXACTLY what I need to do (barring something like a Label). Sometimes I need to create a container component to use as an itemrenderer for a grid. However, sometimes it is not as easy as whipping up some mxml tags to layout what we need. Luckily though, there are 5 methods that every UIComponent implements* that we are able to override and manipulate our objects as we wish. These methods are createChildren, commitProperties, measure, layoutChrome and updateDisplayList. I will be giving a brief explaining of what they are and why we would override them. After that, I will be discussing the flags within UIComponent.as that call these functions and some things to watch out for when overriding these functions.
createChildren
By far the easiest to explain, createChildren does just that. This method is pretty much used to add the children of the component. Aside from that, you are able to set some default settings, event listeners and styles.
commitProperties
When I have used this, I have used it to set state specific properties of my component. IE: changing the color depending on a value, setting flags, etc. Also if your component implements IListItemRenderer or IDropInListItemRenderer, your data or listData values will be set by the time they your component reaches commitProperties.
measure
The Measure function is about as easy to explain as creareChildren. Within here, you are able to set your components default height/width, as welll as minimum/maximum height/width. However, the way this function gets called is a little unique when compared to the other functions, while I will discuss in a bit.
layoutChrome
layoutChrome is used to set the boarders of any Container class that you are extending off of. If any of these functions was the forgotten stepchild, it is this function. I have only run into a situation once where I needed to implement it. However, the one time I got to use it, I pulled my hair out because I ran into an instance where Adobe wanted to protect me and I had to use the mx_internal namespace.
updateDisplayList
If layoutChrome is the forgotten step child, updateDisplayList is the most popular child, and for good reason. This is the component that sets its position and size (if need be) and the component will not be displayed until it is called. For container objects that have more than one component, this is the function that allows you to manually position those components based off of its current state. A perfect example of this would be an HBox of VBox. Your components are positioned horizontally or vertically within updateDisplayList.
With these five functions, you will be able to create any componet that you can think of. But what calls these functions? Turns out that within UIComponent, there are three flags which are set by these functions:
When this is called, it marks your component to call commitProperties upon the next render update.
When this is called, it will call both layoutChrome, as well as updateDisplayList.
This is the interesting one. Calling this method will mark the measure() function to be called, but there is one slight variation on this one. If I update the x value on a component, it will be marked as invalid and updateDisplayList will be called upon the next render event. If a data event gets fired, its marked as invalid and commitProperites is called. However, if I change the height, measure will not be called. Flex will only call measure() if you set explicitHeight or explicitWidth to NaN.
What to watch out for
When people implement these functions, sometimes they do not realize the power they have taken responsibility of. They are to be treated with the respective they deserve. First, do not forget to call the super method of each functions. That may drop you in the land of some angry times if you dont. Another thing I have seen is people sometimes get tempted to add children inside of something like commitProperties or updateDisplayList. This may cause serious performance issues. Whenever addChild is called, invalidateProperties and invalidateDisplayList is called, creating a big mess. It is best to use these functions for only their intended purpose.
It is hard to be a Flex programmer with out having to dive into to the world of creating your own components. Out of the box functionality often does not give us what we need. With these functions, you will be able to create any component you need from the ground up.
*Layoutchrome is included in anything that extends the Container class. A large number of components utilize this, but UIComponent does not.
本文来源于 冰山上的播客 http://xinsync.xju.edu.cn
原文地址:http://xinsync.xju.edu.cn/index.php/archives/4869
Whenever I am working on a Flex project, it is quite seldom that I have been able to take an out of the box component and have it do EXACTLY what I need to do (barring something like a Label). Sometimes I need to create a container component to use as an itemrenderer for a grid. However, sometimes it is not as easy as whipping up some mxml tags to layout what we need. Luckily though, there are 5 methods that every UIComponent implements* that we are able to override and manipulate our objects as we wish. These methods are createChildren, commitProperties, measure, layoutChrome and updateDisplayList. I will be giving a brief explaining of what they are and why we would override them. After that, I will be discussing the flags within UIComponent.as that call these functions and some things to watch out for when overriding these functions.
createChildren
override protected function createChildren():void{ super.createChildren(); if (!_button){ _button = new Button(); _button.addEventListener(MouseEvent.CLICK,handleEvent); _button.setStyle("color",0xFF0000); addChild(_button); } }
By far the easiest to explain, createChildren does just that. This method is pretty much used to add the children of the component. Aside from that, you are able to set some default settings, event listeners and styles.
commitProperties
override protected function commitProperties():void { super.commitProperties(); if (dataChanged){ isDirty=true; } }
When I have used this, I have used it to set state specific properties of my component. IE: changing the color depending on a value, setting flags, etc. Also if your component implements IListItemRenderer or IDropInListItemRenderer, your data or listData values will be set by the time they your component reaches commitProperties.
measure
override protected function measure():void { super.measure(); this.measuredHeight=16; this.percentWidth=100; this.minHeight=5; }
The Measure function is about as easy to explain as creareChildren. Within here, you are able to set your components default height/width, as welll as minimum/maximum height/width. However, the way this function gets called is a little unique when compared to the other functions, while I will discuss in a bit.
layoutChrome
override protected function layoutChrome(unscaledWidth:Number,unscaledHeight:Number):void{ if(border){ border.setActualSize(w,h); } }
layoutChrome is used to set the boarders of any Container class that you are extending off of. If any of these functions was the forgotten stepchild, it is this function. I have only run into a situation once where I needed to implement it. However, the one time I got to use it, I pulled my hair out because I ran into an instance where Adobe wanted to protect me and I had to use the mx_internal namespace.
updateDisplayList
override protected function updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void{ super.updateDisplayList(unscaledWidth,unscaledHeight); var o:Object; var yOffset=10; for (var x:int=0;x<numChildren;x++){ o = getChildAt(x); yOffset += o.height; o.move(o.x+OFFSET,yOffset); } }
If layoutChrome is the forgotten step child, updateDisplayList is the most popular child, and for good reason. This is the component that sets its position and size (if need be) and the component will not be displayed until it is called. For container objects that have more than one component, this is the function that allows you to manually position those components based off of its current state. A perfect example of this would be an HBox of VBox. Your components are positioned horizontally or vertically within updateDisplayList.
With these five functions, you will be able to create any componet that you can think of. But what calls these functions? Turns out that within UIComponent, there are three flags which are set by these functions:
invalidateProperties()
When this is called, it marks your component to call commitProperties upon the next render update.
invalidateDisplayList()
When this is called, it will call both layoutChrome, as well as updateDisplayList.
invalidateSize()
This is the interesting one. Calling this method will mark the measure() function to be called, but there is one slight variation on this one. If I update the x value on a component, it will be marked as invalid and updateDisplayList will be called upon the next render event. If a data event gets fired, its marked as invalid and commitProperites is called. However, if I change the height, measure will not be called. Flex will only call measure() if you set explicitHeight or explicitWidth to NaN.
What to watch out for
When people implement these functions, sometimes they do not realize the power they have taken responsibility of. They are to be treated with the respective they deserve. First, do not forget to call the super method of each functions. That may drop you in the land of some angry times if you dont. Another thing I have seen is people sometimes get tempted to add children inside of something like commitProperties or updateDisplayList. This may cause serious performance issues. Whenever addChild is called, invalidateProperties and invalidateDisplayList is called, creating a big mess. It is best to use these functions for only their intended purpose.
It is hard to be a Flex programmer with out having to dive into to the world of creating your own components. Out of the box functionality often does not give us what we need. With these functions, you will be able to create any component you need from the ground up.
*Layoutchrome is included in anything that extends the Container class. A large number of components utilize this, but UIComponent does not.
本文来源于 冰山上的播客 http://xinsync.xju.edu.cn
原文地址:http://xinsync.xju.edu.cn/index.php/archives/4869
发表评论
-
extjs结合flex(flash)的注意事项.
2014-01-02 17:11 2397//for fix bug //flash里使 ... -
flash(flex)crossdomain dtd规范
2013-12-27 13:38 953dtd文件位置: http://www.macromedia. ... -
flash内嵌在html里面的代码
2013-12-27 09:19 1194<!-- 除IE外都可识别 --> < ... -
FlashBuilder4.5 ADT命令详解(官方)
2011-12-16 17:45 1252http://help.adobe.com/en_US/air ... -
FlashBuilder4.5加入ADT插件
2011-12-16 17:24 1809参考: http://renaun.com/blog/2011 ... -
Flex as3commons log的简单使用
2011-11-28 20:26 1594http://www.as3commons.org/ &l ... -
Flex日志工具汇总
2011-11-27 16:29 1247巨兽 monster [能调试 mobile和web air] ... -
【转】[Flex]我经常使用的Flex Tools 和 Resource
2011-11-22 08:36 1307http://www.k-zone.cn/zblog/post ... -
[转]Flex Socket安全策略<policy-file-request/>及应对方法
2011-08-27 16:43 1726http://hi.baidu.com/dobodo/blog ... -
flash 安全策略文件
2011-08-27 16:31 2149<?xml version="1.0&qu ... -
Request请求头的格式
2011-08-27 15:38 2361每次提交http请求时,请求头是什么样的的格式呢? GET方 ... -
flash Tooltip类
2011-08-27 15:06 1137http://www.flepstudio.com/flash ... -
flash SQLite包装类
2011-08-27 15:00 2231[转]http://www.flepstudio.com/fl ... -
[转](原创)flex解决跨域问题的策略文件的写法
2011-08-04 09:59 1557http://hi.baidu.com/wosinmaiken ... -
[转](整理)flex常用验证控件
2011-08-04 08:30 1381http://hi.baidu.com/wosinmaiken ... -
Flex4.5 skin组建皮肤的应用
2011-07-28 08:52 2815http://www.iyoya.com/2011/06/04 ... -
如何成为一个合格的iOS开发者?
2011-07-17 14:59 1346转:http://www.adobe.com/cn/devne ... -
flex4.5移动设备开发-添加应用背景图片
2011-07-17 10:50 2291【转】http://spy6.blogspot.com/201 ... -
flex4.5移动设备开发-应用访问权限设置
2011-07-16 14:19 1361在构建flex4.5 mobile application的时 ... -
flex4.5移动设备开发-表格效果
2011-07-15 23:12 1804做了个实验,没想到做出表格的效果
相关推荐
重写window.alert方法 重写window.alert方法
方法重写又称方法覆盖。 若子类中的方法与父类中的某一方法具有相同的方法名、返回类型和参数表,则新方法将覆盖原有的方法。 如需父类中原有的方法,可使用super关键字,该关键字引用了当前类的父类。
方法重写又称方法覆盖。 (2)若子类中的方法与父类中的某一方法具有相同的方法名、返回类型和参数表,则新方法将覆盖原有的方法。 如需父类中原有的方法,可使用super关键字,该关键字引用了当前类的父类...
重载,重写,覆盖,多态的深刻剖析,具体分析了重载,重写,覆盖,多态之间的区别
重写equals和hashcode方法,学习和进步
这篇文章主要介绍了C++中重载、重写(覆盖)和隐藏的区别,是C++面向对象程序设计非常重要的概念,需要的朋友可以参考下
重写toString和equals方法的意义以及方法
重写:是指重写基类的方法,在基类中的方法必须有修饰符virtual,而在子类的方法中必须指明override。重载:用于在给定了参数列表和一组候选函数成员的情况下,选择一个最佳函数成员来实施调用。多态:c#的多态性...
Java 中重写又叫覆盖,主要是指继承(extends)父类或者实现(implements)接口时将父类或者接口中已经存在的方法进行重新定义。重写的方法在父类或者接口中必须存在。 注意:后文的重写方法与覆盖方法同义 ...
Safe PHP:重写一组核心PHP函数以抛出异常,而不是在遇到错误时返回false
10.java方法的重写.zip10.java方法的重写.zip10.java方法的重写.zip10.java方法的重写.zip10.java方法的重写.zip10.java方法的重写.zip10.java方法的重写.zip10.java方法的重写.zip10.java方法的重写.zip10.java方法...
C#重写MessageBox对话框C#重写MessageBox对话框C#重写MessageBox对话框C#重写MessageBox对话框C#重写MessageBox对话框C#重写MessageBox对话框C#重写MessageBox对话框
本文讲述了什么时候重写equals方法和如何重写equals方法。
<html> <head> <... charset=gb2312" /> [removed] function myblur () { ...myblur方法被覆盖了!"); }); } [removed] </head> <body> <input type="text" onb
1、重载 方法的重载是同一个类中多态性的一种表现。 方法重载须遵循如下两条规则 (1)方法名相同。 (2)参数列表不同。... (4)子类方法不能抛出比所覆盖方法更多的异常。 (5)静态方法不存在重
静态(static)方法重写(override)
当使用jdk中GZIPInputStream读取.gz文件时,有时还未到文件结尾,则也会返回-1,该工具类解决了此bug
JAVA中的方法重写与方法重载的区别,还算挺详细的
关于重写equals,hashcode以及compareTo方法!