Dynamically calling array value by index number

I'm having trouble calling the values of an array using their index number dynamically. What I'm trying to do is get the name of a movieclip dynamically each time the for loop calls. My code:

public var allItemsUnlockedTC:Array = new Array("Itemwrench", "Itemsc", "Itemvoltmeter", "Itemgloves", "Itemstirespray");

for(var TCitems:int = 0; TCitems < allItemsUnlockedTC.length; TCitems++)
            {
                trace("TCitems length: " + TCitems);
                trace("Values: " + allItemsUnlockedTC.valueOf([TCitems]));
                /*getChildByName(allItemsUnlockedTC.valueOf(TCitems) as MovieClip).x = par.toolCloset.kast_1.slotTC1;//getChildByName("slotTC" + (TCitems + 1)).x + 400;
                getChildByName(allItemsUnlockedTC.valueOf(TCitems) as MovieClip).y = par.toolCloset.kast_1.slotTC1;//getChildByName("slotTC" + (TCitems + 1)).y + 245;
                getChildByName(allItemsUnlockedTC.valueOf(TCitems) as MovieClip).gotoAndStop(2);
                //getChildByName(allItemsUnlockedTC.valueOf(TCitems)).name = ("slotTC" + (TCitems + 1));
                NotinventoryParentTC.addChild(getChildByName(allItemsUnlockedTC.valueOf(TCitems) as MovieClip));*/
            }

Instead of getting the values one by one in ascending order, I get all values at once every time the for loop calls.

How do I call the value by the index using the for loop ?

Thanks in advance,

Milan

Nevermind, I solved it.

trace("Values: " + allItemsUnlockedTC[TCitems]);

Stupid question xS

Answers


You want to get the item at the specific index. In actionscript this is done like this: yourArray[index]. Don't use valueOf.

so it would look like:

trace("Values: " + allItemsUnlockedTC[TCitems]);

Just use a for each...in loop.

 for each(var TCitems:String in allItemsUnlockedTC)
 {
            trace("TCitems length: " + allItemsUnlocked.indexOf(TCitems));
            trace("Values: " + TCitems);
 }

Note that this was just off the top of my head and the code may not be entirely correct.


Need Your Help

RespondToSelector syntax while converting from Objective-C to swift

ios objective-c swift

Well am unable to figure out how to convert the below line to swift

Java - How to give each tile generated from an array a unique “ID”

java arrays random tile

I am trying to do mouse picking and the tile I click on changes to whatever the opposite tile is ie. grass to dirt, but every grass tile has the same "ID" so every grass tile on the screen changes to

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.