/**
         * Build and returns a new Armature instance.
         * @example
         * <listing>
         * var armature:Armature = factory.buildArmature('dragon');
         * </listing>
         * @param	armatureName The name of this Armature instance.
         * @param	The name of this animation.
         * @param	The name of this SkeletonData.
         * @param	The name of this textureAtlas.
         * @param	The name of this skin.
         * @return A Armature instance.
         */
        public Armature BuildArmature(string armatureName, string animationName = null, string skeletonName = null, string textureAtlasName = null, string skinName = null)
        {
            SkeletonData data                  = null;
            ArmatureData armatureData          = null;
            ArmatureData animationArmatureData = null;

            if (skeletonName != null)
            {
                data = _dataDic[skeletonName];
                if (data != null)
                {
                    armatureData = data.GetArmatureData(armatureName);
                }
            }
            else
            {
                foreach (KeyValuePair <string, SkeletonData> skeleton in _dataDic)
                {
                    data         = _dataDic[skeleton.Key];
                    armatureData = data.GetArmatureData(armatureName);
                    if (armatureData != null)
                    {
                        break;
                    }
                }
            }

            if (armatureData == null)
            {
                return(null);
            }

            _currentDataName = skeletonName;

            if (textureAtlasName != null)
            {
                _currentTextureAtlasName = textureAtlasName;
            }
            else
            {
                _currentTextureAtlasName = skeletonName;
            }

            Armature armature = generateArmature();

            armature.Name = armatureName;
            Bone bone;

            foreach (BoneData boneData in armatureData.BoneDataList)
            {
                bone               = new Bone();
                bone.Name          = boneData.Name;
                bone.FixedRotation = boneData.FixedRotation;
                bone.ScaleMode     = boneData.ScaleMode;
                bone.Origin.Copy(boneData.Transform);

                if (armatureData.GetBoneData(boneData.Parent) != null)
                {
                    armature.AddBone(bone, boneData.Parent);
                }
                else
                {
                    armature.AddBone(bone);
                }
            }

            if (animationName != null && animationName != armatureName)
            {
                animationArmatureData = data.GetArmatureData(animationName);
                if (animationArmatureData == null)
                {
                    foreach (KeyValuePair <string, SkeletonData> skeleton in _dataDic)
                    {
                        data = _dataDic[skeleton.Key];
                        animationArmatureData = data.GetArmatureData(animationName);
                        if (animationArmatureData != null)
                        {
                            break;
                        }
                    }
                }
            }

            if (animationArmatureData != null)
            {
                armature.Animation.AnimationDataList = animationArmatureData.AnimationDataList;
            }
            else
            {
                armature.Animation.AnimationDataList = armatureData.AnimationDataList;
            }

            SkinData skinData = armatureData.GetSkinData(skinName);

            if (skinData == null)
            {
                throw new ArgumentException();
            }

            Slot          slot;
            DisplayData   displayData;
            Armature      childArmature;
            int           i;
            List <object> helpArray = new List <object>();

            foreach (SlotData slotData in skinData.SlotDataList)
            {
                bone = armature.GetBone(slotData.Parent);
                if (bone == null)
                {
                    continue;
                }
                slot                 = generateSlot();
                slot.Name            = slotData.Name;
                slot.BlendMode       = slotData.BlendMode;
                slot._originZOrder   = slotData.ZOrder;
                slot._dislayDataList = slotData.DisplayDataList;

                helpArray.Clear();
                i = slotData.DisplayDataList.Count;
                while (i-- > 0)
                {
                    displayData = slotData.DisplayDataList[i];

                    switch (displayData.Type)
                    {
                    case DisplayData.ARMATURE:
                        childArmature = BuildArmature(displayData.Name, null, _currentDataName, _currentTextureAtlasName);
                        if (childArmature != null)
                        {
                            helpArray.Insert(0, childArmature);
                        }
                        break;

                    case DisplayData.IMAGE:
                    default:
                        helpArray.Insert(0, generateDisplay(_textureAtlasDic[_currentTextureAtlasName], displayData.Name, displayData.Pivot.X, displayData.Pivot.Y));
                        break;
                    }
                }
                slot.DisplayList = helpArray;
                slot.changeDisplay(0);
                bone.AddChild(slot);
            }

            //
            i = armature._boneList.Count;
            while (i-- > 0)
            {
                armature._boneList[i].update();
            }

            i = armature._slotList.Count;
            while (i-- > 0)
            {
                slot = armature._slotList[i];
                slot.update();
            }
            armature.UpdateSlotsZOrder();

            return(armature);
        }