flex4 - Flex 4: mx|tree - how can i disable items selection? -
i want create tree it's child nodes contain specific flex components created. override default itemrenderer achieve this.
in itemrenderer have:
two states:
item
,root_item
.a function executes after creation complete using data validates proper state component should in , changes
currentstate
desired state.
my problem once user clicks on of elements, changes automatically first state mess things up.
how can disable items selection @ ? of course want user able drill , down trees not select items.
thanks!
update
the item changes states on hover effect, or disable items selection or somehow prevent hover effect changing state.
another update
this code:
the main treetest.xml:
<?xml version="1.0" encoding="utf-8"?> <s:application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" minwidth="955" autolayout="false" minheight="600"> <fx:declarations> <!-- place non-visual elements (e.g., services, value objects) here --> <fx:xml id="treedata"> <node label="notifications"> <node label="winnings" is_root="yes"> <node label="winner"/> </node> <node label="challenges" is_root="yes"> </node> <node label="achievements" is_root="yes"> </node> <node label="lucky charms" is_root="yes"> </node> <node label="friend requests" is_root="yes"> </node> </node> </fx:xml> </fx:declarations> <fx:script> <![cdata[ import mx.controls.alert; import mx.controls.listclasses.listbase; import mx.events.listevent; protected function tree_itemclickhandler(event:listevent):void { tree.selecteditem = null; event.preventdefault(); } protected function tree_itemrolloverhandler(event:listevent):void { event.preventdefault(); } ]]> </fx:script> <mx:tree id="tree" itemrollover="tree_itemrolloverhandler(event)" itemclick="tree_itemclickhandler(event)" dataprovider="{treedata}" folderopenicon="{null}" folderclosedicon="{null}" defaultleaficon="{null}" width="1024" height="768" labelfield="@label" itemrenderer="treeitemrenderer" showroot="false" allowmultipleselection="false" allowdragselection="false"/> </s:application>
as can see here tried prevent both itemrollover , itemclick did not resolve problem.
this treeitemrenderer.xml:
<?xml version="1.0" encoding="utf-8"?> <s:mxtreeitemrenderer xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationcomplete="init()"> <s:states> <s:state name="root_item" /> <s:state name="item" /> </s:states> <fx:script> <![cdata[ import com.flexer.debug; import mx.binding.utils.changewatcher; import mx.controls.alert; import mx.events.statechangeevent; private function _statechangeeventhandler(e:statechangeevent):void { alert.show("state changed " + e.target.currentstate); } private function init():void { var thexml:xmllist = xmllist(this.data); var thestate:string =( thexml.attribute("is_root") == "yes" ? "root_item" : "item"); this.currentstate=thestate; this.addeventlistener(statechangeevent.current_state_change,this._statechangeeventhandler); // alert.show(thexml.attribute("is_root")); // alert.show(thexml.attribute("label") + (thexml.attribute("is_root") == "yes" ? "true" : "false")); } ]]> </fx:script> <s:hgroup left="0" right="0" top="0" bottom="0" verticalalign="middle" includein="root_item"> <s:rect id="indentationspacer" width="{treelistdata.indent}" percentheight="100" alpha="0"> <s:fill> <s:solidcolor color="0xffffff" /> </s:fill> </s:rect> <s:group id="disclosuregroup"> <s:bitmapimage source="{treelistdata.disclosureicon}" visible="{treelistdata.haschildren}" /> </s:group> <s:bitmapimage source="{treelistdata.icon}" /> <s:label id="labelfield" text="{treelistdata.label}" paddingtop="2"/> </s:hgroup> </s:mxtreeitemrenderer>
you can add event handler tree itemclick event
itemclick="tree_itemclickhandler(event)"
then in event handler can cancel itemclick event
protected function tree_itemclickhandler(event:listevent):void { tree.selecteditem = null; event.preventdefault(); }
update:
the item renderer has 3 default states: normal, hovered, , selected. need use basedon 3 default states reference custom states. ideally want state in data can avoid of work you're doing in init(). allow bind basedon state of data such:
<s:states> <s:state name="normal" basedon="{data.@state}"/> <s:state name="hovered" basedon="{data.@state}"/> <s:state name="selected" basedon="{data.@state}"/> <s:state name="root_item" /> <s:state name="item" /> </s:states>
then regardless of default state sent parent list display based upon in data.
Comments
Post a Comment