more actionscript help

Out of context: Reply #7

  • Started
  • Last post
  • 10 Responses
  • monNom0

    missed you with that last one, sorry.

    if you want to loop through an array and create a unique button for each one then a 'for loop' is in order.

    this is how I would do it
    -----------------------------
    myArray = [peas, carrots, tomatoes, ham];

    for (i=0; i "i=0"
    then the condition for the loop
    (while) "i < my Array.Length"
    then what to do with "i" when that condition is true. "i++" --> increases" i" by one

    then I've assumed that you have a movie clip called button stored in the library. within that movieclip I'm assumed a textbox called "nameTag"

    within the 'for loop' you can take advantage of the incremental variable "i" to make uniquely named new objects.

    so "attachMovie("button";"button" +i, i)

    is attaching a new instance of the movieclip "button". it then calls it: "button" + i
    it then sets the new movieclip's level to be equal to "i"

    you can then access the attached movie by using square brackets to evaluate the expression

    this["button" + i"].nameTag =

    and set the nametag variable to equal the value of the Array at index "i"

    myArray[i]

    hope that's a bit clearer...

    am I on the right track?

View thread