[Flex] Life Cycle of flex component and container children

Source: Internet
Author: User
Detailed usage Flex When you encounter such a problem, New Come out Component Internal components cannot be operated directly. Null . Of course, we are writing Script You can set Children In Constructor . In this way, this problem will not occur. But when we are doing Mxml This problem is very obvious when components are used. We must follow Flex Of Component Life Cycle . The common practice is to put Property Inside , For example

<? XML version = "1.0" encoding = "UTF-8"?>

<Mx: canvas xmlns: MX = "http://www.adobe.com/2006/mxml" width = "400" Height = "300">

<Mx: SCRIPT>

<! [CDATA [

Private var title: string;

Private var bnamechanged: Boolean;

 

Public Function set title (value): void

{

If (title! = Value)

{

Title = value;

Bnamechanged = true;

This. invalidateproperties ();

}

}

Override protected function commitproperties (): void

{

Super. commitproperties ();

If (bnamechanged)

{

Bnamechanged = false;

Lblname. Text = title;

}

}

]>

</MX: SCRIPT>

<Mx: Label id = "lblname"/>

</MX: canvas>

 

However, you are usingContainerInNullBut what is the problem? For example, you put two components on oneTabnavigate.

 

<? XML version = "1.0" encoding = "UTF-8"?>

<Mx: Application xmlns: MX = "http://www.adobe.com/2006/mxml" layout = "absolute" xmlns: Local = "*">

<Mx: tabnavigator>

<Local: testcomponent id = "test1" Title = "Test 1"/>

<Local: testcomponent id = "Test2" Title = "Test 2"/>

</MX: tabnavigator>

</MX: Application>

Try to ensure 

Error #1009: the attribute or method referenced by the null object cannot be accessed.

At this time, I started to complain. Why?FlexWhy do you not comply with your game rules?,HereTabnavigatorOfChildrenIt is called before it is created,CommitepropertiesOrUpdatedisplaylistMethod. This should beFlexOneBug.

To solve this problem, we only needTabnavigatorIn the createChildrenAllChildrenAre created. At this time, we need to pay attentionContainer. createpolicyAttribute.ContainerInternalChildrenNot inCreatechildAs forChildrenThe creation time, take a good look

Containercreationpolicy,AndContainerInternalChildren (PassMxmlAddedChildren)AndCreatechildrenCreated inChidrenIt can be understood as different types.

In the above exampleTabnavigatorAddCreatepolicy = "all"All files are fixed.

 

If you have any questions, please correct them..

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.