8 Replies Latest reply on Jul 28, 2009 2:12 AM by ShardulSingh

    list item renderer override data method problem

    flx23 Level 1

      Hi all ,

       

      i have a list and further a data renderer of it,,,when i visit the list component the item renderer override data method is executed first and later the init method of its parent component and due to which the data becomes null..and gives and error..init method should execute first..why its happening can any body tell me...here is my code

       

       

      item renderer code:-

       

      override public function set data(value:Object):void
                      {
                         
                           super.data = value;
                           obj=value;
                          // change(value);
                          trace(data.FolderName.toString());  // gives error as data is null
                       }

        • 1. Re: list item renderer override data method problem
          Madhav Subedi Level 4

          even if data is null, you can use obj as it is assigned the same value.

           

          trace(obj.FolderName.toString());

          • 2. Re: list item renderer override data method problem
            flx23 Level 1

            @Madhav Subedi

             

            well how can i use obj..as its also null as the value that i am assigning to obj..dont u think it would also be null

             

            problem is the execution of code...first the parent component init method should execute not the override method of item renderer

             

            but i my case it doing opposite first override method is called then the init of parent component..how come that..

            • 3. Re: list item renderer override data method problem
              Madhav Subedi Level 4

              have you provided the constructor, and called super() method in it?

              • 4. Re: list item renderer override data method problem
                Virat Patel

                Hello

                 

                Use like

                 

                                override public function set data(value:Object):void
                                {
                                   
                                     super.data = value;

                                    if(value != null)

                                    {
                                         obj = value;
                                        // change(value);
                                        trace(data.FolderName.toString());  // gives error as data is null

                                    }
                                 }

                 

                With Regards

                Virat Patel

                • 5. Re: list item renderer override data method problem
                  flx23 Level 1

                  Well guys my question is which method will be excuted first parent componets init method or the override method of item renderer...that is what i wana clear..in my case its item renderer's override method that executes first which results in a null DATA...

                  which is wrong the init method should execute first not the override...please clear me the question that's in bold

                  • 6. Re: list item renderer override data method problem
                    ShardulSingh Level 3

                    Hi,

                    Surely the initialize of the parent is called first,then override of the itemrenderer.
                    You can check it from the code below.Pls let me know if u have any problem.

                     

                     

                    Main Application

                     

                     

                     

                     

                     

                     

                    <mx:Application

                     

                    xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">

                     

                    <mx:Script>

                     

                    <![CDATA[

                    import

                     

                    import

                     

                    [Bindable]

                    private

                     

                    new

                     

                    '1',color:'0xFF0000', names:'John'},

                    {seq:

                    '2',color:'0x00FF00', names:'Alex'},

                    {seq:

                    '3',color:'0x0000FF', names:'Peter'},

                    {seq:

                    '4',color:'0xFF0000', names:'Sam'},

                    {seq:

                    '5',color:'0x00FF00', names:'Alis'},

                    {seq:

                    6',color:'0x0000FF', names:'Robin'},

                    {seq:

                    '7',color:'0xFF0000', names:'Mark'}

                    ]);

                     

                     

                     

                    private

                     

                    {

                     

                     

                    var dataObj : Object = event.itemRenderer.data;

                    dataObj.color =

                    "0xFF00FF";

                    event.itemRenderer.data = dataObj;

                    }

                     

                    private

                     

                    </mx:Script>

                     

                     

                    <mx:VBox

                    width="300" height="100%"

                    horizontalAlign="

                    center" verticalAlign="middle">

                     

                    <mx:List

                    id="listComponent" width="50%" height="100%"

                    borderStyle="

                    none"

                    itemRenderer="

                    listItemRenderer"

                    itemClick="onItemClick(event)" initialize="onInit()"

                    />

                     

                     

                    </mx:VBox>

                     

                     

                    </mx:Application>

                     

                     

                     

                    listItemRenderer

                     

                     

                     

                     

                     

                     

                     

                     

                     

                     

                    <?xml version="1.0" encoding="utf-8"?>

                    <mx:HBox

                    xmlns:mx="http://www.adobe.com/2006/mxml" width="100" height="30" horizontalGap="5">

                    <mx:Script>

                    <![CDATA[

                    override

                    public function set data(value:Object):void

                    {

                     

                    super.data = value;

                    }

                     

                    ]]>

                    </mx:Script>

                    <mx:Label

                    width="30" height="30" text="{data.seq}" />

                    <mx:TextInput

                    width="75" height="30"

                    text="

                    {data.names}" editable="false" color="{data.color}"/>

                    </mx:HBox>

                     

                     

                     

                     

                    Shartul Singh Bartwal

                     

                     

                     

                     

                    • 7. Re: list item renderer override data method problem
                      flx23 Level 1

                      @Shardul

                       

                      Thanks shardul but in my case its doin the opposite..can u tell me where i am wrong ...

                       

                      my item renderer code:-

                       

                      override public function set data(value:Object):void
                                      {
                                         
                                           super.data = value;
                                           if(ListBase(owner).isItemSelected(value))
                                          {
                                                  imgfolderMark.source=data.OpenFolderImg;
                                                  lblFolderName.x=30;
                                          }
                                          else
                                          {
                                              //if(data!=null)
                                                  //{
                                                      imgfolderMark.source=data.CloseFolderImg;
                                                      lblFolderName.x=38;
                                              //    }
                                          }
                                        
                                      }

                       

                      parent component code

                      • 8. Re: list item renderer override data method problem
                        ShardulSingh Level 3

                        Hi,

                        You have not provided the parent component code.I think initially your data provider is not having the data.

                        Pls check its lenght,I think it is being fill later.

                         

                         

                         

                        with Regards,

                        Shardul Singh Bartwal