Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

objAtDepth.as

Name: objAtDepth [MX] returns a MovieClip, TextField or Button which exists in the specified depth
Author: senocular: www.senocular.com
Date: 1899-12-31T00:36:43.100
Documentation:
MovieClip OBJATDEPTH: given any depth, determines if an object
resides in that depth, and if so, returns its refrence.
Otherwise undefined is returned.

Arguments:
- depth: the depth to check for a screen object for

Returns:
- an object reference refering to the object at that depth. If nothing exists in that depth,
undefined is returned

Example:
this.createEmptyMovieClip("my_mc", 1);
this.createTextField("my_txt",2,0,0,100,100);

trace(this.objAtDepth(1)); // _level0.my_mc
trace(this.objAtDepth(2)); // _level0.my_txt
trace(this.objAtDepth(3)); // undefined

1
2
3
4
MovieClip.prototype.objAtDepth = function(depth){
	for (var o in this) if (this[o]._parent == this && this[o].getDepth() === depth) return this[o];
	return undefined;
}