自定义Flex的Accordion组件
请问如何修改Flex的Accordion组件,实现:
1.单击Header时展开当前Header关联的Pane的内容;
2.再次单击Header时折叠当前Header关联的Pane的内容;
3.单击Header时只改变当前Header关联的Pane的折叠/展开状态,其他Pane的折叠/展开状态不变。
[解决办法]
可以写一个继承自Panel的自定义组件,实现折叠/展开状态。
然后在VBox里加入若干这些自定义组件。
[解决办法]
http://blog.csdn.net/xuhuanchao/archive/2009/12/08/4967429.aspx
[解决办法]
给你个示例代码:
<?xml version="1.0" encoding="utf-8"?><mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" borderStyle="solid" borderThickness="2"> <mx:Script> <![CDATA[ private var _child:DisplayObject; private var childChanged:Boolean = false; private var _titleText:String = ""; private var titleTextChanged:Boolean = false; private var expand:Boolean = true; private function titleClickHandler():void { var thisWidth:int = this.width; if (expand) { expand = false; vbox.visible = false; vbox.includeInLayout = false; this.width = thisWidth; } else { expand = true; vbox.visible = true; vbox.includeInLayout = true; } } public function set child(value:DisplayObject):void { if (_child != value) { childChanged = true; _child = value; } } public function get child():DisplayObject { return _child; } public function set titleText(value:String):void { if (_titleText != value) { titleTextChanged = true; _titleText = value; } } public function get titleText():String { return _titleText; } override protected function commitProperties():void { super.commitProperties(); if (childChanged && vbox != null) { childChanged = false; vbox.addChild(child); } if (titleTextChanged && title != null) { titleTextChanged = false; title.label = titleText; } } ]]> </mx:Script> <mx:VBox width="100%" height="100%"> <mx:Canvas id="titleCanvas" backgroundColor="gray" width="100%" height="25" > <mx:LinkButton id="title" textAlign="left" width="100%" height="25" click="titleClickHandler()"/> </mx:Canvas> <mx:VBox id="vbox" width="100%" height="100%" paddingLeft="3" paddingRight="3" paddingTop="3" paddingBottom="3"/> </mx:VBox> </mx:Canvas>