L'affectation dynamique d'une source d'image dans un rendu d'élément ne fonctionne pas dans Flex / AS3.
-
06-07-2019 - |
Question
J'ai un rendu d'élément personnalisé qui affiche des 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>
Et une fonction getProfilePic:
public function getProfilePic(data:Object):String{
if(String( data.image_path.text() ) == ""){
return "../assets/no_profile_pic.png";
}else{
return data.image_path;
}
}
Le problème est que lorsque j'attribue l'option "Pas de photo de profil". image, il ne s'affiche pas. J'ai cette drôle d'image & "; L'image ne peut pas être trouvée" icône en place. Si je place une image dans ../assets sur mon serveur, elle s'affiche. L'intégration est plus idéale. La question est donc de savoir comment intégrer une image dans ce cas.
La solution
Essayez peut-être ceci:
<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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow