I'm trying to add an itemrenderer to a datagrid dynamically, 
dempending on the number of column of the dataprovider, which can be 
different everytime.

I was able to handler everything, but I got a wierd bug. Everytime I 
recive the data I get 4 error from the player saying:

TypeError: Error #1009: unable to access one property or a method of 
a reference object null.
        at views::DayRenderer/handleDataChanged()
        at 
flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchE
ventFunction()
        at flash.events::EventDispatcher/dispatchEvent()
        at mx.core::Container/set data()
        at mx.controls::DataGrid/::setupRendererFromData()
        at 
mx.controls::DataGrid/mx.controls:DataGrid::commitProperties()
        at mx.core::UIComponent/validateProperties()
        at mx.managers::LayoutManager/::validateProperties()
        at mx.managers::LayoutManager/::doPhasedInstantiation()
        at Function/http://adobe.com/AS3/2006/builtin::apply()

but if I keep pressing the continue button of the aller finally, I 
can see the results and the renderer works fine.
It look like the renderer is trying to access the property data 
before it's popolated, is this a bug or I'm doing something wrong?

renderer code (DayRenderer):

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; 
preinitialize="initComponent();"
        
        implements="mx.controls.listClasses.IDropInListItemRenderer"
>
    <mx:Script>
        <![CDATA[
            import mx.events.FlexEvent;
       
            import mx.controls.dataGridClasses.DataGridListData;
            import mx.controls.listClasses.BaseListData;
            import flash.events.Event;
            
            //Importing interface IDropInListItemRenderer 
requirements
        private var _listData:BaseListData;
                        
        public function get listData():BaseListData{
                return _listData;
        }
                        
        public function set listData(value:BaseListData):void{
                _listData = value;
                dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
        }
                        
        private var itm:Object;
        
        public function initComponent():void {
             addEventListener("dataChange", handleDataChanged);
        }    

        public function handleDataChanged(event:Event):void { 
 
           // Cast listData to DataGridListData. 
           var myListData:DataGridListData = DataGridListData
(listData);
            if(data != null){
               itm = data[myListData.dataField];
               testo.text = itm.celltype;
               testo2.text = itm.label;
            }
        }   
        ]]>
    </mx:Script>
    <mx:Text id="testo"/>
    <mx:Text id="testo2"/>
</mx:VBox>



this is the function were I build the grid;


public function setBooking():void{
     var milliSecondsPerDay:int = 86400000;
     var days:int = (toDf.selectedDate.getTime() - 
fromDf.selectedDate.getTime()) / milliSecondsPerDay;
     var newColumns : Array = new Array();
for(var i:int = 0; i < days; i++){ 
        var newColumn:DataGridColumn = new DataGridColumn("cell"+i);
        newColumn.itemRenderer = new ClassFactory views.DayRenderer);
        newColumn.headerText = "giorno "+i
        newColumns.push(newColumn);             
        
    }
    bookingList.columns = newColumns;
    bookingList.dataProvider = model.bookingData;
}






--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to