I am trying to make a calculator where a user can select from a list of items. If a user clicks say "ITEM1", it should add the item to a "CONTAINER_MC". The problem i have is all my data is set inside an array containing names and prices like the code below.
var menuNames:Array = [
"Item1",
"Item2",
"Item3",
"Item4",
"item5",
"item6"
];
//price array
var menuPrices:Array = [
"0.99",
"1.99",
"2.99",
"5.99",
"6.99",
"10.99"
];
Now i have a sprite which creates a menu for each of these items by the use of a movie clip containing 2 input fields which i setup like the code below.
var menuSprite:Sprite = new Sprite();
var totalItems:Number = menuNames.length;
var item:menuItem; //new item field
var btn:add_btn;
for(var i = 0; i < totalItems; i++) {
item = new menuItem();
btn = new add_btn();
menuSprite.addChild(item);
item.addChild(btn);
item.x = 0;
item.y = i * 80;
btn.y = 45;
item.itemName.text = menuNames[i];
item.itemPrice.text = "$" + menuPrices[i];
}
addChild(menuSprite);
This all works fine so far, the problem is that i have a button inside my item and i need to add even listeners for these buttons, the problem is how to target these buttons. Since these buttons are added through the for loop they are not given instance names so notice how i targetted the input fields stored within the "item", i used itemName but how would i do it to the buttons stored inside item.
Thank you, really appreciate any help possible.