actionscript 3 – AS3 Object Coercion – Education Career Blog

Hi guys I get this coercion error:

TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::[email protected] to flash.display.

When I create an instance of a MovieClip from my library:

var childmc:ChipEasy = new ChipEasy();
Canvas.Map.Tiles.addChild(childmc);

When I try to access all the children like:

for (var i:int=0; i<Canvas.Map.Tiles.numChildren-1; i++)
{
    var mc:MovieClip = Canvas.Map.Tiles.getChildAt(i);
}

Any suggestions?

,

One (or more) of the children is Shape, it can’t be converted to MovieClip. Get children as DisplayObject, then you may check

if (child is MovieClip)
{
     var mc:MovieClip = child as MovieClip; //safe cast
}

Leave a Comment