code_junkie

Why are a DisplayObject's child's .name property and the results of getChildByName() sometimes different?

Nov 11th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. var gfx:MovieClip = new a_Character(); //(a library object exported for Actionscript)
  2.  
  3. var do1:DisplayObject = null;
  4. var do2:DisplayObject = null;
  5.  
  6. for( var i:int = 0 ; i < gfx.amSword.numChildren ; i++ )
  7. {
  8. var child:DisplayObject = gfx.amSword.getChildAt(i);
  9. if( child.name == "amWeaponExchange" ) //An instance name set in the IDE
  10. {
  11. do2 = child;
  12. }
  13. }
  14.  
  15. trace("do2:", do2 );
  16.  
  17. var do1:DisplayObject = gfx.amSword.getChildByName("amWeaponExchange");
  18.  
  19. do2: [object MovieClip]
  20. ReferenceError: Error #1069: Property amWeaponExchange not found on builtin.as$0.MethodClosure and there is no default value.
  21.  
  22. var do1:DisplayObject = gfx.amSword.getChildByName["amWeaponExchange"];
  23.  
  24. ReferenceError: Error #1069: Property amWeaponExchange not found on builtin.as$0.MethodClosure and there is no default value.
  25.  
  26. var do1:DisplayObject = gfx.amSword.getChildByName("amWeaponExchange");
Add Comment
Please, Sign In to add comment