I have some strange problem with my custom list.
I defined list which needs to show list of employees. In my custom list, i want to provide selectedId property in order to select(highlight) employee with concrete id. List is created according to [http://blog.flexdevelopers.com/2010/02/flex-examples-binding-value-to-combobox.html].
This is code for my custom list...
<mx:List ....>
<mx:Script>
<![CDATA[
private var _selectedId:int;
public function get selectedId():int
{
//...
}
public function set selectedId(id:int):void
{
_selectedId=id;
invalidateProperties();
invalidateDisplayList();
}
override protected function commitProperties():void
{
super.commitProperties();
if(dataProvider!=null)
setSelectedId();
}
protected function setSelectedId():void
{
var subordinates:ArrayCollection=dataProvider as ArrayCollection;
var subordinate:EmployeeSimpleDTO=null;
for(var i:int=0;i<subordinates.length;i++)
{
var sub:EmployeeSimpleDTO=(subordinates.getItemAt(i))as EmployeeSimpleDTO;
if(sub.employeeId==_selectedId)
{
subordinate=sub;
_selectedId=sub.employeeId;
break;
}
}
selectedItem=subordinate;
}
override protected function collectionChangeHandler(event:Event):void
{
super.collectionChangeHandler(event);
invalidateProperties();
invalidateDisplayList();
}]]>
<mx:Script>
<mx:itemRenderer>
<mx:Component>
<view:SubordinatesListItem employeeId = "{data.employeeId}"
employeeName = "{data.employeeName}"
employeeSurname = "{data.employeeSurname}"
employeeUsername = "{data.employeeUsername}"/>
</mx:Component>
</mx:itemRenderer>
</mx:List>
EDIT
This is code for my item renderer
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%">
<mx:Script>
<![CDATA[
[Embed(source="/assets/employeeIcon.png")]
[Bindable]
private var employeeIcon:Class;
[Embed(source="/assets/infoIcon.png")]
[Bindable]
private var infoIcon:Class;
//-----------------------------
// private var declarations
//-----------------------------
private var _employeeId:int;
public function get employeeId():int
{
return _employeeId;
}
public function set employeeId(id:int):void
{
_employeeId=id;
}
private var _employeeName:String;
[Bindable]
public function get employeeName():String
{
return _employeeName;
}
public function set employeeName(name:String):void
{
_employeeName=name;
}
private var _employeeSurname:String;
[Bindable]
public function get employeeSurname():String
{
return _employeeSurname;
}
public function set employeeSurname(surname:String):void
{
_employeeSurname=surname;
}
private var _employeeUsername:String;
[Bindable]
public function get employeeUsername():String
{
return _employeeUsername;
}
public function set employeeUsername(username:String):void
{
_employeeUsername=username;
}
private function dispatchShowSubordinateDetails():void
{
dispatchEvent(new Event("showSubordinateDetails",true));
}
]]>
</mx:Script>
<mx:Metadata>
[Event(name="showSubordinateDetails", type="flash.events.Event")]
</mx:Metadata>
<mx:Image source="{employeeIcon}" scaleX="0.35" scaleY="0.35"/>
<mx:Label text="{employeeName} {employeeSurname}"/>
<mx:Label text=" [{employeeUsername}]" color="#8D8D8D"/>
<mx:Spacer width="100%"/>
<mx:LinkButton icon="{infoIcon}" click="dispatchShowSubordinateDetails()" width="30"/>
</mx:HBox>
In my code i bind some value on selectedId property of custom list(list is placed inside popup - TitleWindow).
Now, only on the first show up of my custom list, employee, who have id identical as selectedId, is not visually selected(colored) in list. When i said visually, i mean that i get correct object and index when i take selectedItem or selectedIndex property of my custom list.
Even more, on that critical first show up, when i roll mouse over item which should be selected, it stays selected(as she should be) after i roll out.
Subsequent show ups behave as expected.
I tried to give "plastic" description of my problem, so please, excuse me if i gave to little information. I just don't get what the problem is. Any ideas?
itemRenderer
? – bmleite