- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
import { DisplayObject, Container } from '@pixi/display';
/**
* The instance name of the object.
* @memberof PIXI.DisplayObject#
* @member {string} name
*/
DisplayObject.prototype.name = null;
/**
* Returns the display object in the container.
*
* Recursive searches are done in a preorder traversal.
* @method getChildByName
* @memberof PIXI.Container#
* @param {string} name - Instance name.
* @param {boolean}[deep=false] - Whether to search recursively
* @returns {PIXI.DisplayObject} The child with the specified name.
*/
Container.prototype.getChildByName = function getChildByName<T extends DisplayObject = DisplayObject>(
name: string,
deep?: boolean,
): T
{
for (let i = 0, j = this.children.length; i < j; i++)
{
if (this.children[i].name === name)
{
return this.children[i];
}
}
if (deep)
{
for (let i = 0, j = this.children.length; i < j; i++)
{
const child = (this.children[i] as Container);
if (!child.getChildByName)
{
continue;
}
const target = child.getChildByName<T>(name, true);
if (target)
{
return target;
}
}
}
return null;
};