Can anyone explain the difference between the "name" property of a display object and the value found by getChildByName("XXX") function? They're the same 90% of the time, until they aren't, and things fall apart.
For example, in the code below, I find an object by instance name only by directly examining the child's name property; getChildByName() fails.
var gfx:MovieClip = new a_Character(); //(a library object exported for Actionscript)
var do1:DisplayObject = null;
var do2:DisplayObject = null;
for( var i:int = 0 ; i < gfx.amSword.numChildren ; i++ )
{
var child:DisplayObject = gfx.amSword.getChildAt(i);
if( child.name == "amWeaponExchange" ) //An instance name set in the IDE
{
do2 = child;
}
}
trace("do2:", do2 );
var do1:DisplayObject = gfx.amSword.getChildByName("amWeaponExchange");
Generates the following output:
do2: [object MovieClip]
ReferenceError: Error #1069: Property amWeaponExchange not found on builtin.as$0.MethodClosure and there is no default value.
Any ideas what Flash is thinking?