Flex 4 states: includeIn and creationComplete component

I have a component that, when everything is ready, I need to set the state based on the variable that I am reading from XML. I tried to do this with help creationComplete, but it is apparently not ready, since the state is not set with the elements being processed correctly, but the states and rendering work fine if I make a subsequent state change with the action of clicking on some element.

What should I do in this situation to make sure that the state is set at the right time, and the elements that should appear due to includeInexist so that they can be visualized? initializeinstead creationComplete, it doesn't seem to do the trick the first time the component is created. Any consecutive component calls are good.

+3
source share
3 answers

FYI, it is not surprising that it initializedid not work, it was run before the creation of the children, and then it worked creationComplete. Because creationCompletethis is the last event in the init lifecycle to run.

Sometimes you need to change the state of a child component from the parent container if the event creationCompletefor the component is fired prematurely.

creationComplete , creationComplete.

Adobe

creationPolicy

creationPolicy , all. ( , auto)

enterState

enterState , , .

visible.state.

/ ( includeInLayout .) , . enterState , .

+4

, , , itemCreationPolicy = . createComplete.

<s:states>
<s:State name="normal" />
<s:State name="special" />
</s:states>

<s:Label text="normal" includeIn="normal" /> //is available creationComplete
<s:Label text="special1" includeIn="special" itemCreationPolicy="immediate" /> //is available creationComplete
<s:Label text="special2" includeIn="special" /> //not available creationComplete
+1

, reset . , , . :

You can hook an event handler on enterState in a status declaration ... [emphasis added]

... which looks like this:

protected function state1_enterStateHandler(event:FlexEvent):void
{
    myComponent.reset();
}

<s:states>
    <s:State id="state1" name="state1" enterState="state1_enterStateHandler(event)" />
    <s:State name="state2" />
</s:states>

<views:MyComponent id="myComponent" includeIn="state1" />

I tried to add an event handler to myComponent without success. I would prefer it there, but this seemed to be the only way to update every time the state was turned on again.

This causes reset every time state1 becomes currentState and all components are ready and properties are set.

+1
source

Source: https://habr.com/ru/post/1789402/


All Articles