AS3: declaring variables in a for loop

Out of context: Reply #11

  • Started
  • Last post
  • 23 Responses
  • tommyo0

    Don't get frustrated man, it takes a little time. The biggest problem is changing your thinking from AS2 to AS3. Labeling dynamic objects so that you can find them after you create them is now mainly handled by assigning myObject.name. Before, in AS2, once you declared a variable it was accessible via it's variable name, but because of the access limiting that no longer applies unless the variable is defined inside of your Class declaration. So you have different options now for grouping and accessing dynamic objects: 1. Push the objects to an array and access them via their array position (the ol' myArray[0]), 2. Add the objects to a display object using addChild and then you can look them up with myMainObject.getChildAt or myMainObject.getChildByName, OR, and this one I really like, create a hashmap or I think it's officially called Dictionary (a lot like an array) where you assign objects along with a string to a Dictionary and then you can look them up by their string.

    More on Dictionaries:
    http://www.gskinner.com/blog/arc…

    Keep your chin up.

View thread