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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. 'use strict';
  9. var display = require('@pixi/display');
  10. /**
  11. * The instance name of the object.
  12. * @memberof PIXI.DisplayObject#
  13. * @member {string} name
  14. */
  15. display.DisplayObject.prototype.name = null;
  16. /**
  17. * Returns the display object in the container.
  18. *
  19. * Recursive searches are done in a preorder traversal.
  20. * @method getChildByName
  21. * @memberof PIXI.Container#
  22. * @param {string} name - Instance name.
  23. * @param {boolean}[deep=false] - Whether to search recursively
  24. * @returns {PIXI.DisplayObject} The child with the specified name.
  25. */
  26. display.Container.prototype.getChildByName = function getChildByName(name, deep) {
  27. for (var i = 0, j = this.children.length; i < j; i++) {
  28. if (this.children[i].name === name) {
  29. return this.children[i];
  30. }
  31. }
  32. if (deep) {
  33. for (var i = 0, j = this.children.length; i < j; i++) {
  34. var child = this.children[i];
  35. if (!child.getChildByName) {
  36. continue;
  37. }
  38. var target = child.getChildByName(name, true);
  39. if (target) {
  40. return target;
  41. }
  42. }
  43. }
  44. return null;
  45. };
  46. //# sourceMappingURL=mixin-get-child-by-name.js.map