How To Run a Function After the Map Has Finished Loading
A web map will not fully appear and function in your web page until after all of its components have been downloaded. Depending on the size of your map this can take some time. You may want to have processing that occurs only after the map is ready. You can pass a function in the loadedCB parameter of the embedViewer API that will be called after the map has finished downloading and initializing.
You can see a live example here.