I want to reinitialize a component by clicking a button.I use the following code, but seem nothing is happening.
protected function createItem(event:MouseEvent):void
{
this.currentState="Viewer";
this.initialize();
}
Why?
Yes I am referring the Flex Component lifecycle. I know there have four step for flex to create a Component, but Is there having a method to force Flex to execute those step again?
Actually, there are much more steps than four to the Flex Component Lifecycle. See here and here for more information.
What you may mean is that there are four methods run as part of the Flex Component LifeCycle; and those are createChildren(), commitProperties(), updateDisplayList(), and measure(). In the MX architecture, there is also a layoutChrome() method, but that is not commonly used.
In Flex 4 Spark architecture; there are a lot of other hooks (partAdded(), partRemoved()) but they all extend off the MX Architecture.
You may benefit from using the invalidation methods:
In a Flex 4, Spark component, run invalidateSkinState() to force getCurrentSkinState() method to re-execute during the next render event.
You can also remove a component from the stage using removeChild()--removeElement() for Spark containers--and then addChild()--addElement for Spark containers. That would essentially force the component to re-start it's process.
You could also create a brand new instance of the component and remove the old one.