From: http://www.cnblogs.com/jiahuafu/archive/2009/03/20/1417679.html
In Flex
In the application, you cannot directly use addchild to add Sprite, movieclip, and other classes from the flash. Display package. For exampleCodeAn error is reported:
PrivateFunction Init ():Void
{
VaR SP: Sprite= NewSprite ();
Addchild (SP );
}
Typeerror: Error #1034: forced conversion type failed: Flash. display: SPRITE @ 156b7b1 cannot be converted to MX. Core. iuicomponent.
This is because the addchild method of application is not completely inherited from displayobjectcontainer,
Application → layoutcontainer → container → uicomponent → flexsprite → sprite → displayobjectcontainer
Instead, it is overwritten in the container:
Public override function addchild (Child: displayobject): displayobject
Public override function addchild (Child: displayobject): displayobject although the type of the parameter child is displayobject, it must implement the iuicomponent interface (all flex components have implemented this interface) before it can be added.
If you want to add a sprite to the application, you can first load it into a uicomponent, and then add the uicomponent:
Code
ImportMX. Core. uicomponent;
PrivateFunction Init ():Void
{
VaR SP: Sprite= NewSprite ();
VaR UC: uicomponent= NewUicomponent ();
UC. addchild (SP );
Addchild (UC );
}