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

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