Hi all,
I’m kinda stuck on this. I have a loop that counts how many xml nodes contain data.
One xml node looks like this:
[code]
7553130
INDE IDCL75BH
<C01_dim>70x90x70</C01_dim>
<C01_wght>30</C01_wght>
<C02_dim/>
<C02_wght/>
<C03_dim/>
<C03_wght/>
<C04_dim/>
<C04_wght/>
<C05_dim/>
<C05_wght/>
<C06_dim/>
<C06_wght/>
[/code]
Now I would like to use a loop:
(variable k is valid and this is not the problem)
for (var m:int = 1; m<7 ; m++){
if( xmlArtData.Artikel[k].['C0' + m + '_dim'] != "" ){
intNumberOfColli++;
}
}
The line:
Gives the following errors:
Scene 1, Layer ‘Layer 2’, Frame 1, Line 654 1084: Syntax error: expecting identifier before leftbracket.
Scene 1, Layer ‘Layer 2’, Frame 1, Line 654 1084: Syntax error: expecting rightparen before rightbracket.
Any tips would be appreciated.
Thanks !
There’s no dot between [k] and [‘C0’ + m + ‘_dim’] just like there’s no dot between Artikel and [k]:
xmlArtData.Artikel[k]['C0' + m + '_dim']
If you use E4x you could do something like
Article.children().(toString() !== '').length()
or
Article.children().(children().length()).length()
Thank you !
I’ll look into E4x too, looks interesting when handling XML
One more question though
function fncSearchLabelData(SearchArtNr) : Array {
var intNumberOfColli:int = 0;
var arrResult:Array;
for (var k:int = 0; k<xmlArtData.*.length(); k++){
if(xmlArtData.Artikel[k].ArtNr == SearchArtNr){
strDescription = xmlArtData.Artikel[k].Descr;
for (var m:int = 1; m<7 ; m++){
if( xmlArtData.Artikel[k]['C0' + m + '_dim'] != "" ){
intNumberOfColli++;
} //end if
} //end for
arrResult = [strDescription,intNumberOfColli]
return(arrResult);
break;
} //end if
} //end for
return(arrResult);
} //end fncSearchLabelData[/code]
If the code above reaches the 'break' statement, will this break the main loop :
[code]for (var k:int = 0; k<xmlArtData.*.length(); k++){
Thnx
The break won’t break the loop because it will never be encountered. The return above it would break out of the function before the break can even be read.
If the return weren’t there, yes, it would break the main loop since thats the loop its in. If it were in the inner loop it would break, and only break, the inner loop. If you want something in an inner loop to break an outer loop, you can use a label.
outer: for (var k:int = 0; k<xmlArtData.*.length(); k++){
// ...
for (var m:int = 1; m<7 ; m++){
// ...
break outer; // breaks all loops up to, and including, the one labeled outer
}
}
Thanks for explaining and the tip about the label