This content has been marked as final. Show 8 replies
You can use this.setDepthTo(DepthManager.kTop); instead of this.getNextHighestDepth(); and you will achieve the same result.
I'm afraid your solution does not work although it seems to have been the official line for some time! The attached code demonstrates the problem and a workaround.
While not in the conspiracy of silence category this does seem to have been a long term blind spot. The Flash 8 LiveDocs for createEmptyMovieClip() has an entry in September 2006 highlighting the problem but it was not acknowledged.
The difficulty is quite obvious: createEmptyMovieClip() and other methods like it require a number to be supplied for the depth. The method getNextHighestDepth() returns a number, albeit a flaky one in the presence of version 2 components. DepthManager does not return a number. Instead it does exactly what it says in the documentation; mc.setDepthTo(DepthManager.kTop) sets the depth of mc to 20 places above the currently highest occupied depth. DepthManager is a method of the target mc whereas getNextHighestDepth() is a method of mc's parent. You can't invoke a method of movieclip that hasn't been created yet.
So there is no way that DepthManager can be used as a simple replacement for getNextHighestDepth() and it seems quite cynical that the documentation is sprinkled with recommendations to do just that without any explanation or example of how it can be done. The DepthManager documentation is particularly short on code examples compared with other areas.
I see your point and in running your code I see the problem that you describe. I just looked at a program that uses this method, both for components and for movieClips. It works and it works correctly. I just tested the depth that was returned by a movieClip and the result was correct. It may be that you need to have at least one component whose depth is set using the depth manager before you set the depth of a movieClip.
I don't think it's as simple as that....
I don't know what to do with the code that you sent. I don't see any reference to a component there. Here's an abbreviation of the code that I used to instantiate one of the component types:
Sorry, I used onStageBtn to refer to a button component I'd placed on stage.
If your code works for you I don't understand how, unless your code resides on a child timeline - see below. Within the function below, "this" traces _level0 so I wouldn't expect a sensible result. That aside, even if it did work, this example misses the point. In situations where a new object is being created and a depth has to be supplied, the method MC.getNextHighestDepth() returns a number representing the next free depth in MC which is the parent of the object being created. This method cannot be simply replaced by any method of the DepthManager class as they do not return a number. The method setDepthTo() only operates on an existing instance and therefore cannot be used to specify the depth in methods such as createEmptyMovieClip().
I think I'm seeing the difference between what I did and what you're doing. I'm not trying to set a depth for an empty movieClip. I'm loading an .swf into that clip and then, when I position the clip, I give it a new depth. Have a look at this example building on your example. Substitute your own .swf to load in.
Thank's, I think that's clear now. Getting back to my original question: what should replace this.getNextHighestDepth() in createEmptyMovieClip? The answer appears to be "1", or whatever you choose, but followed by a DepthManager call. Eg