4 Replies Latest reply on Sep 28, 2006 4:30 AM by jake_pomme

    Displaying images from a database

    jake_pomme
      I am developing a quiz which displays randomised questions from a database using a 3rd party Xtra. Each record in the Microsoft Access database contains the question text and 4 possible answers 1 of which is the correct answer. I also need the database to hold images for each of the possible answers and have tried storing the image path i.e. Images/image1 in a text field fin the database which is then input into a text field in Director. However, I am unsure as to how to use this text in order to retrieve and display the image in Director. Can anyone help?
        • 1. Re: Displaying images from a database
          Level 7
          If I understand correctly, your query returns a string representing the
          path to an image, and you now need to display this image in Director. If
          so, you can set the filename of an existing - or newly created - #bitmap
          to this path. For example:
          -- tPath returned from query
          -- uses Buddy API, but any xtra with a 'file exists' method would do:
          if baFileExists( tPath ) then
          member("linked bitmap").filename = tPath
          end if

          You will need to make image import xtras available to your projector to
          support image types like tiff, png, etc. as well as the Mix Services xtra

          There /are/ xtras available which support databases that can store
          images natively as opposed to strings pointing to external files. You
          need to consider the implications of image files being unavailable when
          needed otherwise.
          • 2. Re: Displaying images from a database
            jake_pomme Level 1
            Thanks for this. I am now wondering whether it would be better/possible to have all the images as cast members in the movie since none of the images will ever change. Because the Director file generates 10 random questions each with 4 possible images there would be 40 bmp images stored in the cast. If I were to store the cast member names i.e. img1, img2 - img40 in the database, would it be possible to use these strings in order to display the 4 relevant images.

            For example if I had 4 empty bmp cast members named image1, image2, image3, image4 is it possible to use the 4 text strings returned from the database in order to display the relevant images in these 4 cast members?

            Hope this makes sense.
            • 3. Re: Displaying images from a database
              duckets Level 1
              As I understand it, you're considering two approaches: all your images as external files, with the filenames in your database, or all your images as castmembers, with the cast member names in your database.

              Both approaches should be fairly simple to implement.

              For the first approach, you'll need 4 empty bitmap cast members (named image1, image2, image3, image4)

              Your query will return the filenames of 4 external image files, so you need to set the filenames of your empty bitmap cast members to the filenames retrieved as Sean described above. eg:

              member("image1").filename = queryResultFilename1
              member("image2").filename = queryResultFilename2
              member("image3").filename = queryResultFilename3
              member("image4").filename = queryResultFilename4

              You then just need to make sure that you have placed those bitmap cast members on stage as sprites, and they will display the correct images.

              In your alternative approach, where you have all the images present in the cast, you will need to have one empty bitmap cast member, as a 'placeholder'. Then place 4 copies of this bitmap on stage, which creates 4 sprites.

              Your program will then need to set the cast member of each sprite to the relevant image, based on the cast member names returned by your query from the database. For example, if your 4 placeholder sprites happen to be in channels 11-14, your code might look like this:

              sprite(11).member= queryResultMemberName1
              sprite(12).member= queryResultMemberName2
              sprite(13).member= queryResultMemberName3
              sprite(14).member= queryResultMemberName4

              hope this helps,


              - Ben
              • 4. Re: Displaying images from a database
                jake_pomme Level 1
                Thanks for the help. I have decided to use the approach using all images as cast members. I have been playing around with the code and found that the following also works.

                tPath= tempList.imgCorrect
                member("image1").image = member(tPath).image
                tPath= tempList.imgIncorrect1
                member("image2").image = member(tPath).image
                tPath= tempList.imgIncorrect2
                member("image3").image = member(tPath).image
                tPath= tempList.imgIncorrect3
                member("image4").image = member(tPath).image