dynamically created layers not usuable for layer commands

Discussion created by ngalford on Jun 11, 2013
Latest reply on Jun 13, 2013 by ngalford
I'm building layers dynamically and this is working great but I don't seem to be leveraging the api properly.  The layers are being built at runtime properly but I can't attach to them after the page is loaded, which leads me to believe that their creation is not seen by the API, but I'm unsure of how to solve this.  My first thought is to use the **new** keyword to instantiate the object but I can't get that working.

The code below is what is actually generating new objects from the GIS api, 'makeid()' is a function that creates a unique string from uppercase/lowercase letters and numbers.  I call this function for every new layer I want to add, the variable creation is where I think I'm off but I'm not sure.....

    var setTiledLayer = function(URL) {
        var tuID = makeid();
        tuID = new esri.layers.ArcGISTiledMapServiceLayer(URL, {id: tuID + 'ID'});
        return tuID;