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

flex 学习笔记 一个可以动态缩放的tree

发布时间:2020-12-15 04:52:12 所属栏目:百科 来源:网络整理
导读:代码:自定义的ResizeTree.as package??contr ? {? ? ????import?flash.events.*; ? ????import?flash.utils.*; ? ???? ? ????import?mx.controls.Alert; ? ????import?mx.controls.Tree; ? ????import?mx.events.TreeEvent; ? ???? ? ????public?class?Resi

代码:自定义的ResizeTree.as

 
 
  1. package??contr ?
  2. {? ?
  3. ????import?flash.events.*; ?
  4. ????import?flash.utils.*; ?
  5. ???? ?
  6. ????import?mx.controls.Alert; ?
  7. ????import?mx.controls.Tree; ?
  8. ????import?mx.events.TreeEvent; ?
  9. ???? ?
  10. ????public?class?ResizeTree?extends?Tree?{? ?
  11. ???????? ?
  12. ????????private?var?timer:Timer?=?new?Timer(10,?1); ?
  13. ????????private?var?_autoStretch_:Boolean?=?false; ?
  14. ????????[Bindable] ?
  15. ????????public?function?get?autoStretch():Boolean{? ?
  16. ????????????return?_autoStretch_;? ?
  17. ????????}? ?
  18. ???????? ?
  19. ????????public?function?set?autoStretch(value:Boolean):void{ ?
  20. ????????????_autoStretch_?=?value;? ?
  21. ????????????if?(_autoStretch_)?{ ?
  22. ????????????????this.addEventListener(Event.RESIZE,?doStretch); ?
  23. ????????????????this.addEventListener(TreeEvent.ITEM_OPEN,?startStretch);? ?
  24. ????????????????this.addEventListener(TreeEvent.ITEM_CLOSE,?startStretch);? ?
  25. ????????????????this.verticalScrollPolicy?=?"off";? ?
  26. ????????????????stretch();? ?
  27. ????????????}?else?{ ?
  28. ????????????????timer.stop(); ?
  29. ????????????????this.removeEventListener(Event.RESIZE,?doStretch); ?
  30. ????????????????this.removeEventListener(TreeEvent.ITEM_OPEN,?startStretch); ?
  31. ????????????????this.removeEventListener(TreeEvent.ITEM_CLOSE,?startStretch); ?
  32. ????????????????this.verticalScrollPolicy?=?"auto";? ?
  33. ????????????}? ?
  34. ????????}? ?
  35. ???????? ?
  36. ????????protected?function?stretch(evtObj:Event?=?null):void{ ?
  37. ????????????var?items:Array?=?this.listItems;? ?
  38. ????????????var?borderThickness:Number?=?this.getStyle("borderThickness");? ?
  39. ????????????if?(this.height?-?borderThickness?*?2?<?this.rowHeight)?{ ?
  40. ????????????????thisthis.height?=?this.rowHeight?+?borderThickness?*?2;? ?
  41. ????????????}? ?
  42. ????????????if?(this.maxVerticalScrollPosition?>?0)?{ ?
  43. ????????????????this.height?+=?this.rowHeight?-?(this.height?-?borderThickness?*?2)?%?this.rowHeight; ?
  44. ????????????????return; ?
  45. ????????????}?else?if?(items[items.length?-?1]?==?"")?{ ?
  46. ????????????????this.height?-=?this.rowHeight?+?(this.height?-?borderThickness?*?2)?%?this.rowHeight; ?
  47. ????????????????return;? ?
  48. ????????????}? ?
  49. ????????}? ?
  50. ???????? ?
  51. ????????protected?function?startStretch(evtObj:Event?=?null):void{ ?
  52. ????????????timer.stop(); ?
  53. ????????????timer.delay?=?this.getStyle("openDuration")?+?50; ?
  54. ????????????timer.start();? ?
  55. ????????}? ?
  56. ???????? ?
  57. ????????protected?function?doStretch(evtObj:Event?=?null):void{ ?
  58. ????????????timer.stop();? ?
  59. ????????????timer.delay?=?10; ?
  60. ????????????timer.start();? ?
  61. ????????} ?
  62. ???????? ?
  63. ????????protected?function?onTimerComplete(evtObj:Event?=?null):void{ ?
  64. ????????????stretch();? ?
  65. ????????}? ?
  66. ???????? ?
  67. ????????public?function?ResizeTree():void{? ?
  68. ????????????super();? ?
  69. ????????????timer.addEventListener(TimerEvent.TIMER_COMPLETE,?onTimerComplete);? ?
  70. ????????}? ?
  71. ????}? ?
  72. } ?

使用:

 
 
  1. <?xml?version="1.0"?encoding="utf-8"?>?
  2. <s:Application?xmlns:fx="http://ns.adobe.com/mxml/2009"? ?
  3. ???????????????xmlns:s="library://ns.adobe.com/flex/spark"? ?
  4. ???????????????xmlns:mx="library://ns.adobe.com/flex/mx"? ?
  5. ???????????????minWidth="955"?minHeight="600"?xmlns:logic="contr.*">?
  6. ????<fx:Declarations>?
  7. ????????<!--?将非可视元素(例如服务、值对象)放在此处?-->?
  8. ????????<fx:XMLList?id="treeData">?
  9. ????????????<node?label="选择数据集">?
  10. ????????????????<node?label="hsql">?
  11. ????????????????????<node?label="tabels">?
  12. ??????????????????????????<node?label="订单"?head="images/install.jpg"/>?
  13. ??????????????????????????<node?label="订单明细"?head="images/install.jpg"/>?
  14. ??????????????????????????<node?label="雇员"?head="images/install.jpg"/>?
  15. ????????????????????</node>? ?
  16. ????????????????</node>?
  17. ????????????????<node?label="mysql">?
  18. ????????????????????<node?label="tabels">?
  19. ??????????????????????????<node?label="demo_salesday"?head="images/install.jpg"/>?
  20. ??????????????????????????<node?label="Personal"?head="images/install.jpg"/>?
  21. ????????????????????</node>? ?
  22. ????????????????</node>?
  23. ????????????</node>?
  24. ????????</fx:XMLList>?
  25. ????</fx:Declarations>?
  26. ????<mx:VBox?backgroundColor="#CCCCCC"?width="100%"?height="100%"?verticalAlign="middle"?horizontalAlign="center">?
  27. ????????<logic:ResizeTree?dataProvider="{treeData}"?height="100"?autoStretch="true"?labelField="@label"??depthColors="[#CCCCCC,#f60f0f,#1c47e8,#31eb18]"/>?
  28. ????</mx:VBox>?
  29. </s:Application>?

效果:点击节点 打开或关闭时 tree的高度会动态变化

(编辑:李大同)

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

    推荐文章
      热点阅读