53.
this will cause the component, its container
(and its containers container, so on ...),
its surrounding components etc. to recalculate size
and positioning of themselves and all their children ..
i.e a lot of calculation will happen.

54.
now in the next code segment you change width of
your component again .... all that calculation will
happen again ...
now since code segments can execute more times
than render segments ...

55.
your ﬁrst set of calculations for change in width could
potentially be useless ..

56.
... this is the main reason a component needs a
life cycle
performance

64.
lets setup some breakpoints and walk
through some code as we look at
each of these phases ..

65.
Construction
var b:MyButton = new MyButton();
• not much happens in this phase
• thats good because Constructors are not JIT
• the component is given a name in FlexSprite
• event listeners are added

66.
Addition
this.addChild(b);
• calls addingChild(), $addChild() and childAdded()
• a lot happens in addingChild(),
• child’s parent and document properties are set etc.
• $addChild() is the ﬂash player method that adds the component to the display list
• childAdded() calls the initialize() method of the child if not initialized

67.
Initialization
initialize(); // called by the parent’s childAdded
• ﬁres FlexEvent.PREINITIALIZE when it starts
• calls createChildren() .. where children of this component
are created and added to itself
• ﬁres FlexEvent.INITIALIZED when it ends

68.
Construction
Addition BIRTH
Initialization
a component has been born ...

97.
attachSkin() creates the skin and adds it as a
child ...
which in turn kicks off the life cycle of the skin

98.
attachSkin() also calls ﬁndSkinParts() which looks
though the children of the skin and populates our
declared static part references

99.
attachSkin() also calls ﬁndSkinParts() which looks
though the children of the skin and populates our
declared static part references
ﬁndSkinParts() calls partAdded() for all the static
parts it ﬁnds

100.
attachSkin() also calls ﬁndSkinParts() which looks
though the children of the skin and populates our
declared static part references
ﬁndSkinParts() calls partAdded() for all the static
parts it ﬁnds
also throws an exception if it does not ﬁnd a
required part

101.
at a later time, when you create a dynamic part
using createDynamicPartInstance()
that method calls partAdded() as well