"that would be limited to you hard coding the number of levels to go down
to"
- he already had this level var created with whatever number he had
intended, I was just giving an example value...
" If the XML gets larger and deeper, that function would fail... "
- why would it fail? (assuming that the level var could be whatever you
want?
"it would be a better idea to check the length of the array instead"
- John didn't indicate that this was a problem of verifying the data, but
instead wishing to write the same code in fewer lines. That is what I did. I
do agree with you though, that error checking would be good to have.
I've changed my code to test creating the string required. This is a TEST to
prove that my code would indeed create the referencing desired.
var level:int = 5;
var str:String = "xml.menu"
for (var i:int = 1; i < level; i++) {
str += ".item[whichItem" + ((i == 1) ? "" : i) + "]";
}
str += ".item.length()";
change level to whatever you want and it will produce the same lines of code
John reference above. Clearly this doesn't work, but since such little
information was given (especially about the 'whichItemX' variables, this was
my shot at it.
This here is an updated version of it that breaks out a piece to make it a
bit cleaner to read:
var level:int = "n";
var xmlItem:* = xml.menu;
for (var i:int = 1; i < level; i++) {
var which:* = this["whichItem" + ((i == 1) ? "" : i)]
xmlItem = xmlItem.item[which];
}
totalItems = xmlItem.item.length();
John, I think if we are going to be able to help you further we would need
more information about how this xml is truly setup, and wher some of these
values come from (whichItem, whichItem2..., level)
On Thu, Aug 11, 2011 at 12:58 PM, Henrik Andersson <[email protected]>wrote:
> While you have the right spirit I think that it would be a better idea to
> check the length of the array instead. That way you won't accidentally step
> out of bounds there.
>
> ______________________________**_________________
> Flashcoders mailing list
> [email protected].**com <[email protected]>
> http://chattyfig.figleaf.com/**mailman/listinfo/flashcoders<http://chattyfig.figleaf.com/mailman/listinfo/flashcoders>
>
--
Ktu;
The information contained in this message may or may not be privileged
and/or confidential. If you are NOT the intended recipient, congratulations,
you got mail!
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders