【问题标题】:Dynamically assigning an image source in an item renderer does not work in Flex/AS3在项目渲染器中动态分配图像源在 Flex/AS3 中不起作用
【发布时间】:2009-10-23 14:18:37
【问题描述】:

我有一个显示图像的自定义项目渲染器:

<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 中,则会显示图像。嵌入更理想。所以问题是......在这种情况下我如何嵌入图像?

【问题讨论】:

    标签: apache-flex actionscript-3 itemrenderer


    【解决方案1】:

    不妨试试这个:

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

    【讨论】:

    • 我试过了,效果很好!祝你好运!如果您有任何问题,请在这里写信,我会帮助您...
    • 太棒了!花了半天时间搞清楚itemRenderer图片回收问题。看到这个答案终于解决了!
    • 我一直在寻找一个简单的解决方案,这对我有用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-12-08
    • 1970-01-01
    • 2019-05-28
    • 1970-01-01
    • 2011-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多