3 Replies Latest reply on Mar 21, 2009 4:01 PM by Newsgroup_User

    Random swap image

    SimonBaum09 Level 1
      Hi
      I would like to have swapping images (randomly) on one frame (not randomly change between frames). Each image should be shown four seconds, then exchanged with another random image. The swap is done automatically every four seconds.
      Can you give me some advise how this can be done? Thanks very much!

      Regards, Simon Text
        • 1. Re: Random swap image
          Level 7
          Normally I would create a behavior and attach it to the sprite that contains
          the first image. There are many, many ways to do this. You'll need a
          timer. You could create your own or use a timer object. The time check
          should be in the exitFrame handler of the behavior and when the timer
          expires (4 seconds in your case) it would trigger the changing of an image
          and then reset itself for another 4 seconds.

          Somehow you'll need to let the behavior know what the inventory of images
          is. I would probably create a separate cast and cycle through the non-empty
          cast members in that cast.

          In programming there are endless opportunities for error checking, for
          example, checking to make sure the cast member you're about to use is not
          empty and if it isn't to make sure it's an image member and not something
          else. Coding with this in mind avoids errors but also can add a lot of
          (often valuable but necessary) time to the coding process.

          If you need some code written just say so.

          --
          Craig S. Wollman

          Word of Mouth Productions
          159-00 Riverside Drive West
          New York, New York 10032
          (212) 928-9581
          "SimonBaum09" <webforumsuser@macromedia.com> wrote in message
          news:gq0f75$avu$1@forums.macromedia.com...
          > Hi
          > I would like to have swapping images (randomly) on one frame (not randomly
          > change between frames). Each image should be shown four seconds, then
          > exchanged
          > with another random image. The swap is done automatically every four
          > seconds.
          > Can you give me some advise how this can be done? Thanks very much!
          >
          > Regards, Simon Text
          >


          • 2. Re: Random swap image
            SimonBaum09 Level 1
            Hi Craig

            Thanks very much for your answer. I tried some coding but I'm just not experienced enough. Could you show me some code examples please, especially the behaviour, that is attached to the sprite.

            Best Regards

            Simon
            • 3. Re: Random swap image
              Level 7
              Well, there are 3 steps. One is to make the sprite so it can change
              images. Two is to make a timer that changes it. And three is setting it
              up to pick a random one. So, you would put this on the #bitmap sprite
              that you want to be changeable...

              on changeImage me, vMemberName
              sprite(me.spriteNum).member=vMemberName
              end

              And this in a #movie script (NOT a behaviour). Watch for inadvertent
              line breaks due to the forum system... and I just did this off the top
              of my head, so I apologize for any accidental misspellings...


              global gPickList

              on startMovie
              --start the timeout to go off every 4 secs
              vTimeOut = timeOut("FourSecTimer")
              if ilk(vTimeOut) = #timeout then vTimeOut =
              timeOut("FourSecTimer").new(4000, #FourSecTimer)
              else vTimeOut = timeOut().new("FourSecTimer", 4000, #FourSecTimer )

              --define the list of images that will be changable
              gPicList=["image 1","image 2","All","the","memberNames",'that","you","want"]

              end

              on FourSecTimer
              --pick a random number from the number of images in the list
              iRandom=random(gPicList.count)
              sendAllSprites(#changeImage,gPicList[iRandom])
              end


              It would be best if the images were all the same size. If they are not,
              then you'd have to write a little more code to make the image fit into
              the right size.