PDA

View Full Version : Array in an Array


robodiaz
03-26-2008, 11:18 PM
:eek:

So the problem I'm having is randomly choosing an element within a loaded xml file.
I can't seem to randomly select "audioXX" with the associate "TextX"

The red highlights are things I was trying out in my code but I couldnt figure it out. Any help or pointers would be super. Thanks in advance.

my XML file looks something like ...

<L1>
<L2>
<L3>
<A1>Text1</A1>
<A2>Def1</A2>
<A3>
<B1>audio1a</B1>
<B1>audio1b</B1>
<B1>audio1c</B1>
<B1>audio1d</B1>
<B1>audio1e</B1>
<B1>audio1f</B1>
</A3>
</L3>
<L3>
<A1>Text2</A1>
<A2>Def2</A2>
<A3>
<B1>audio2a</B1>
<B1>audio2b</B1>
<B1>audio2c</B1>
<B1>audio2d</B1>
<B1>audio2e</B1>
</A3>
</L3>
</L2>
</L1>

My button chooses a random A1, but then I need it to choose randomly an associated audio element.

my actionscript looks like


var b_txt:Array = new Array;
var b_def:Array = new Array;
var b_aud_length:Array = new Array;
var b_aud:Array = new Array;
var b_aud_array:Array = new Array;

function loadXML(loaded) {
if (loaded) {
var var_b_text = this.firstChild.firstChild.childNodes;
for (i=0; i<var_b_text.length; i++) {
b_txt[i] = this.firstChild.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue;
b_def[i] = this.firstChild.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue;
j = this.firstChild.firstChild.childNodes[i].childNodes[2].childNodes.length;

for (k=0; k<j; k++) {
b_aud[k] = this.firstChild.firstChild.childNodes[i].childNodes[2].childNodes[k].firstChild.nodeValue;
b_aud_array[i].push(b_aud[k]);
};
};
};
};
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("myXML.xml");


I dont think the problem is in the actionscript of my button but it looks like below

b_btn.onRelease = function(){
// random number
lastRandomNumber = randomNumber;
randomNumber = Math.floor(Math.random()*i);
while (lastRandomNumber == randomNumber) {
randomNumber = Math.floor(Math.random()*i);
}

_root.txt_mc.txt_box.htmlText = b_txt[randomNumber];
_root.def_mc.def_box.htmlText = b_def[randomNumber];

// random audio
lastRandomNumber2 = randomNumber2;
randomNumber2 = Math.floor(Math.random()*k);
while (lastRandomNumber2 == randomNumber2) {
randomNumber2 = Math.floor(Math.random()*k);
}

var bSound:Sound = new Sound();
bSound.onLoad = function(sucess){
if (sucess)
bSound.start(0, 1);
displayLoadError();
};
// bSound.loadSound(b_aud_array[randomNumber,randomNumber2]);
bSound.loadSound(b_aud_array[0]);

...

bSound.onSoundComplete = function(){
b_mc.gotoAndStop(1);
}
};

So my question is what is the best way to randomly access those associated audio files?

robodiaz
03-27-2008, 12:16 AM
Should I have posted this in the Actionscript 2.0 Portion of the Forum?

robodiaz
03-27-2008, 05:07 PM
I've moved this to the Actionscript 2.0 Portion