无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent
2014-03-27 14:54
316 查看
无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent
在Flex Application里,是不能直接用addChild添加Sprite,MovieClip等来自flash.display包里的类的。譬如以下代码就会报错:
private function init():void { var sp:Sprite = new Sprite(); addChild(sp);}TypeError: Error #1034: 强制转换类型失败:无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent。
这是因为Application的addChild方法并非完全继承自DisplayObjectContainer,
Application→LayoutContainer→Container→UIComponent→FlexSprite→Sprite
→DisplayObjectContainer
而是在Container那里被重写了:
public override function addChild(child:DisplayObject):DisplayObject
虽然参数child的类型是DisplayObject,但是它必须实现IUIComponent接口(所有Flex组件都实现了这一接口),才能添加。
如果要在Application里添加Sprite,可以先把它装进一个UIComponent,或者用UIMOVIECLIP,然后再添加这个UIComponent:
import mx.core.UIComponent;private function init():void { var sp:Sprite = new Sprite(); var uc:UIComponent = new UIComponent(); uc.addChild(sp); addChild(uc);}
相关文章推荐
- 无法将 flash.display::Sprite@156b7b1 转换为 mx.core.IUIComponent
- TypeError: Error #1034: 强制转换类型失败:无法将 global@189ac0d1 转换为 mx.core.IFlexDisplayObject。
- 无法将 flash.display::BitmapData 转换为 flash.display.Bitmap
- TypeError: Error #1034: 强制转换类型失败:无法将 mx.controls::DataGrid@9a7c0a1 转换为 spark.core.IViewport。
- TypeError: Error #1034: 强制转换类型失败:无法将 flash.events::MouseEvent@73b7cc1 转换为 mx.events.ItemClickEvent。
- TypeError: Error #1034: 强制转换类型失败:无法将 mx.controls::DataGrid@9a7c0a1 转换为 spark.core.IViewport。
- TypeError: Error #1034: 强制转换类型失败:无法将 flash.events::MouseEvent@73b7cc1 转换为 mx.events.ItemClickEvent。
- 无法将 flash.display::AVM1Movie 转换为 flash.display.MovieClip错误原因
- TypeError: Error #1034: 强制转换类型失败:无法将 flash.events::MouseEvent@73b7cc1 转换为 mx.events.ItemClickEvent。
- TypeError: Error #1034: 强制转换类型失败:无法将 flash.display::BitmapData@79aea11 转换为 flash.display.Bitmap
- [解决]无法将....object 转换为 mx.messaging.messages.IMessage
- Error #1034: 强制转换类型失败:无法将 mx.managers::DragManagerImpl@141c5b81 转换为 mx.managers.IDragManager。
- 使用EF6.0出现:CS0029 无法将类型“System.Data.Entity.Core.Objects.ObjectContext”隐式转换为“System.Data.Objects.ObjectContext”错误
- 强制转换类型失败:无法将 mx.managers::DragManagerImpl转换为 mx.managers.IDragManage
- FlashBuilder中 Molehill项目运行时 VerifyError: Error #1014: 无法找到类 flash.display3D::Context3D。错误解决方法
- TypeError: Error #1034: 强制转换类型失败:无法将 Object@2555f679 转换为 mx.messaging.messages.IMessage。
- 无法将 mx.charts.events::ChartItemEvent转换为 mx.events.IndexChangedEvent。
- TypeError: Error #1034: 强制转换类型失败:无法将 "0.49" 转换为 mx.graphics.IFill。
- TypeError: Error #1034: 强制转换类型失败:无法将 "0.49" 转换为 mx.graphics.IFill。
- Error #1034: 强制转换类型失败:无法将 mx.graphics::Stroke@b945581 转换为 mx.graphics.IStroke