6 Replies Latest reply on Nov 17, 2011 12:00 AM by Flex harUI

    IconItemRender no happy with me today....

    Jason Woodcock Level 1

      Alright, simple item render, or so I thought... I have an some data loaded into a list, one of the fields is project_Type. It's a string that either says "RESIDENTIAL" or "COMMERCIAL". And based on that string, I just want to display a little house, or a little office building as the icon. So, I cobbled together my itemrender as follows:

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:IconItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                                        xmlns:s="library://ns.adobe.com/flex/spark" 
                                                        labelField="dateAdded" 
                                                        messageField="builder_Name" 
                                                        iconFunction="myiconfunction"
                                                        iconWidth="32" iconHeight="32" 
                                                        decorator="@Embed('assets/clickety-clack-32x32.png')" >
        
                <fx:Script>
                          <![CDATA[
        
        
                                    private function myiconfunction(item:Object):String{
        
                                              var type:String; 
        
                                              if  (item.project_Type == "RESIDENTIAL") { 
                                                        type = "assets/House-48x48.png";
                                              } 
                                              else if ( item.project_Type == "COMMERCIAL") { 
                                                        type = "assets/Commercial-48x48.png";
                                              } 
        
                                              return type;
        
                                    }  
        
                          ]]>
                </fx:Script>
      
      
      </s:IconItemRenderer>
      
      

       

      Seems like I did it right... BUT, when I launch it, I get:

       

       

      TypeError: Error #1009: Cannot access a property or method of a null object reference.
                at projectSearchListRenderer/myiconfunction()[C:\Users\OWNER\Adobe Flash Builder 4.5\Pro-Linx-SigmaMobile\src\projectSearchListRenderer.mxml:19]
      
      

       

      And, of course, line 19 is:

       

       

      if  (item.project_Type == "RESIDENTIAL") {

       

      But all my other fields work fine... And my data is spot on....

       

      Any ideas?

        • 1. Re: IconItemRender no happy with me today....
          robglobal

          Where are you storing the project_Type? I normally look for values in an itemRenderer using the data object: data.project_Type.

          • 2. Re: IconItemRender no happy with me today....
            Jason Woodcock Level 1

            Hmm... let me try data instead of item...

             

            Update*

             

            No dice... Still same error...

             

            Here's my list:

             

             

            <s:List id="dataGrid" includeIn="Start" left="10" right="10" top="20" bottom="20"
                                          alternatingItemColors="[#FFFFFF, #C8DEFF]"
                                          creationComplete="projectListMain_creationCompleteHandler(event)"
                                          doubleClick="currentState='Detail_Project';" doubleClickEnabled="true"
                                          downColor="#A0B2CC" interactionMode="touch" itemRenderer="projectSearchListRenderer">
            
                                <s:AsyncListView list="{getProjects_full_pagedResult.lastResult}"/>
            
            
                      </s:List>
            

             

            And here is my function:

             

                           protected function projectListMain_creationCompleteHandler(event:FlexEvent):void
                           {
                                projectsfullService.endpoint = "http://www.a-url-somewhere.com/app-resources/gateway.php";
                                getProjects_full_pagedResult.token = projectsfullService.getProjects_full_paged();
                           }  
            

             

            And my declerations:

             

            <s:CallResponder id="getProjects_full_pagedResult"/>
            <projectsfullservice:ProjectsfullService id="projectsfullService"/>
            

             

            Message was edited by: Jason Woodcock

            • 4. Re: IconItemRender no happy with me today....
              Flex harUI Adobe Employee

              Sometimes the item will be null, so you should decide what to do in that case.

              • 5. Re: IconItemRender no happy with me today....
                Jason Woodcock Level 1

                I though that might have something to do with it. So i changed the function to:

                 

                 

                private function myiconfunction(data:Object):String{

                               

                                var type:String;

                               

                                var projectType:String = data.project_Type;

                               

                                if (projectType == "RESIDENTIAL") {

                                    type = "assets/House-48x48.png";

                                }

                                else if (projectType == "COMMERCIAL") {

                                    type = "assets/Commercial-48x48.png";

                                }

                               

                                else if (projectType == "NULL") {

                                    type = "assets/Question-48x48.png";

                                }

                               

                                return type;

                               

                            }

                and it still complains:

                 

                 

                Error #1009: Cannot access a property or method of a null object reference.
                • 6. Re: IconItemRender no happy with me today....
                  Flex harUI Adobe Employee

                  That’s because this line:

                   

                  var projectType:String = data.project_Type;

                   

                  Will throw an error if data is null.

                   

                  I would do something like:

                   

                  var projectType:String = (data != null) ? data.project_Type : “RESIDENTIAL”;