Hie
I use fl.controls.DatGrid in a dashboard application developped in flash adobe cs5. I know is better in flex but I begin like this. I use yahoo layout to display the dimension without distorsion and cellRenderer to manage color externally.
But I have a bug when I scroll the datagrid manually : the column number 2 take the content of the column 1 and etc…This is a knowed bug but I can’t find a good solution to manage it. I can’t use validateNow with dataGrid to refresh because i don’t extends cellRenderer class : is there anybody having the same bug ?
Thanks in advance
Here is the code
package
{
import fl.controls.ComboBox;
import fl.controls.DataGrid;
import fl.controls.dataGridClasses.DataGridColumn;
import fl.controls.listClasses.ICellRenderer;
import fl.controls.listClasses.ListData;
import fl.core.InvalidationType;
import fl.core.UIComponent;
import fl.data.DataProvider;
import fl.events.ListEvent;
import flash.display.Bitmap;
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.net.URLRequest;
import flash.text.AntiAliasType;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;
.
public class CockpitCellRenderer extends UIComponent implements ICellRenderer
{
// … REFERENCE AL DATAGRID
private var _loader:Loader;
private var datagrid :CockPitDataGrid;
protected var _data:Object;
protected var _listData:ListData;
private var _selected :Boolean;
// ... TEXTFIELD
private var _textField :TextField;
private var _textFormat :TextFormat;
private var _w :Number;
private var _h :Number;
private var _colorCell :String;
private var bIndex:Boolean=true;
public function CockpitCellRenderer()
{
super();
buildComponents();
}
private function buildComponents()
{
buildTextFormat();
buildText();
mouseChildren = false;
buttonMode = false;
}
private function buildTextFormat():void
{
_textFormat = new TextFormat();
_textFormat.size = 10;
_textFormat.color = 0x000000;
_textFormat.font = "Verdana"
_textFormat.bold = false;
}
private function buildText():void
{
_textField = new TextField();
_textField.type = TextFieldType.DYNAMIC;
_textField.antiAliasType=AntiAliasType.ADVANCED;
_textField.height = 10;
_textField.selectable=false;
_textField.embedFonts=true;
this.addChild(_textField);
}
public function set data(newData:Object):void
{
_data = newData;
}
public function get data():Object
{
return _data;
}
public function set listData(newListData:ListData):void
{
bIndex=true;
_listData = newListData;
invalidate(InvalidationType.DATA);
invalidate(InvalidationType.STATE);
updateCell();
}
private function updateCell():void{
datagrid=CockPitDataGrid(_listData.owner);
_w=this.width;
_h = datagrid.rowHeight;
var rowcolor1:String=datagrid.dataXML.headerrow.cell[_listData.column].@rowcolor1;
var rowcolor2:String=datagrid.dataXML.headerrow.cell[_listData.column].@rowcolor2;
var colorRow:String=datagrid.dataXML.rows.row[_listData.index].@color;
var colorCol:String=datagrid.dataXML.headerrow.cell[_listData.column].@colorCol;
var colorCell:String;
if(colorCol!="" ){
colorCell=colorCol;
}else{
if(rowcolor1!="" && rowcolor2!="" ){
if(_listData.index % 2 == 0){
if(colorRow!=""){
colorCell=colorRow;
}else{
colorCell=rowcolor1;
}
}else{
//on colore ligne entiere qui doit se colorer
if(colorRow!=""){
colorCell=colorRow;
}else{
colorCell=rowcolor2;
}
}
}
}
if(datagrid.name=="smallGrid" && _listData.index==(datagrid.length-1)) _textFormat.bold=true;
drawCell(_w,_h,uint(colorCell));
_colorCell=colorCell;
if(datagrid.dataXML.headerrow.cell[_listData.column].@image=="true"){
_loader=new Loader();
var url:URLRequest=new URLRequest(Suadeo.root.xmlSite.@imageURL+_data["col"+ String(_listData.column)]);
_loader.contentLoaderInfo.addEventListener(Event.C OMPLETE,onComplete)
_loader.load(url);
_textField.text="";
}else{
var dataalign:String=datagrid.dataXML.headerrow.cell[_listData.column].@dataalign;
_textField.text = _data["col"+ String(_listData.column)];
_textField.width=_w;
_textFormat.align = dataalign;
}
_textField.setTextFormat(_textFormat);
}
private function onComplete(e:Event):void{
var bmp:Bitmap=Bitmap(e.target.content) as Bitmap;
this.addChild(bmp);
bmp.scaleX=0.6;
bmp.scaleY=0.6;
bmp.x=this.width/2-bmp.width/2;
bmp.y=this.height/2-bmp.height/2;
bmp.smoothing=true;
}
public function get listData():ListData
{
return _listData;
}
private function drawCell(w:Number, h:Number,pColor:uint):void
{
graphics.clear();
graphics.beginFill(pColor);
graphics.drawRect(1, 1, w-1, h-1);
graphics.endFill();
}
}
}
[[IMG]http://www.flashxpress.net/forum/images/buttons/edit.gif[/IMG]](http://www.flashxpress.net/forum/editpost.php?do=editpost&p=525106)