转载自:http://blog.sina.com.cn/s/blog_78b3ed7c0100t0l9.html
在flex Application 中添加一个以Sprite类为基类的对象 animation。
使用this.addChild(animation)后,编译通过,但是运行时,直接报错。
TypeError: Error #1034: 强制转换类型失败:无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent。
原因如下:
在flex框架中Uicomponent的继承结构如下:
UIComponent > FlexSprite> Sprite >DisplayObjectContainer>InteractiveObject >Displayobject,
在flash中(Sprite类的继承关系)
Sprite >DisplayObjectContainer>InteractiveObject >Displayobject,
通常情况下的类关系是
Application→LayoutContainer→Container→UIComponent→FlexSprite→Sprite→DisplayObjectContainer
所以解决方法是:
如果要在Application里添加Sprite,可以先把它装进一个UIComponent,然后再添加这个UIComponent:
import mx.core.UIComponent;
private function init():void
{
}