3 Replies Latest reply on May 28, 2007 4:24 PM by Newsgroup_User

    Back and frw in a list

    wgb14 Level 1
      Hi all

      I have the following code

      on startmovie

      myclick = 0
      end

      global myclick
      on mousedown

      mylist = ["one","two"]

      if myClick < 3 then
      myClick = min(myClick + 1, count(mylist))
      alert(mylist[myclick])

      end if

      if myClick > 3 then

      alert(mylist[myclick - 1])

      end if

      if myclick = 0 then

      alert("No more entries")
      end if
      end

      I want to check how many times the user has clicked the mouse and return the appropriate reposince from the list. Although the fwr in the list is working nicely, the backwards stacks on "two". Any idea how to solve this? I know it is a relatively simple problem but it doesn't seem to work out for me!

      Many thanks
        • 1. Re: Back and frw in a list
          Level 7
          It's not clear how you intend to manage the back/forward functions. I'm
          guessing that you want to begin by counting upwards, but when the upper
          limit is hit start going backwards until you get to the bottom, then
          reverse and go up again etc. - essentially bouncing up and down. But you
          haven't made clear your desired outcome.
          • 2. Re: Back and frw in a list
            wgb14 Level 1
            Hi Sean

            Yes, this is what i want to do! On a mousedown event the first item of the list should be disaplyed (in the above example is one but in my real application is a photograph), then on the second mousedown event the second item should be displayed (in my above example is two, but in my real application is the second photograph). Then on a third mousedown the second item should be displayed again, on the fourth mousedown the first one, on the fifth mousedown the second one and so on..... it is as you said bounching up and down. Any idea how to do that?

            Many thanks
            • 3. Re: Back and frw in a list
              Level 7
              Try something like the following:
              -- #movie script:
              global gList

              on prepareMovie
              gList = [1,2,3,4,5]
              end

              -- behavior attached to button:
              global gList

              property myIndex
              property myDirection

              on beginSprite me
              myIndex = 1
              myDirection = 1
              end

              on mouseUp me
              put gList[myIndex]
              myIndex = myIndex + myDirection
              if myIndex = count(gList) then myDirection = -myDirection
              if myIndex = 1 then myDirection = -myDirection
              end