A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: 2D arrays

  1. #1
    Junior Member
    Join Date
    Mar 2002
    Posts
    12
    I am trying to use a 2d array and have elements of the array go into 2 different places.
    For example
    Questions = new Array();
    Questions({word: "game", clue: "activity engaged in for diversion or amusement"});
    Questions({word: "chocolate", clue: "a food prepared from ground roasted cacao beans"});

    In this code I want what's in the "word" area to go into one text box, and "clue" to go into another. I have created 2 dynamic text boxes, but cant's figure out how to get the items to go into their individual boxes.
    Any ideas?
    Thanks

  2. #2
    Senior Member
    Join Date
    Jul 2000
    Posts
    266

    Try this:

    Hi,

    If you created your words and clues like this, you could easily reference them with the index:

    var Words = new Array();
    var Clues = new Array();

    Words[0] = "Game";
    Clues[0] = "activity engaged in for diversion or amusement";

    //set variables
    text1 = Words[0];
    text2 = Clues[0];

    //or if we were to use the MX method of text instance names:
    //text1.text = Words[0]
    //text2.text = Clues[0]
    //

    Hope this helps,

    Dan.

  3. #3
    Junior Member
    Join Date
    Mar 2002
    Posts
    12

    Re: Try this:

    Thanks, the problem with doing it that way is that I have to randomize the word in the array, but also have the words and clues match up (one is the term, the other is the definition).




    Originally posted by d_humphrey
    Hi,

    If you created your words and clues like this, you could easily reference them with the index:

    var Words = new Array();
    var Clues = new Array();

    Words[0] = "Game";
    Clues[0] = "activity engaged in for diversion or amusement";

    //set variables
    text1 = Words[0];
    text2 = Clues[0];

    //or if we were to use the MX method of text instance names:
    //text1.text = Words[0]
    //text2.text = Clues[0]
    //

    Hope this helps,

    Dan.

  4. #4
    Senior Member
    Join Date
    Jul 2000
    Posts
    266

    but wouldn't you randomize the index???

    Hi,

    wouldn't you do something like this:

    //lets say you have 10 words and clues

    var seed = Math.random()* 10;

    text1 = Words[seed];
    text2 = Clues[seed];

    Dan.

  5. #5
    Junior Member
    Join Date
    Mar 2002
    Posts
    12

    Re: Re: Try this:

    But how would I get the words and definitions in 2 separate text boxes?



    Originally posted by d_humphrey
    Hi,

    If you created your words and clues like this, you could easily reference them with the index:

    var Words = new Array();
    var Clues = new Array();

    Words[0] = "Game";
    Clues[0] = "activity engaged in for diversion or amusement";

    //set variables
    text1 = Words[0];
    text2 = Clues[0];

    //or if we were to use the MX method of text instance names:
    //text1.text = Words[0]
    //text2.text = Clues[0]
    //

    Hope this helps,

    Dan.
    [/B][/QUOTE]

  6. #6
    Senior Member
    Join Date
    Jul 2000
    Posts
    266

    uuuh???

    Hi,

    I don't know if I'm simplifying this too much, or I dont understand what you're trying to do.

    The code I just posted puts the word in text box 1 and the relative clue in text box 2:

    Code:
    text1 = Words[seed]; 
    text2 = Clues[seed];
    Isn't this what you wanted?

    Dan.

  7. #7
    Junior Member
    Join Date
    Mar 2002
    Posts
    12

    Re: Re: Re: Try this:

    Don't know what I'm doing wrong, but here is the code I'm using. I'm still not getting the words to come up in the text boxes
    words = new Array();
    words[0] = "game";
    words[1] = "chocolate";
    words[2] = "strawberry";
    words[3] = "taupe";
    words[4] = "detect";
    words[5] = "soda pop";
    words[6] = "square";
    words[7] = "dinner";
    words[8] = "breakfast";
    words[9] = "fuchsia";

    clues = new Array();
    clues[0] = "activity engaged in for diversion or amusement";
    clues[1] = "a food prepared from ground roasted cacao beans";
    clues[2] = "the juicy edible usually red fruit of of several low-growing temperate herbs (genus Fragaria) of the rose family that is technically an enlarged pulpy receptacle bearing numerous achenes";
    clues[3] = "a brownish gray";
    clues[4] = "to discover the true character of";
    clues[5] = "a sweet drink consisting of soda water, flavoring, and often ice cream";
    clues[6] = "any of the quadrilateral spaces marked out on a board for playing games";
    clues[7] = "a formal feast or banquet";
    clues[8] = "the first meal of the day especially when taken in the morning";
    clues[9] = "any of a genus (Fuchsia) of decorative shrubs of the evening-primrose family having showy noddiflowers usually in deep pinks, reds, and purples";
    //lets say you have 10 words and clues
    var seed = Math.random()* 10;
    text1 = words[seed];
    text2 = clues[seed];

  8. #8
    Senior Member
    Join Date
    Jul 2000
    Posts
    266

    sorry

    sorry,

    my mistake,

    use:

    var seed = random(10);


    Dan.

  9. #9
    Junior Member
    Join Date
    Mar 2002
    Posts
    12

    Re: Re: Re: Re: Try this:

    You rock!!! Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center