Skip to main content
July 23, 2014
Answered

Randomize Array and Present Multiple Items From Array Simultaneously

  • July 23, 2014
  • 2 replies
  • 275 views

Hi All,

I've figured out how to randomize an array and to present the items where the user can cycle through the items one-at-a-time. However, I would like to know how might I go about presenting items from a randomized array simultaneously. To be concrete, suppose that I have a list of three words i.e., word 1, word 2, and word 3. For each user, I'm looking to present all three words on the screen at the same time but in a different order. So one person might see this on the screen:

WORD 1

WORD 3

WORD 2

and another person might see

WORD 3

WORD 2

WORD 1

Any pointers or guides are much appreciated. Thanks for reading.

This topic has been closed for replies.
Correct answer Amy Blankenship

You say you already know how to randomize the Array, so I won't go into that. Let's assume that you already have 3 TextFields on screen and they're called tf1, tf2, tf3. You haven't said if you're using Classes or timeline code. I'm not a big fan of timeline code in AS3, so I'm not good at writing examples in it. The example here assumes Class code. It also assumes

  1. You have "declare stage instances automatically" off
  2. tf1, tf2, and tf3 exist in all frames of the timeline of the MC that is using this Class.

public class Words extends MovieClip {

    protected var wordSource:Array;

    public var tf1:TextField;

    public var tf2:TextField;

    public var tf3:TextFiels;

    //constructor

    public function Words() {

          super();

          //init your wordSource array here

          //a Vector is like an Array, but you're very sure what type of "thing" is at each index.

          //in this case, it's TextFields.

          var tfs:Vetor.<TextField> = Vector.<TextField>([tf1, tf2, tf3]);

          //loop through each word and each text field and match them up

          var loops = wordSource.length;

          for (var i=0; i<loops; i++) {

              var currentTf:TextField = tfs;

              var currentWord = wordSource;

              currentTf.text = currentWord;

          }

    }

}

2 replies

Amy Blankenship
Amy BlankenshipCorrect answer
Legend
July 24, 2014

You say you already know how to randomize the Array, so I won't go into that. Let's assume that you already have 3 TextFields on screen and they're called tf1, tf2, tf3. You haven't said if you're using Classes or timeline code. I'm not a big fan of timeline code in AS3, so I'm not good at writing examples in it. The example here assumes Class code. It also assumes

  1. You have "declare stage instances automatically" off
  2. tf1, tf2, and tf3 exist in all frames of the timeline of the MC that is using this Class.

public class Words extends MovieClip {

    protected var wordSource:Array;

    public var tf1:TextField;

    public var tf2:TextField;

    public var tf3:TextFiels;

    //constructor

    public function Words() {

          super();

          //init your wordSource array here

          //a Vector is like an Array, but you're very sure what type of "thing" is at each index.

          //in this case, it's TextFields.

          var tfs:Vetor.<TextField> = Vector.<TextField>([tf1, tf2, tf3]);

          //loop through each word and each text field and match them up

          var loops = wordSource.length;

          for (var i=0; i<loops; i++) {

              var currentTf:TextField = tfs;

              var currentWord = wordSource;

              currentTf.text = currentWord;

          }

    }

}

Ned Murphy
Legend
July 24, 2014

All you need to do is loop thru the randomized array when you present the words and show them all however you intend to arrange them.