Flex 4 Component Lifecycle (Slides and Code)
I gave a talk this Friday on the lifecycle of a component in Flex 4. The talk went into the details of how the flash player works, why a component needs a lifecycle and the various stages of a components life.
UPDATE: I gave the same talk at FlexMania .. Here’s the 1hr long Adobe Connect recording
Here are the slides and experimental code from the talk …
Here’s the code we played with to understand how frame rates work in the flash player …
FrameRates.as
Here’s the code we wrote with to understand the Elastic Racetrack …
ElasticRaceTrack.as
Here’s the experiment to understand marshaled slices …
MarshaledSlices.as
The presentation was slightly long and I’ve already heard that some people found it boring but I hope that wasn’t the case for everyone
I would like to thank all the awesome people in the Flash/Flex community who have helped me understand all this by publishing some great articles and blog posts … here are just some of the articles that I’ve found very useful …
Ted Patrick on the Elastic Racetrack
Sean Christmann’s Updated ‘Elastic Racetrack’ for Flash 9 and AVM2
Ely Greenfrield on Building a Flex Component [PDF] (Thanks Ted Patrick for making it available on his blog)
“Diving Deep With the Flex Component Lifecycle,” by Brad Umbaugh and RJ Owen
White Paper by the guys at Development Arc on Component Lifecycle
Please do let me know what you thought of my talk and how I can improve it.









June 22nd, 2009
Hi,
I missed attending the talk as I was held up with work at office. Thanks for sharing the slides.
-Anish
http://wwww.macoscoders.com/
June 22nd, 2009
[...] UPDATE: I’ve posted the slides and code from the talk here [...]
June 22nd, 2009
Thanks a lot for
By the way Download Slides button is not working
June 22nd, 2009
Hey Kiran,
Thanks, just fixed the link
Mrinal
June 22nd, 2009
Thats a fantastic presentation Mrinal, thanks. I havent looked too deep into Fx4 yet so very instructive.
June 22nd, 2009
Thanks Arpit, I’m very glad you like it
June 22nd, 2009
@Anish hopefully you can make it to the meeting next time
June 22nd, 2009
Hey Mrinal,
; but the experimental proofs were really awesome.
Really a nice job.
Thanks for the great talk. It was a bit long, not boring
Regards,
Anshuman
June 22nd, 2009
Hay Mrinal,
Cool preso man, I am sad I missed it
. Will definitely try to catch next time
June 22nd, 2009
Hey Mrinal,
As a newbie like me, presentation is very heavy, So i felt bit boring (i think only me) .But coding examples are really nice & i get lot of things from that. i missed a lot also
June 22nd, 2009
Impressive presentation Mrinal, Congrats and thanks for sharing.
June 22nd, 2009
Very interesting presentation Mrinal! Thanks for posting the slides and code for the benefit of all those who couldn’t attend the meeting in person. Very informative!
June 22nd, 2009
Thanks Mrinal for fixing the Link .
Only thing in the slides that confuses me is death part and also you mentioned that it removes the component from the display list. Thats right it just removes reference to its parent object . But it won’t be the death to the Object . You can get the same object if you add it to any other object . In my understanding Death is Basically sending Object for Garbage collection . Could you please shed some light on that perspective? Sorry for questioning you .
Regards
Kiran
June 22nd, 2009
Hi Kiran
Checkout the removeChild method of UIComponent class
death in the slides refers to the death of a component’s life … i.e it is no longer living the invalidation/validation cycle.
the references held by a component’s parent and the display list are removed in removeChild … but there could be other references out there … in an even listener for example … so garbage collection (or death of the object) will happen when the garbage collector runs and reference count is zero
Hope that helps,
Mrinal
June 22nd, 2009
Thanks Mrinal,
Please excuse me for asking again and again . Correct me if I am wrong
But what confuses me , Could you please run the following code and enter some thing in the text field and hit Vanish button . It will remove the child(text field) and then again click on Appear Button . It will add the text field again , But the text you entered before clicking on Vanish button still there . That feels the object still exist and also doc says ( this help I got it by pressing F1 on Flex Builder )
removeChild () method
public override function removeChild(child:DisplayObject):DisplayObject
Removes a child DisplayObject from the child list of this Container. The removed child will have its parent property set to null. The child will still exist unless explicitly destroyed. If you add it to another container, it will retain its last known state.
——————————————————————————————–
June 23rd, 2009
Of course, the object still exists .. your own code is holding a reference to it (tempText)
An object only gets garbage collected when there is no reference to it .. also you have no control over when the garbage collector runs .. so till the time an object has been garbage collected .. it will remember its last state … if you set text on it .. it will remember it.
removeChild as you said only nulls the reference that a parent holds .. it also removes the object from the diplaylist .. so if displaylist holds a reference that would be nulled too … but this does not mean the object will no longer exist .. the object may or may not become ready for garbage collection at this point .. but removing from parent and displaylist is a totally separate operation from removing the object from memory
removeChild simply means that the “Component” is no longer going through the invalidate validate cycle that we described as life in the slides
June 24th, 2009
Nice presentation Mrinal!
June 24th, 2009
Thank you John
June 25th, 2009
Thanks Mrinal for an interesting and instructive presentation!
I liked the fact that you went into the details of the Flash player to give us a more complete picture.
June 27th, 2009
Thanks Vandana .. I think its important to emphasize that its the Flash Player that is doing most of the hard work .. Flex is just a bunch of convenience classes.
July 1st, 2009
Hi Mrinal,
.
I missed out the presentation as i was out of city and after going throught your slides, am feeling really missed out on an opportunity to learn something which I was badly looking for. Nevertheless will try to catch something from slides and code. Thanks for sharing them. Do let me know in case you repeat the presentation anywhere else
July 10th, 2009
Hey Everyone,
I gave the same talk at FlexMania .. Here’s the 1hr long Adobe Connect recording
_
Mrinal
July 10th, 2009
[...] AND CODE: The slides and code from the talk can be found [...]
July 23rd, 2009
Very Informative..Thank you so much for the post
July 31st, 2009
[...] here UPDATE: I gave a talk on the Lifecycle of a Component in Flex 4 first at Bangalore Flex User Group and then at FlexMania conference, check out the video recording, [...]
August 27th, 2009
Thanks and slide is very best and easy to understand the life cycle of Flex3 and Flex4 component
October 13th, 2009
Hi,
very good article!
I’ve some questions for you.
First question
What’s a frame? Is it essentially a slot of time or something else? I think a frame is a logic unic linked with ActionScript code, isn’t true?
Second Question
During a component’s lifecycle, a render event is dispatched. You say that render events happen before the invalidate action’s section, Do you mean that invalidate methods, like invalidateproperties() or invalidateSize(), have already executed? In this case flags have already set.
Thanks in advance,
Best regards
Lorenzo
October 17th, 2009
[...] biggest source was Mrinal Wadhwa’s similar presentation which provided a lot of inspiration and some things I could steal to make myself seem smarter than [...]
February 5th, 2010
[...] A Flex 4 Component’s life cycle [...]