I have a component that, once it's all ready, I need to set the state based on a variable I'm reading in from XML. I tried doing it with creationComplete
, but it's apparently not ready, as the state isn't being set with elements rendering properly, but the states & rendering work fine if I do a subsequent state change with a click action on some element.
What should I do in this situation to make sure the state gets set at the right time & elements that should appear due to includeIn
exist so they can be rendered? initialize
instead of creationComplete
doesn't seem to do the trick for the first time the component is created. Any successive calls to the component are fine.
FYI, it's no surprise that
initialize
didn't work, it's fired before the child elements are created, andcreationComplete
then fires. SincecreationComplete
is the last event in the init lifecycle to fire.Sometimes you need to change child component state from the parent container, if the
creationComplete
event for the component is fired prematurely.creationComplete
for any component fires after all of it's child components have fired theircreationComplete
.Have a look at Adobe's documentation for the component instantiation life cycle
creationPolicy
You may also need to set the
creationPolicy
attribute for your app, toall
. (I think it's default isauto
)enterState
You can hook an event handler on
enterState
in a state declaration, once that runs the objects within the state should be available.visible.state properties.
Ultimately you can set the containers for your state based objects to be invisible / not included in the layout (visible and includeInLayout properties.) On occassion you won't have any other method of reaching an object through code, because it won't exist. However,
enterState
should only execute when a view state has been entered, so objects within that state should be fully available.