thatrenowned
MIS
I'm creating an app which reads hundreds of values out of an XML file, stores them in seperate arrays depending on the tags, populates a list with the relevant values depending on what button is clicked and finally displays all the attributes of the value which is clicked in seperate text boxes.
Certain values in each array link to other values in another array, so for example, the SYSTEM array has the ID of the person who is responsible for that system. Clicking a button displays the details of that person (and it then goes further to give a button to display everyone in their department etc etc).
Now to the problem, and to keep things simple I'll just stick to one array (peopleDetails) because if there is a solution for this I can implement it on the rest!
There are several text fields displayed when you click one of the people in the list and a few of these text fields have buttons which link elsewhere. The function which runs on the majority of these buttons is identical except for part of the path. Heres an example of the one which displays all of the people in the same department as the person clicked in the list:
and heres one which displays all of the people in the same location of that person:
as you can see, they're almost identicle.
cwipList - the list component (obvious really!)
currDep - that var which holds whatever value is in the text box which is later compared to the value in the array
currLoc - that var which holds whatever value is in the text box which is later compared to the value in the array
n - just a counter...its used in a label to show haw many values are in the list
personDetails - the array which stores all the people and their attributes (name, id etc)
What I'm hoping to do is have a variable, in this case I'll call it personInfo, which is set depending on what button is clicked. So if the user clicks on the department button, that variable holds "department", if they click on location it stores "location" etc.
Then when the function runs, instead of where it says
I can hopefully replace txtPersonDepartment with whatever is stored in personInfo.
Any time that I've tried doing this e.g.
_root.peopleTexts.personInfo.text
or
_root.peopleTexts.("txtPerson" + personInfo).texts //where personInfo would be "department" or "contact" etc
I just get an error about it being undefined. Is there any way to use a variable in the path or some sort of work around because I've tried loads of different ways (most of which I can't remember!) and none work.
If any of this is unclear (which I'm sure it is!) ask me whatever you need to know and I'll answer. Bear in mind that the app works as it should - this is just a question to try to make the app more efficient instead of repeating unneccessary code.
Any help is appreciated.
Thanks
Certain values in each array link to other values in another array, so for example, the SYSTEM array has the ID of the person who is responsible for that system. Clicking a button displays the details of that person (and it then goes further to give a button to display everyone in their department etc etc).
Now to the problem, and to keep things simple I'll just stick to one array (peopleDetails) because if there is a solution for this I can implement it on the rest!
There are several text fields displayed when you click one of the people in the list and a few of these text fields have buttons which link elsewhere. The function which runs on the majority of these buttons is identical except for part of the path. Heres an example of the one which displays all of the people in the same department as the person clicked in the list:
Code:
function displayPeopleDepartment(){
cwipList.removeAll();
currDep = _root.peopleTexts.txtPersonDepartment.text;
n=0;
for (i=0; i<personDetails.length; i++){
if (personDetails[i].personDepartment == currDep){
cwipList.addItem(personDetails[i].personName,i);
n++;
};
};
cwipList.sortItemsBy("label", "ASC");
txtCurrentList.text = currDep + " (" + n + ")";
};
and heres one which displays all of the people in the same location of that person:
Code:
function displayPeopleLocation(){
cwipList.removeAll();
currLoc = _root.peopleTexts.txtPersonLocation.text;
n=0;
for (i=0; i<personDetails.length; i++){
if (personDetails[i].personLocation == currLoc){
cwipList.addItem(personDetails[i].personName,i);
n++;
};
};
cwipList.sortItemsBy("label", "ASC");
txtCurrentList.text = currLoc + " (" + n + ")";
};
as you can see, they're almost identicle.
cwipList - the list component (obvious really!)
currDep - that var which holds whatever value is in the text box which is later compared to the value in the array
currLoc - that var which holds whatever value is in the text box which is later compared to the value in the array
n - just a counter...its used in a label to show haw many values are in the list
personDetails - the array which stores all the people and their attributes (name, id etc)
What I'm hoping to do is have a variable, in this case I'll call it personInfo, which is set depending on what button is clicked. So if the user clicks on the department button, that variable holds "department", if they click on location it stores "location" etc.
Then when the function runs, instead of where it says
Code:
_root.peopleTexts.txtPersonDepartment.text;
Any time that I've tried doing this e.g.
_root.peopleTexts.personInfo.text
or
_root.peopleTexts.("txtPerson" + personInfo).texts //where personInfo would be "department" or "contact" etc
I just get an error about it being undefined. Is there any way to use a variable in the path or some sort of work around because I've tried loads of different ways (most of which I can't remember!) and none work.
If any of this is unclear (which I'm sure it is!) ask me whatever you need to know and I'll answer. Bear in mind that the app works as it should - this is just a question to try to make the app more efficient instead of repeating unneccessary code.
Any help is appreciated.
Thanks