Solved! Go to Solution.
dojo.connect(map, 'onLayerAdd', function(){ alert(basemap.layerInfos[0].name); }); map.addLayer(basemap);
dojo.connect(map, 'onLayerAdd', function(){ alert(basemap.layerInfos[0].name); }); map.addLayer(basemap);
You'll want to listen to the 'onLayerAdd' event when adding individual layers.
http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jsapi/map.htm#onLayerAdd
So something likedojo.connect(map, 'onLayerAdd', function(){ alert(basemap.layerInfos[0].name); }); map.addLayer(basemap);
Right now you're trying to access the layerInfos immediately after adding it to the map, but you have to wait for it to finish loading before you can interact with it.
You might even be able to listen to the individual layers onLoad, but I haven't tried that way.
http://help.arcgis.com/EN/webapi/javascript/arcgis/help/jsapi/layer.htm#onLoad