大家好我得到了这个强制错误:
TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Shape@41754601 to flash.display.
当我从我的库中创建一个MovieClip实例时:
var childmc:ChipEasy = new ChipEasy();
Canvas.Map.Tiles.addChild(childmc);
当我尝试访问所有孩子时:
for (var i:int=0; i<Canvas.Map.Tiles.numChildren-1; i++)
{
var mc:MovieClip = Canvas.Map.Tiles.getChildAt(i);
}
有什么建议吗?
答案 0 :(得分:4)
其中一个(或多个)孩子为Shape
,无法转换为MovieClip
。让孩子为DisplayObject
,然后您可以检查
if (child is MovieClip)
{
var mc:MovieClip = child as MovieClip; //safe cast
}