views:

506

answers:

1

I have a custom item renderer that displays images:

<mx:DataGrid dataProvider="{friends.friend}" id="friendsGrid" width="240" 
     rowCount="3" variableRowHeight="true" headerHeight="0" 
     horizontalCenter="true" backgroundAlpha="0" borderThickness="0"
     useRollOver="false" selectable="false">
     <mx:columns>

      <mx:DataGridColumn width="80" paddingLeft="20">
       <mx:itemRenderer>
              <mx:Component>
                  <mx:HBox height="50" horizontalAlign="center" 
                   verticalAlign="middle" horizontalScrollPolicy="off" verticalScrollPolicy="off">
                      <mx:Image  source="{outerDocument.getProfilePic(data)}"/>
                  </mx:HBox>
              </mx:Component>
          </mx:itemRenderer>
         </mx:DataGridColumn>

        </mx:columns>
    </mx:DataGrid>

And a function getProfilePic:

public function getProfilePic(data:Object):String{
       if(String( data.image_path.text() ) == ""){
        return "../assets/no_profile_pic.png";
       }else{
        return data.image_path;
       }
      }

The issue is that when I assign the "no profile pic" image, it does not show up. I get that funny looking "image cannot be found" icon in place. If I place an image in ../assets on my server, the image shows up. Embedding is more ideal. So the question is...how do I embed an image in this case?

+2  A: 

Maybe try this:

<mx:itemRenderer>
    <mx:Component>
        <mx:HBox height="50" horizontalAlign="center" verticalAlign="middle" horizontalScrollPolicy="off" verticalScrollPolicy="off">
            <mx:Script>
                <![CDATA[
                    override public function set data(value:Object):void
                    {
                        super.data = value;

                        if(String(data.image_path.text()) == ""){
                            profileImage.load("../assets/no_profile_pic.png");
                        }
                        else{
                            profileImage.load(data.image_path);
                        }
                    }
                ]]>
            </mx:Script>

            <mx:Image id="profileImage" />
        </mx:HBox>
    </mx:Component>
</mx:itemRenderer>
Eric Belair
I tried this out and it works like a charm! Good luck! Write back here if you have any problems and I'll help you out...
Eric Belair
works great. thanks!
Tony
awesome...glad to help
Eric Belair