2 Replies Latest reply on Sep 19, 2010 11:53 AM by jimmyoneshot

    Making An Image Visible Only When It's Source is Relevant/Valid

    jimmyoneshot Level 1

      I have an image in my app that displays images of players that has a dynamic source depending on what player is currently selected. However some players have images and some don't so obviously if a player without an image is selected the source of the image won't be valid and the none-existent image icon will be shown (or whatever exactly it is referred to as). Here is the code for the image:-

       

      <mx:Image id="playerProfile" source="assets/images/playerprofiles/{playerSurname}.jpg" visible="{}" includeInLayout="{}"/>

       

      I want to set it so that unless the source is relevant the image won't be visible and won't be included in the layout. For example the player Jones has an image jones.jpg in the assets/images/playerprofiles/ folder whereas Smith has no image so when jones is selected it will be fine and the image will appear but if Smith is selected the image won't appear and the little non-existent image icon will appear which I don't like. In this case I want the image to not appear at all. What can I insert into the visible and includeInLayout properties to achieve this effect?

       

      Thanks for any help.

        • 1. Re: Making An Image Visible Only When It's Source is Relevant/Valid
          Flex harUI Adobe Employee

          I don't think there is anything you can insert in there.  There aren't any

          properties to watch that will tell you what you want.

           

          I think it would be better to set the source property in code.  Why waste

          the cycles to fetch an image that doesn't exist?  And if you know the image

          doesn't exist, then turn off the visible and includeInLayout.

           

          If you don't know if the image exists, you might be able to use complete and

          ioerror events to set the visible and includeInLayout properties.

          1 person found this helpful
          • 2. Re: Making An Image Visible Only When It's Source is Relevant/Valid
            jimmyoneshot Level 1

            Hi mate. Sorry for the late reply. The problem is this - the image displays profile pictures of players and is always visible on the page the idea being as the user clicks each player name the image of the player changes dynamically. Each player object has a property called surname after which the images are named eg smith.jpg jones.jpg etc. Would it be better to assign each player a property called something like "hasProfileImage" which can be a boolean so if it is set to true for a player the image will appear for the selected player yet if the selected player's value is false it won't?

             

            I wanted to avoid doing this as I didn't want each player item to have too many properties but I suppose it needs to be done for this if there is no way to check if the source exists/is valid.