アイテムレンダラーで画像ソースを動的に割り当てると、Flex / AS3で機能しません

StackOverflow https://stackoverflow.com/questions/1613784

質問

画像を表示するカスタムアイテムレンダラーがあります:

<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