This is driving me nuts. This script is adding datagrids to various containers in an accordion. In my first level for-each loop the item that fills my "if(component.@component_componentID == "999999999")" is the last item looped through everything works fine except the datagrid I am building there has the wrong columns. For some reason "tempGridicd9.columns" array is returning the columns array from the tempGrid variable, and not even the version I end up with after the filter, but the original columns array. I don't even see how this is possible.
Then when they datagrid gets drawn it has the right data in it, but it has extra columns, cause the items from the else statement have 4 more columns.
I have done hours of trouble shooting on this so far. The problem will not present itself if I do not assign a dataProvider to tempGrid, for some reason that seems to be where it all blows up.
Anyone have a clue what's going on? Either I've majorly screwed up or this is a major bug. Please help!!
Here's a simple example of the XML, the real thing has a lot more nodes and a lot of attributes:
<component>
<question>
<answer/>
</question>
</component>
<component>
<icd9/>
</component>
Script With the Problem
public function populateTemplate():void{
accComponents.removeAllChildren();
for each(var component:XML in XMLTemplate.template.children()){
var newVBox:VBox = new VBox();
newVBox.id = component.@component_name;
newVBox.label = component.@component_longName;
newVBox.width = 388;
newVBox.percentHeight = 100;
accComponents.addChild(newVBox);
if(component.@component_componentID == "999999999"){//icd9component
var tempGridicd9:DataGrid = new DataGrid();
tempGridicd9.setStyle("borderStyle","none");
tempGridicd9.dataProvider = component.children();
tempGridicd9.validateNow();
//tempGridicd9.columns = tempGridicd9.columns.filter(newTempGridicd9ColFilter);
tempGridicd9.id = 'gridICD9';
tempGridicd9.headerHeight = 0;
tempGridicd9.selectable = false;
tempGridicd9.percentWidth = 100;
tempGridicd9.percentHeight = 100;
tempGridicd9.variableRowHeight = true;
tempGridicd9.columns[0].dataField = "@icd9_color";
tempGridicd9.columns[0].width = 25;
tempGridicd9.columns[0].itemRenderer = new ClassFactory(icdDot);
tempGridicd9.columns[1].dataField = "@icd9_icd9";
tempGridicd9.columns[1].width = 60;
tempGridicd9.columns[2].dataField = "@templateIcd9_name";
tempGridicd9.columns[2].width = 283;
tempGridicd9.columns[2].wordWrap = true;
tempGridicd9.columns[3].dataField = "@templateIcd9_templateIcd9ID";
tempGridicd9.columns[3].visible = false;
newVBox.addChild(tempGridicd9);
}else if(component.children().length()>0){
for each (var section:XML in component.children()){
var newPanel:Panel = new Panel();
newPanel.title = section.@sectionType_name + ": " + section.@section_name;
newPanel.width = 368;
newPanel.id = section.@section_sectionID;
newPanel.data = section.@section_sortOrder;
newPanel.addEventListener(MouseEvent.CLICK,panelClick,false,100,false);
newPanel.addEventListener(MouseEvent.MOUSE_OVER,sectMouseOver,false,100,false);
newPanel.addEventListener(MouseEvent.MOUSE_OUT,sectMouseOut,false,100,false);
newVBox.addChild(newPanel);
if(section.children().length()>0){
var tempGrid:DataGrid = new DataGrid();
var tempGridList:XMLList = section.children();
tempGridList = tempGridList.(@questionType_name!="null");
tempGridList = tempGridList.(@question_hideByUserID=="null");
tempGrid.dataProvider = tempGridList;
tempGrid.columns = tempGrid.columns.filter(tempGridColFilter);
tempGrid.id = 'grid'+ section.@section_sectionID
//There is a bug that prevents only showing one line with this:tempGrid.showHeaders = false;
//use below instead
tempGrid.headerHeight = 0;
tempGrid.width = 348;
tempGrid.columns[0].dataField="@questionDisplay";
tempGrid.columns[1].dataField="@question_questionID";
tempGrid.columns[1].visible=false;
tempGrid.columns[2].dataField="@question_sortOrder";
tempGrid.columns[2].visible=false;
tempGrid.rowCount = tempGridList.length();
tempGrid.addEventListener(MouseEvent.CLICK,qDgClick,true,1,false);
newPanel.addChild(tempGrid);
}
}
}
}
}
//This is an addon to the above function
private function newTempGridicd9ColFilter(element:*, index:int, arr:Array):Boolean{
var quickArrayicd9:Array = ["@icd9_color","@icd9_icd9","@templateIcd9_name","@templateIcd9_templateIcd9ID"]
return (quickArrayicd9.indexOf(element.dataField) != -1);
}
private function tempGridColFilter(element:*, index:int, arr:Array):Boolean{
var quickArray:Array = ["@questionDisplay","@question_sortOrder","@question_questionID"]
return (quickArray.indexOf(element.dataField) != -1);
}
Edit 12/17/09: This problem continues to infect other datagrids I create with actionScript. Am I doing something wrong with the way I am creating dataGrids on the fly?