Hmm, rather than the last modification I offered below, I can add one line to 
get it working (see below). I'm wondering how the original code could work 
without it... 



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

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

if (dispatchChangeEvent) 
dispatchChangeAfterSelection = dispatchChangeEvent; 

_proposedSelectedIndex = value; 
invalidateProperties(); 
} 
else { value=-1; } // ADD THIS LINE 

} else { 
if (dispatchChangeEvent) 
dispatchChangeAfterSelection = dispatchChangeEvent; 

_proposedSelectedIndex = value; 
invalidateProperties(); 
} 

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

----- Original Message -----

From: [email protected] 
To: "users, apache" <[email protected]> 
Sent: Monday, September 8, 2014 6:35:00 AM 
Subject: Re: attached code to disable certain items in spark DropDownList not 
working 

I'm not understand how the original code in function setSelectedIndex() in 
OptgroupDropDownList.as is supposed to work when selectionEnabled is false. If 
I modify it, including directly changing value to -1 when 
selectionEnabled=false, it seems to work. Of course, I'm fairly new to Flex, 
and not comfortable with these inner workings. Are my changes OK, or why 
doesn't the original code work to prevent selection when 
selectionEnabled=false? 


THE ORIGINAL FUNCTION: 

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 
} 

HOW I MODIFIED IT: 



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

if (value == selectedIndex) 
return; 

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

if (dispatchChangeEvent) 
dispatchChangeAfterSelection = dispatchChangeEvent; 

_proposedSelectedIndex = value; 
invalidateProperties(); 

} else { // I changed the location of this to place it inside previous brackets 

if (dispatchChangeEvent) 
dispatchChangeAfterSelection = dispatchChangeEvent; 
value=-1; // isn't this needed to prevent the selection? 
_proposedSelectedIndex = value; 
invalidateProperties(); 

} 
} 
super.setSelectedIndex(value, dispatchChangeEvent, changeCaret); 
} 

----- Original Message ----- 

From: [email protected] 
To: "users, apache" <[email protected]> 
Sent: Monday, September 8, 2014 6:00:23 AM 
Subject: attached code to disable certain items in spark DropDownList not 
working 

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