suchislife801
11-04-2009, 11:41 PM
Hello experts,
I've been working on a small project and have been stuck on this for a few days. Let me show you some of the code:
1. I declare 3 Bindable Arrays.
private var arrTeam:Array;
[Bindable]
private var arrStats1:Array;
[Bindable]
private var arrStats2:Array;
[Bindable]
private var arrStatsFinal:Array;
2. I create the init() function that initializes these arrays populating some of them.
private function init():void
{
arrTeam = new Array();
arrTeam.push({col0:'vini', col1:'martins'});
arrTeam.push({col0:'trent', col1:'easton'});
arrTeam.push({col0:'jeniffer', col1:'valandingham'});
arrStats1 = new Array();
arrStats1.push({col0:'vini', col1:'martins', col2:100});
arrStats1.push({col0:'jeniffer', col1:'valandingham', col2:300});
arrStats2 = new Array();
arrStats2.push({col0:'trent', col1:'easton', col2:150});
arrStats2.push({col0:'jeniffer', col1:'valandingham', col2:250});
arrFinal = new Array();
// For each employee found in arrTeam...
arrTeam.forEach(traceEmployee);
}
3. This is the function that I think I should run for each time we iterate through arrTeam's indexes... Also where I need help because it is incomplete.
private function traceEmployee(element:*, index:Number, arr:Array):void
{
// Each time this function gets called..
for (var i:int=0; i < arrStats1.length; i++)
{
// If we find a match in arrStats1 then..
if (arrStats1[i].col0 == element.col0)
{
// Populate arrFinal with it.
arrFinal.push({col0:element.col0, col1:element.col1, col2:arrStats1[i].col2});
}
}
4. As you can see, the function above only checks arrTeam against arrStats1. I need to find a way to...
a. If name from arrTeam is found inside arrStats1 then check arrStats2.
b. If name from arrTeam is found inside arrStats2 then add both to arrFinal.
c. If name from arrTeam is NOT found inside arrStats1 then check arrStats2.
d. If name from arrTeam is NOT found inside arrStats2 then add only the first and last name.
e. If name from arrTeam is found inside arrStats1 then check arrStats2.
f. If name from arrTeam is NOT found inside arrStats2 then add first, last name and Stats1 to arrFinal.
g. If name from arrTeam is NOT found inside arrStats1 then check arrStats2.
h. If name from arrTeam is found inside arrStats2 then then add first, last name and Stats2 to arrFinal.
I've been working on a small project and have been stuck on this for a few days. Let me show you some of the code:
1. I declare 3 Bindable Arrays.
private var arrTeam:Array;
[Bindable]
private var arrStats1:Array;
[Bindable]
private var arrStats2:Array;
[Bindable]
private var arrStatsFinal:Array;
2. I create the init() function that initializes these arrays populating some of them.
private function init():void
{
arrTeam = new Array();
arrTeam.push({col0:'vini', col1:'martins'});
arrTeam.push({col0:'trent', col1:'easton'});
arrTeam.push({col0:'jeniffer', col1:'valandingham'});
arrStats1 = new Array();
arrStats1.push({col0:'vini', col1:'martins', col2:100});
arrStats1.push({col0:'jeniffer', col1:'valandingham', col2:300});
arrStats2 = new Array();
arrStats2.push({col0:'trent', col1:'easton', col2:150});
arrStats2.push({col0:'jeniffer', col1:'valandingham', col2:250});
arrFinal = new Array();
// For each employee found in arrTeam...
arrTeam.forEach(traceEmployee);
}
3. This is the function that I think I should run for each time we iterate through arrTeam's indexes... Also where I need help because it is incomplete.
private function traceEmployee(element:*, index:Number, arr:Array):void
{
// Each time this function gets called..
for (var i:int=0; i < arrStats1.length; i++)
{
// If we find a match in arrStats1 then..
if (arrStats1[i].col0 == element.col0)
{
// Populate arrFinal with it.
arrFinal.push({col0:element.col0, col1:element.col1, col2:arrStats1[i].col2});
}
}
4. As you can see, the function above only checks arrTeam against arrStats1. I need to find a way to...
a. If name from arrTeam is found inside arrStats1 then check arrStats2.
b. If name from arrTeam is found inside arrStats2 then add both to arrFinal.
c. If name from arrTeam is NOT found inside arrStats1 then check arrStats2.
d. If name from arrTeam is NOT found inside arrStats2 then add only the first and last name.
e. If name from arrTeam is found inside arrStats1 then check arrStats2.
f. If name from arrTeam is NOT found inside arrStats2 then add first, last name and Stats1 to arrFinal.
g. If name from arrTeam is NOT found inside arrStats1 then check arrStats2.
h. If name from arrTeam is found inside arrStats2 then then add first, last name and Stats2 to arrFinal.