1 Reply Latest reply on Apr 16, 2006 7:14 PM by Newsgroup_User

    Random quotes without repeat

    mikeinoz
      I have a basic ynamic text box importing random quotes from an external .txt file. How can I get the quotes to display without repeating until all of the quotes have been viewed?

      Thanks in advance.
        • 1. Re: Random quotes without repeat
          Level 7
          mikeinoz,

          > I have a basic ynamic text box importing random quotes
          > from an external .txt file. How can I get the quotes to
          > display without repeating until all of the quotes have
          > been viewed?

          Least complicated way I can think of is to store your quotes in an
          array, "shuffle" the array, then dole out your quotes one by one. Once
          shuffled, you can move through your array in order, and the quotes will of
          course be random -- and you'll hit every last one.

          So ... I'm not sure what you mean by a "basic" scenario. I don't know
          how your external text file is setup. You could put all your quotes into
          one long string -- in other words, one name/value pair in your external text
          file -- and use the String.split() method to convert your string into an
          array. See the ActionScript Language Reference for details ... you could
          use a rare character like pipe, |, to separate your quotes.

          Once you have the array, you can use any of the popular methods for
          shuffling. Search the forum archives for kglad's shuffle prototype or check
          out my recent blog entry on Array.sort() ...

          http://www.quip.net/blog/2006/flash/actionscript-20/getting-the-most-array-sort

          Once you have a shuffled array, you can use a number variable to step
          through each array index. If you need help with that, post back with
          specific questions.


          David
          stiller (at) quip (dot) net
          Dev essays: http://www.quip.net/blog/
          "Luck is the residue of good design."