I'm trying to disable certain items in a spark DropDownList. I found this nice 
example online, which works when you run it online:

http://apache-flex-users.2333346.n4.nabble.com/error-overriding-mx-internal-method-setSelectedIndex-td4110.html
 
http://flexponential.com/2010/01/31/spark-dropdownlist-equivalent-of-the-html-optgroup-concept/
 
http://flexponential.com/samples/OptgroupDropDownList/srcview/ 

I copied everything exactly as found above (the last link above), then modified 
OptgroupDropDownList.as in 2 places as follows: 


1. I changed mx_internal to public, then added changeCaret and 
super.setSelectedIndex() to this function (result of changes is shown):


override public function setSelectedIndex(value:int, 
dispatchChangeEvent:Boolean = false , changeCaret:Boolean = true ): void 
{ 

super.setSelectedIndex(value, dispatchChangeEvent, changeCaret); // not sure if 
this line goes here or at the end, so I tried both

if (value == selectedIndex) 
return ; 

if (value >= 0 && value < dataProvider.length){ 
if (dataProvider.getItemAt(value).selectionEnabled != false ){ 

if (dispatchChangeEvent) 
dispatchChangeAfterSelection = dispatchChangeEvent; 

_proposedSelectedIndex = value; 
invalidateProperties(); 
} 
} else { 
if (dispatchChangeEvent) 
dispatchChangeAfterSelection = dispatchChangeEvent; 

_proposedSelectedIndex = value; 
invalidateProperties(); 
} 

super .setSelectedIndex(value, dispatchChangeEvent, changeCaret); // not sure 
if this goes at end or start, so I tried both
} 


2. I added changeCaret to the following function (result of changes is shown): 


override mx_internal function setSelectedIndices(value:Vector.<int>, 
dispatchChangeEvent:Boolean = false , changeCaret:Boolean = true ): void 
{ 
var newValue:Vector.<int> = new Vector.<int>; 
// take out indices that are on items that have selectionEnabled=false 


for ( var i:int = 0; i < value.length; i++) 
{ 

var item:* = dataProvider.getItemAt(value[i]); 

if (item.selectionEnabled == false ) 
{ 
continue ; 
} 

newValue.push(value[i]); 
} 

super .setSelectedIndices(newValue, dispatchChangeEvent, changeCaret); 
} 


When I run this code on SDK 4.12, I observe that, while the mouse doesn't 
highlight the heading items in the drop down list, if I select one of these 
heading items, it DOES show as the selected item in the drop down list. That 
is, the collapsed drop down list shows this heading at the selected item (bad), 
and expanding the drop down list scrolls this heading item to the top (as if it 
were selected; also bad), although the heading item itself is not highlighted 
in the expanded drop down list (good). Thus, the skin appears to work, but the 
logic for preventing the selection of heading items isn't working.

Is there something that changed in the SDK since the code was released that 
might cause this?

Can someone run the code and help me debug it? 

Lastly, I tried placing a mouseEnabled="false" in the 
OptgroupHeadingItemRenderer in OptgroupDropDownListSkin.mxml, first in 
<s:ItemRenderer .../>, and second in <s:Label .../>, in an effort to ignore 
mouse clicks to heading items, but it had no effect. Anyone know how to achieve 
this?

Thanks in advance for any comments.

Reply via email to