mixin-get-child-by-name.mjs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*!
  2. * @pixi/mixin-get-child-by-name - v6.5.10
  3. * Compiled Thu, 06 Jul 2023 15:25:11 UTC
  4. *
  5. * @pixi/mixin-get-child-by-name is licensed under the MIT License.
  6. * http://www.opensource.org/licenses/mit-license
  7. */
  8. import { DisplayObject, Container } from '@pixi/display';
  9. /**
  10. * The instance name of the object.
  11. * @memberof PIXI.DisplayObject#
  12. * @member {string} name
  13. */
  14. DisplayObject.prototype.name = null;
  15. /**
  16. * Returns the display object in the container.
  17. *
  18. * Recursive searches are done in a preorder traversal.
  19. * @method getChildByName
  20. * @memberof PIXI.Container#
  21. * @param {string} name - Instance name.
  22. * @param {boolean}[deep=false] - Whether to search recursively
  23. * @returns {PIXI.DisplayObject} The child with the specified name.
  24. */
  25. Container.prototype.getChildByName = function getChildByName(name, deep) {
  26. for (var i = 0, j = this.children.length; i < j; i++) {
  27. if (this.children[i].name === name) {
  28. return this.children[i];
  29. }
  30. }
  31. if (deep) {
  32. for (var i = 0, j = this.children.length; i < j; i++) {
  33. var child = this.children[i];
  34. if (!child.getChildByName) {
  35. continue;
  36. }
  37. var target = child.getChildByName(name, true);
  38. if (target) {
  39. return target;
  40. }
  41. }
  42. }
  43. return null;
  44. };
  45. //# sourceMappingURL=mixin-get-child-by-name.mjs.map