Thanks Paul!
Works like a charm! I didn't know about the try/ catch construct. Looks
pretty awesome to me.
I also have an update on the Layer Order Problem. My first solution doesn't take
the order of the selection into account. So if more than one layer is selected the
new layer was placed above the first one selected. I hate that kind of awkwardness
in software so i came up with a pretty nasty solution for that problem.
Code:
// Position of the new Layer
// Check if at least one Layer is Selected
// if so move the new Layer on top of the selected one(s)
if ( slctd_layer[0] != null){
// Search for the Layer with the lowest index
i = 0; // Set Counter
lowest_index = slctd_layer[i].index; // Initilize the placeholder for the index of the lowest layer to the first layer in the array
top_layer = slctd_layer[i]; // Set the Output to the layer of the placeholder
// Go through the array of the selected layers
while (i < slctd_layer.length){
// If the placeholder is bigger than the current layer set the placeholder to the value of the current layer
if (lowest_index > slctd_layer[i].index){
lowest_index = slctd_layer[i].index;
top_layer = slctd_layer[i];
}
i++;
}
// Move the new Layer on top of the layer with the lowest index
new_solid.moveBefore(top_layer);
}
Again, thanks for yout help Paul!