Flex 4 Component Lifecycle (Slides and Code)

June 21, 2009

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

Download Slides
Download Source Code

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.

37 Responses - What do you think?

  1. 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/

  2. [...] UPDATE: I’ve posted the slides and code from the talk here [...]

  3. Thanks a lot for

    By the way Download Slides button is not working

  4. Hey Kiran,

    Thanks, just fixed the link

    Mrinal

  5. Thats a fantastic presentation Mrinal, thanks. I havent looked too deep into Fx4 yet so very instructive.

  6. Thanks Arpit, I’m very glad you like it :)

  7. @Anish hopefully you can make it to the meeting next time :)

  8. Anshuman Rudra
    June 22nd, 2009

    Hey Mrinal,
    Really a nice job.
    Thanks for the great talk. It was a bit long, not boring :) ; but the experimental proofs were really awesome.

    Regards,
    Anshuman

  9. RT @davidderaedt: RT @gillesguillemin: Flex 4 Component Lifecycle http://bit.ly/FS79v #feedly

  10. Gumbo component livecycle -> http://tr.im/pj6D

  11. Hay Mrinal,

    Cool preso man, I am sad I missed it :( . Will definitely try to catch next time :)

  12. 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 :)

  13. Impressive presentation Mrinal, Congrats and thanks for sharing.

  14. 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!

  15. Flex 4 Component Lifecycle (Slides and Code) http://bit.ly/OmfnX
    .. all frames!

  16. RT @gillesguillemin: Flex 4 Component Lifecycle http://bit.ly/FS79v #feedly Not much new but a solid review.

  17. RT @govisualperu Flex 4 Component Lifecycle (Slides and Code) http://bit.ly/OmfnX .. all frames!

  18. 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

  19. RT @pettheory: RT @gillesguillemin: Flex 4 Component Lifecycle http://bit.ly/FS79v #feedly Not much new but a solid review.

  20. 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

  21. 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.
    ——————————————————————————————–

  22. 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

  23. Nice presentation Mrinal!

  24. 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.

  25. 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.

  26. 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 :) .

  27. Hey Everyone,

    I gave the same talk at FlexMania .. Here’s the 1hr long Adobe Connect recording
    _
    Mrinal

  28. [...] AND CODE: The slides and code from the talk can be found [...]

  29. RT @mrinal: Recording of my talk-Flex4 Component’s Lifecycle @flexmania2009 http://go.mrinalwadhwa.com/flext4 Slides,Code http://tr.im/rFTO

  30. Very Informative..Thank you so much for the post

  31. [...] 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, [...]

  32. Thanks and slide is very best and easy to understand the life cycle of Flex3 and Flex4 component

  33. RT @mrinal: @anandvardhan http://bit.ly/YXV9M taht’s slides, sample code and a connect recording presentation of Flex 4 life cycle

  34. 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

  35. [...] 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 [...]

  36. [...] A Flex 4 Component’s life cycle [...]

Your thoughts or questions: