简体   繁体   English

AS3 + Starling-查找未知的Sprite

[英]AS3 + Starling - Find Unknown Sprite

I have legacy code project. 我有遗留代码项目。 While Starling is running sometimes some Sprite appears and covers all application. 当Starling运行时,有时会显示一些Sprite,并覆盖所有应用程序。

In pure flash I used "console" https://code.google.com/p/flash-console/wiki/GettingStarted to get object hierarhy in display tree. 在纯Flash中,我使用“控制台” https://code.google.com/p/flash-console/wiki/GettingStarted在显示树中获取对象层次结构。 But it doesn`t work for Starling. 但这对Starling无效。

My idea is to add some listener to root, cause this Sprite is in display list tree. 我的想法是向根添加一些侦听器,因为此Sprite在显示列表树中。 And find who is this Spite's parent. 并找到谁是这个Spite的父母。 Is it possible? 可能吗?

And find who is this Spite's parent. 并找到谁是这个Spite的父母。 Is it possible? 可能吗?

If you are trying to find a display object, and you have no idea where it is coming from, one thing you could try doing is in a frame event, keep track of all the new sprites that are added to the display list. 如果您试图查找显示对象,却不知道它来自何处,则可以尝试做的一件事是发生在框架事件中,跟踪添加到显示列表中的所有新精灵。 Then you can work backwards from there. 然后,您可以从那里向后工作。 Eg. 例如。

  // keep track of unique display objects
  private var _displayList:Array = [];
  public function Main()
  {
      addEventListener( Event.ENTER_FRAME, trackDisplayList );
  }

  private function trackDisplayList( event:Event ):void
  {
      trackAsset( stage );
  }

  private function trackAsset( asset:* ):void
  {
      var i:int = -1;
      while( ++i < asset.numChildren )
      {
          var child:* = asset.getChildAt( i );
          if ( _displayList.indexOf( child ) == -1 )
          {
              _displayList.push( child );
              trace( "tracking display object: " + child.name );
          }
          if ( child.numChildren > 0 )
          {
              trackAsset( child );
          }
      }
  }

Hopefully you don't have a boat load of sprites to sort through! 希望您没有大量的精灵可以进行排序! This is one way you could recursively check all your unique display objects. 这是您可以递归检查所有唯一显示对象的一种方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM