PDA

View Full Version : array troubles...



RabBell
March 1st, 2006, 08:05 AM
ok first here is the code


import mx.controls.MediaPlayback;
var my_video:MediaPlayback;
var actarray = new Array();

GenerateMenu = function(container, name, x, y, depth, node_xml) {
// variable declarations
var curr_node;
var curr_item;
moviecombo.addItem("--- Select Interview ---");

for (var i=0; i<node_xml.childNodes.length; i++) {
// item submenu behavior for rollover event

if (node_xml.childNodes[i].nodeName == "interview"){
curr_node = node_xml.childNodes[i];
actarray[i] = curr_node.attributes.movloc;
//moviecombo.addItem(curr_node.attributes.name);
moviecombo.addItem(i+" : "+actarray[i]);

} // if
} // for
} // function

function changelist(eventObj){
var number = moviecombo.selectedIndex-1;
trace("NUM:"+number);

trace("ARR:"+actarray(number));
}

moviecombo.addEventListener("change",changelist);


I've edited out the XML from here cause it's not relevant to my problem, that much I do know.

The problem is when I change an item in my combobox (moviecombo) the trace message says the value is undefined

actually what I get in my output box is

NUM:1
ARR:undefined

but the arrays contents are showing correctly in the combobox so....I'm confused

Any helps greatly appreciated :cool:

ThePuzzleMaster
March 1st, 2006, 08:14 AM
try


trace("ARR:"+actarray[number]);

tristessa
March 1st, 2006, 08:15 AM
ok first here is the code


import mx.controls.MediaPlayback;
var my_video:MediaPlayback;
var actarray = new Array();

GenerateMenu = function(container, name, x, y, depth, node_xml) {
// variable declarations
var curr_node;
var curr_item;
moviecombo.addItem("--- Select Interview ---");

for (var i=0; i<node_xml.childNodes.length; i++) {
// item submenu behavior for rollover event

if (node_xml.childNodes[i].nodeName == "interview"){
curr_node = node_xml.childNodes[i];
actarray[i] = curr_node.attributes.movloc;
//moviecombo.addItem(curr_node.attributes.name);
moviecombo.addItem(i+" : "+actarray[i]);

} // if
} // for
} // function

function changelist(eventObj){
var number = moviecombo.selectedIndex-1;
trace("NUM:"+number);

trace("ARR:"+actarray(number));
}

moviecombo.addEventListener("change",changelist);

I've edited out the XML from here cause it's not relevant to my problem, that much I do know.

The problem is when I change an item in my combobox (moviecombo) the trace message says the value is undefined

actually what I get in my output box is

NUM:1
ARR:undefined

but the arrays contents are showing correctly in the combobox so....I'm confused

Any helps greatly appreciated :cool:

i can't test it and its a wild shot but

maybe change the trace line to

trace ("ARR: " + actarray[i](number))

but again i wouldn't know if it's even a valid code

RabBell
March 1st, 2006, 08:18 AM
try


trace("ARR:"+actarray[number]);


aaaaarrrrrggggghhhhhhh, I've been staring at this code for ages I can't believe I made such a stupid mistake

thanks puzzle, I'm gonna go stand in the corner now :(

ThePuzzleMaster
March 1st, 2006, 03:16 PM
No problem... It happens to us all!:D

I definitely know that feeling!