rholdrae
07-06-2009, 09:24 AM
Hello guys!
I just want to ask how to get the same values in Array 1 and push it all in Array 2. This is the situation, every time I add an object on the stage I'm adding its name and X and Y coordinates in an array.
//I'm actually pulling data in xml. Let's just assume these are the data in my xml.
arrayName = new Array("Dessert Fork","Table Fork","Table Knife","Table Spoon","Dessert Fork", "Soup Spoon","Table Fork");
arrayXcoor = new Array("10","20","30","40","50", "60",70);
arrayYcoor = new Array("100","200","300","400","500", "600,700");
var arr1:Array = new Array();
var arr2:Array = new Array();
var count:Number = 0;
btn.onPress = function(){
arr1.push({name:arrayName[count], thisX:arrayXcoor[count], thisY:arrayYcoor[count]});
count++;
lookforsameobj()
}
function lookforsameobj(){
// now this is where I get lost. what should happen is that every time you add an object it should check if there's a same value in terms of name in arr1. if it found same object it should push in arr2
arr2.push({name:arr1[x].name, thisX:arr1[x].thisX, thisY:arr1[x].thisY})
}
// it should output
// arr2[0].name = Dessert Fork
// arr2[1].name = Dessert Fork
// arr2[2].name = Table Fork
// arr2[3].name = Table Fork
// arr2[0].thisX= 10
// arr2[1].thisX= 40
// arr2[2].thisX= 20
// arr2[3].thisX= 70
// arr2[0].thisY= 100
// arr2[1].thisY= 400
// arr2[2].thisY= 200
// arr2[3].thisY= 700
is this possible? How is it done? Appreciate all the help I can get. Thanks in advance.
I just want to ask how to get the same values in Array 1 and push it all in Array 2. This is the situation, every time I add an object on the stage I'm adding its name and X and Y coordinates in an array.
//I'm actually pulling data in xml. Let's just assume these are the data in my xml.
arrayName = new Array("Dessert Fork","Table Fork","Table Knife","Table Spoon","Dessert Fork", "Soup Spoon","Table Fork");
arrayXcoor = new Array("10","20","30","40","50", "60",70);
arrayYcoor = new Array("100","200","300","400","500", "600,700");
var arr1:Array = new Array();
var arr2:Array = new Array();
var count:Number = 0;
btn.onPress = function(){
arr1.push({name:arrayName[count], thisX:arrayXcoor[count], thisY:arrayYcoor[count]});
count++;
lookforsameobj()
}
function lookforsameobj(){
// now this is where I get lost. what should happen is that every time you add an object it should check if there's a same value in terms of name in arr1. if it found same object it should push in arr2
arr2.push({name:arr1[x].name, thisX:arr1[x].thisX, thisY:arr1[x].thisY})
}
// it should output
// arr2[0].name = Dessert Fork
// arr2[1].name = Dessert Fork
// arr2[2].name = Table Fork
// arr2[3].name = Table Fork
// arr2[0].thisX= 10
// arr2[1].thisX= 40
// arr2[2].thisX= 20
// arr2[3].thisX= 70
// arr2[0].thisY= 100
// arr2[1].thisY= 400
// arr2[2].thisY= 200
// arr2[3].thisY= 700
is this possible? How is it done? Appreciate all the help I can get. Thanks in advance.