Good morning!
I am elementary school teacher and I made a little app that allows a teacher to click a button and randomly select one student’s name from a XML imported array. The selected name is then removed from the list and when the teacher clicks the button again it gives them a new name and so on all the way through the class list. When the teacher reaches the end of the names, the list is rescrambled and the app starts over. The app. only imports one class list.
The teachers love it and it works great, but they would like an upgrade–they would like to be able to click a combobox and be able to select from a list of class lists to load different sets of student names. And this is where I am stuck. I have been trying to use the XMLconnector component and have been able to populate the combobox with the names of the classes, however I am not sure how to proceed from there.
So…here is my questions: should I continue in this direction using the XMLconnector? If not, what would you suggest? How does the XMLconnector access the XML array that was loaded and what would it be called? Is it better to try and write it by hand–you will see in my AS that I was playing with the idea of writing it by hand.
Here is my simple XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<teaching>
<myClass name="Kindergarten">
<student>Davey Pliska</student>
<student>Sarah L.</student>
<student>Madeline Pliska</student>
</myClass>
<myClass name="First">
<student>Su</student>
<student>Homer</student>
<student>Huey</student>
<student>Kim</student>
<student>SpongeBob</student>
<student>J.D.</student>
</myClass>
</teaching>
Here is my AS:
stop();
//
// Trigger Data Source Behavior
// Macromedia 2003
this.myConnection.trigger();
///////////////////
myName.text = "?";
myStudentList = new Array();
myClassList = new Array();
//////////
/*------- I was commenting this out because it is not needed by the connector and I was fishing.
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
myStudents = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
myStudents* = xmlNode.childNodes*.firstChild.nodeValue;
}
myClasses = new []();
myClasstotal = xmlNode.childNodes.length;
for (z=0; z<myClasstotal; z++) {
myClasses = xmlNode.childNodes[z].nodeValue;
}
trace(myClasses);
myStudentList = myStudents.concat();
// Shuffle word array
shuffles = Math.floor(Math.random()*(99));
myStudents.shuffle(shuffles);
myName.text = "Ready";
} else {
content = "file not loaded!";
}
}
--------------------------------------*/
///////// Array shuffle function
Array.prototype.shuffle = function(times) {
var max = this.length;
var a, b, temp;
while (times--) {
a = Math.floor(Math.random()*max);
b = Math.floor(Math.random()*max);
temp = this[a];
this[a] = this**;
this** = temp;
}
};
///////buttons///////////////////
pickMe_btn.onRelease = function() {
theName = myStudents[0];
myName.text = theName;
trace(theName);
myStudents.shift();
if (myStudents[0] == undefined) {
myName.text = "Done";
}
};
reset_btn.onRelease = function() {
myStudents = myStudentList.concat();
shuffles1 = Math.floor(Math.random()*(99));
myStudents.shuffle(shuffles1);
myName.text = "Ready";
};
/*//////XML////////////---commented out not needed by the connector
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("myStudents.xml");
//////////////////////////////////*/
And [COLOR=“Red”]attached is my fla[/COLOR]–sorry too large! and xml and a zip to the first version.
Any ideas or help would be greatly appreciated!
Thanks,
Madzander