質問

I have a spark Group container, but all its sub-components are MX components. I need to perform some operations on the MX components when the container is initialized. I tried to put the operations in the commitProperties function, but the sub-components are still null there. I tried moving them to the childrenCreated function, but they are still null. What function can I use for working with the components? Thanks.

protected override function commitProperties():void
        {
            var defaultFinishedDate:Date=new Date();
            defaultFinishedDate.date--;
            includeFinishedDateSelector.selectedDate=defaultFinishedDate;
        }

The includeFinishDateSelector is null in this function, and thus I'm getting a run-time error. It's defined as:

<mx:DateField id="includeFinishedDateSelector" formatString="{GeneralUtils.DATE_FORMAT_STRING}" 
    enabled="{includeFinishedCheckBox.selected}" width="18%"/>

And as I said, its container is a spark Group container.

役に立ちましたか?

解決 3

Thanks to whomever tried to help. In the end I solved this by changing the direct container (parent) of the MX components to a spark container (it was originally an MX container in a spark container).

他のヒント

I would have expected the Flex life cycle method createChildren() is where you could do your operations. But you'd want to only do this work AFTER the super class has executed createChildren():

override protected function createChildren():void
{
    super.createChildren();
    // now do your thing
}

Another thing is that in the commitProperties() method you show above, you are not calling the super class method. That is a big no-no. The commitProperties() method is invoked by the Flex framework AFTER createChildren(). So theoretically, your approach with commitProperties() should have worked -- you might go back and put a call to super.commitProperties() in that code and give it another go.

Finally, if none of this works it may be due to the way Flex instantiates the children objects in MXML containers. So an approach that will definitely work is to listen for Flex life cycle events from the Group container. When the creationComplete event is dispatched by the Group, it is guaranteed that all of the children exist.

You can also try to wrap your code in callLater, it will essentially queue it to run on the next pass. So in creationComplete try the following:

callLater(function():*{
    var defaultFinishedDate:Date=new Date();
    defaultFinishedDate.date--;
    includeFinishedDateSelector.selectedDate=defaultFinishedDate;
});

It's not very elegant, but it should work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top