Addchild () in flex Application ()

Source: Internet
Author: User

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 );

}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.