Thanks Robert, this is exactly what I was looking for! This code makes a lot of sense.
Small problem, though: layer.sublayers comes back empty. This is what I have
var BREADCADLayer = landLayer.sublayers.getItemAt(40);
with landLayer being a MapImageLayer that i know has sublayers. After removing the getItemAt() function and putting landLayer.sublayers.join() in a console.log, I confirmed that the collection is empty. Am i missing something here?
edit: I don't specify the sublayers property of landLayer in its constructor, as I want every sublayer in the MapService to be included. The only thing specified in the landLayer constructor is url.