我有一个显示图片的自定义项呈示器:

<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>

一个函数getProfilePic:

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

问题在于,当我指定“无配置文件图片”时图像,它没有显示出来。我看起来很有趣“无法找到图像”图标到位。如果我将图像放在我的服务器上的../assets中,则图像会显示出来。嵌入更理想。所以问题是......在这种情况下如何嵌入图像?

有帮助吗?

解决方案

也许试试这个:

<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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top