SlideShare a Scribd company logo
1 of 44
Download to read offline
Adobe Flex 3 Component
       Lifecycle

   Presented by Ethan Du(杜增强)
Who am I ?


   Ethan Du
     – Senior Flex Architect @ 123Show
     – blog: http://www.duzengqiang.com
Flex
   What is Flex?
   • MXML
   • A set of components
   • The component lifecycle!
Flex Component Lifecycle
   What is it?
   • The way the framework interacts with
   every Flex component
   • A set of methods the framework calls to
   instantiate, control, and destroy components
Phases of the Lifecycle
   3 Main Phases:
     BIRTH:
    • construction, configuration,attachment,
    initialization
     LIFE:
    • invalidation, validation, interaction
     DEATH:
    • detachment, garbage collection
Birth
Construction
What is a constructor?
   A function called to instantiate (create in
 memory) a new instance of a class
How is a constructor invoked?

               Actionscript:
      var theLabel : Label = new Label();
                  MXML:
          <mx:Label id="theLabel"/>
What does an ActionScript3
constructor look like?
 public function ComponentName()
 {
   super();
   //blah blah blah
 }
   No required arguments (if it will be used in
 MXML); zero, or all optional
   Only one per class (no overloading!)
   No return type
   Must be public
   Call super()…or the compiler will do it for you.
What should a constructor do?
   A good place to add event listeners to the
 object.

   Not much. Since the component’s
 children have not yet been created, there’s
 not much that can be done.
Don’t create or add children in
the constructor

    It’s best to delay the cost of createChildren
  calls for added children until it’s necessary
Configuration
Configuration
   The process of assigning values to
 properties on objects
   In MXML, properties are assigned in this
 phase, before components are attached or
 initialized
 <local:SampleChild property1="value"/>
Configuration Optimization
   To avoid performance bottlenecks, make
 your setters fast and defer any real work
 until validation
   We’ll talk more about deferment in the
 validation / invalidation section
Attachment
What is attachment?
   Adding a component to the display list
 (addChild, addChildAt, MXML declaration)
Methods

  addingChild(child);

  $addChildAt(child, index);

  childAdded(child);
Must know about attachment
   The component lifecycle is stalled after
 configuration until attachment occurs.
Consider this component:
 public class A extends UIComponent
 {
           public function A() {
                              trace( "CONSTRUCTOR" );
                              super();
           }

          override protected function createChildren() : void {
                            trace( "CREATECHILDREN" );
                            super.createChildren();
          }

          override protected function measure() : void {
                            trace( "MEASURE" );
                            super.measure();
          }

          override protected function updateDisplayList(width:Number, height:Number) : void {
                            trace( "UPDATEDISPLAYLIST" );
                            super.updateDisplayList(width,height);
          }

          override protected function commitProperties():void {
                            trace( "COMMITPROPERTIES" );
                            super.commitProperties();
          }

 (It traces all of its methods.)
And this application:
 <mx:Application ...>
    <mx:Script>
     <![CDATA[
           override protected function createChildren() :
   void {
                   super.createChildren();
                   var a : A = new A();
           }
     ]]>
    </mx:Script>
 </mx:Application>
Output:
  CONSTRUCTOR




  Without attachment, the rest of the lifecycle
doesn’t happen.
But what about this application?
 <mx:Application ...>
    <mx:Script>
     <![CDATA[
           override protected function createChildren() :
   void {
                   super.createChildren();
                   var a : A = new A();
 this.addChild( a );
           }
     ]]>
    </mx:Script>
 </mx:Application>
Output:
  CONSTRUCTOR
  CREATECHILDREN
  COMMITPROPERTIES
  MEASURE
  UPDATEDISPLAYLIST


  Don’t add components to the stage
   until you need them.
Initialization
Initialization

  1. ‘preInitialize’ dispatched
  2. createChildren(); called
  3. ‘initialize’ dispatched
  4. first validation pass occurs
  5. ‘creationComplete’ dispatched – component
    is fully commited, measured, and updated.
createChildren()
   MXML uses the createChildren() method to add children to
   containers
   Override this method to add children using AS
   • Follow MXML’s creation strategy: create, configure, attach

 override protected function createChildren():void
 {
 ...
 textField = new UITextField();

 textField.enabled = enabled;
 textField.ignorePadding = true;
 textField.addEventListener("textFieldStyleChange",
           textField_textFieldStyleChangeHandler);
   ...
       ...
   addChild(DisplayObject(textField));
 }
3 Important Rules
 1. Containers must contain only UIComponents
 2. UIComponents must go inside other
   UIComponents.
 3. UIComponents can contain anything (Sprites,
   Shapes, MovieClips, Video, etc).
Life
Invalidation / Validation cycle
   Flex imposes deferred validation on the
   Flash API
   • goal: defer screen updates until all
     properties have been set
   3 main method pairs to be aware of:
     • invalidateProperties() ->
       commitProperties()
     • invalidateSize() -> measure()
     • invalidateDisplayList() ->
       updateDisplayList()
Deferment
   Deferment is the central concept to
 understand in the component Life-cycle
   Use private variables and boolean flags to
 defer setting any render-related properties until
  the proper validation method
bad example

 public function set text(value:String):void
 {
   myLabel.text = value;

 }
good example
 private var _text:String = "";
 private var textChanged:Boolean = false;
 public function set text(value:String):void
 {

     _text = value;
     textChanged = true;
     invalidateProperties();
     invalidateSize();
     invalidateDisplayList();
 }

 override protected function commitProperties():void{
 {
        if(textChanged){
              myLabel.text = _text;
              textChanged = false;
        }
        super.commitProperties();
 }
Interaction
Interaction
   Flex is an Event Driven Interaction Model.
Death
Detachment
Detachment
   “Detachment” refers to the process of
 removing a child from the display list
   These children can be re-parented
 (brought back to life) or abandoned to die
   Abandoned components don’t get
 validation calls and aren’t drawn
   If an abandoned component has no more
 active references, it *should* be garbage-
 collected
Garbage Collection
Garbage Collection
   The process by which memory is returned
 to the system
   Only objects with no remaining references
 to them will be gc’d
 • Set references to detached children to
 “null” to mark them for GC
   Consider using weak references on event
 listeners
Conclusion
   Defer, Defer, DEFER!
   Use validation methods correctly
Conclusion
   Defer, Defer, DEFER!
   Use validation methods correctly
References
   Ely Greenfield: “Building a Flex Component”
   •http://www.onflex.org/ACDS/BuildingAFlexCo
   mponent.pdf
   RJ Owen: “Flex 3 Component Life-cycle”
   •http://rjria.blogspot.com/2009/04/cf-united-
   express-denver-presentation.html
   Mrinal Wadhwa: “Flex 4 Component
   Lifecycle”
   •http://weblog.mrinalwadhwa.com/2009/06/21/
   flex-4-component-lifecycle/
QA

More Related Content

What's hot

A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to ReactJean Carlo Emer
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC InternalsVitaly Baum
 
Introductionandgreetings
IntroductionandgreetingsIntroductionandgreetings
IntroductionandgreetingsPozz ZaRat
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentationThanh Tuong
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limitsDroidcon Berlin
 
JSON Part 3: Asynchronous Ajax & JQuery Deferred
JSON Part 3: Asynchronous Ajax & JQuery DeferredJSON Part 3: Asynchronous Ajax & JQuery Deferred
JSON Part 3: Asynchronous Ajax & JQuery DeferredJeff Fox
 
React.js enlightenment
React.js enlightenmentReact.js enlightenment
React.js enlightenmentArtur Szott
 
Riacon swiz
Riacon swizRiacon swiz
Riacon swizntunney
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Controlbhochhi
 
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Fabio Collini
 
Automated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xAutomated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xTatsuya Maki
 
Making React Native UI Components with Swift
Making React Native UI Components with SwiftMaking React Native UI Components with Swift
Making React Native UI Components with SwiftRay Deck
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testabilitydrewz lin
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 ThreadingDiego Grancini
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"IT Event
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!DataArt
 

What's hot (20)

A full introductory guide to React
A full introductory guide to ReactA full introductory guide to React
A full introductory guide to React
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC Internals
 
Introductionandgreetings
IntroductionandgreetingsIntroductionandgreetings
Introductionandgreetings
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limits
 
JSON Part 3: Asynchronous Ajax & JQuery Deferred
JSON Part 3: Asynchronous Ajax & JQuery DeferredJSON Part 3: Asynchronous Ajax & JQuery Deferred
JSON Part 3: Asynchronous Ajax & JQuery Deferred
 
React.js enlightenment
React.js enlightenmentReact.js enlightenment
React.js enlightenment
 
Riacon swiz
Riacon swizRiacon swiz
Riacon swiz
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2Intro to Retrofit 2 and RxJava2
Intro to Retrofit 2 and RxJava2
 
Easy Button
Easy ButtonEasy Button
Easy Button
 
I hate mocking
I hate mockingI hate mocking
I hate mocking
 
Automated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.xAutomated%20testing%20with%20Espresso2.x
Automated%20testing%20with%20Espresso2.x
 
Making React Native UI Components with Swift
Making React Native UI Components with SwiftMaking React Native UI Components with Swift
Making React Native UI Components with Swift
 
谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability谷歌 Scott-lessons learned in testability
谷歌 Scott-lessons learned in testability
 
Android App Development - 07 Threading
Android App Development - 07 ThreadingAndroid App Development - 07 Threading
Android App Development - 07 Threading
 
Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"Alexey Buzdin "Maslow's Pyramid of Android Testing"
Alexey Buzdin "Maslow's Pyramid of Android Testing"
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!
 

Viewers also liked

基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en增强 杜
 
杜增强 Flash移动开发优化技巧
杜增强 Flash移动开发优化技巧杜增强 Flash移动开发优化技巧
杜增强 Flash移动开发优化技巧增强 杜
 
优秀Flash产品演示与技术解析
优秀Flash产品演示与技术解析优秀Flash产品演示与技术解析
优秀Flash产品演示与技术解析增强 杜
 
杜增强 Flash移动项目展示
杜增强 Flash移动项目展示杜增强 Flash移动项目展示
杜增强 Flash移动项目展示增强 杜
 
iOS中Lua脚本的应用
iOS中Lua脚本的应用iOS中Lua脚本的应用
iOS中Lua脚本的应用Proteas Wang
 
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例Justin Lee
 
Objective C Tricks
Objective C TricksObjective C Tricks
Objective C TricksInova LLC
 

Viewers also liked (8)

基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
 
杜增强 Flash移动开发优化技巧
杜增强 Flash移动开发优化技巧杜增强 Flash移动开发优化技巧
杜增强 Flash移动开发优化技巧
 
优秀Flash产品演示与技术解析
优秀Flash产品演示与技术解析优秀Flash产品演示与技术解析
优秀Flash产品演示与技术解析
 
杜增强 Flash移动项目展示
杜增强 Flash移动项目展示杜增强 Flash移动项目展示
杜增强 Flash移动项目展示
 
iOS中Lua脚本的应用
iOS中Lua脚本的应用iOS中Lua脚本的应用
iOS中Lua脚本的应用
 
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
Objective C Tricks
Objective C TricksObjective C Tricks
Objective C Tricks
 

Similar to Flex Component Lifecycle Methods

Building Components In Flex3
Building Components In Flex3Building Components In Flex3
Building Components In Flex3Tikal Knowledge
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface ComponentsAhmad Hamid
 
Diving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleDiving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleEffectiveUI
 
Diving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleDiving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleEffective
 
Flex component lifecycle
Flex component lifecycleFlex component lifecycle
Flex component lifecycleYaniv Uriel
 
Invalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your CraniumInvalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your Craniumsakrirosenstrom
 
Diving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleDiving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleEffective
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4Naga Muruga
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy CodeNaresh Jain
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade ServerlessKatyShimizu
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade ServerlessKatyShimizu
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4Billie Berzinskas
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfStephieJohn
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testingpleeps
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answerskavinilavuG
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageabilityDaniel Fisher
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Watersmichael.labriola
 
Backbone to React. What it says about awesome UI Code.
Backbone to React. What it says about awesome UI Code.Backbone to React. What it says about awesome UI Code.
Backbone to React. What it says about awesome UI Code.Richard Powell
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingVisual Engineering
 

Similar to Flex Component Lifecycle Methods (20)

Building Components In Flex3
Building Components In Flex3Building Components In Flex3
Building Components In Flex3
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface Components
 
Diving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleDiving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life Cycle
 
Diving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleDiving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life Cycle
 
Flex component lifecycle
Flex component lifecycleFlex component lifecycle
Flex component lifecycle
 
Backbone.js
Backbone.jsBackbone.js
Backbone.js
 
Invalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your CraniumInvalidation Routines Pounded Into Your Cranium
Invalidation Routines Pounded Into Your Cranium
 
Diving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life CycleDiving Deep with the Flex Component Life Cycle
Diving Deep with the Flex Component Life Cycle
 
Behavioral pattern 4
Behavioral pattern 4Behavioral pattern 4
Behavioral pattern 4
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless[NDC 2019] Enterprise-Grade Serverless
[NDC 2019] Enterprise-Grade Serverless
 
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
[NDC 2019] Functions 2.0: Enterprise-Grade Serverless
 
Coldbox developer training – session 4
Coldbox developer training – session 4Coldbox developer training – session 4
Coldbox developer training – session 4
 
Fundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdfFundamental Concepts of React JS for Beginners.pdf
Fundamental Concepts of React JS for Beginners.pdf
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Selenium interview questions and answers
Selenium interview questions and answersSelenium interview questions and answers
Selenium interview questions and answers
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
 
Diving in the Flex Data Binding Waters
Diving in the Flex Data Binding WatersDiving in the Flex Data Binding Waters
Diving in the Flex Data Binding Waters
 
Backbone to React. What it says about awesome UI Code.
Backbone to React. What it says about awesome UI Code.Backbone to React. What it says about awesome UI Code.
Backbone to React. What it says about awesome UI Code.
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 

Recently uploaded

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Flex Component Lifecycle Methods

  • 1. Adobe Flex 3 Component Lifecycle Presented by Ethan Du(杜增强)
  • 2. Who am I ? Ethan Du – Senior Flex Architect @ 123Show – blog: http://www.duzengqiang.com
  • 3. Flex   What is Flex? • MXML • A set of components • The component lifecycle!
  • 4. Flex Component Lifecycle   What is it? • The way the framework interacts with every Flex component • A set of methods the framework calls to instantiate, control, and destroy components
  • 5. Phases of the Lifecycle   3 Main Phases:   BIRTH: • construction, configuration,attachment, initialization   LIFE: • invalidation, validation, interaction   DEATH: • detachment, garbage collection
  • 8. What is a constructor?   A function called to instantiate (create in memory) a new instance of a class
  • 9. How is a constructor invoked? Actionscript: var theLabel : Label = new Label(); MXML: <mx:Label id="theLabel"/>
  • 10. What does an ActionScript3 constructor look like? public function ComponentName() { super(); //blah blah blah }   No required arguments (if it will be used in MXML); zero, or all optional   Only one per class (no overloading!)   No return type   Must be public   Call super()…or the compiler will do it for you.
  • 11. What should a constructor do?   A good place to add event listeners to the object.   Not much. Since the component’s children have not yet been created, there’s not much that can be done.
  • 12. Don’t create or add children in the constructor   It’s best to delay the cost of createChildren calls for added children until it’s necessary
  • 14. Configuration   The process of assigning values to properties on objects   In MXML, properties are assigned in this phase, before components are attached or initialized <local:SampleChild property1="value"/>
  • 15. Configuration Optimization   To avoid performance bottlenecks, make your setters fast and defer any real work until validation   We’ll talk more about deferment in the validation / invalidation section
  • 17. What is attachment?   Adding a component to the display list (addChild, addChildAt, MXML declaration)
  • 18. Methods addingChild(child); $addChildAt(child, index); childAdded(child);
  • 19. Must know about attachment   The component lifecycle is stalled after configuration until attachment occurs.
  • 20. Consider this component: public class A extends UIComponent { public function A() { trace( "CONSTRUCTOR" ); super(); } override protected function createChildren() : void { trace( "CREATECHILDREN" ); super.createChildren(); } override protected function measure() : void { trace( "MEASURE" ); super.measure(); } override protected function updateDisplayList(width:Number, height:Number) : void { trace( "UPDATEDISPLAYLIST" ); super.updateDisplayList(width,height); } override protected function commitProperties():void { trace( "COMMITPROPERTIES" ); super.commitProperties(); } (It traces all of its methods.)
  • 21. And this application: <mx:Application ...> <mx:Script> <![CDATA[ override protected function createChildren() : void { super.createChildren(); var a : A = new A(); } ]]> </mx:Script> </mx:Application>
  • 22. Output: CONSTRUCTOR   Without attachment, the rest of the lifecycle doesn’t happen.
  • 23. But what about this application? <mx:Application ...> <mx:Script> <![CDATA[ override protected function createChildren() : void { super.createChildren(); var a : A = new A(); this.addChild( a ); } ]]> </mx:Script> </mx:Application>
  • 24. Output: CONSTRUCTOR CREATECHILDREN COMMITPROPERTIES MEASURE UPDATEDISPLAYLIST Don’t add components to the stage until you need them.
  • 26. Initialization 1. ‘preInitialize’ dispatched 2. createChildren(); called 3. ‘initialize’ dispatched 4. first validation pass occurs 5. ‘creationComplete’ dispatched – component is fully commited, measured, and updated.
  • 27. createChildren()   MXML uses the createChildren() method to add children to containers   Override this method to add children using AS • Follow MXML’s creation strategy: create, configure, attach override protected function createChildren():void { ... textField = new UITextField(); textField.enabled = enabled; textField.ignorePadding = true; textField.addEventListener("textFieldStyleChange", textField_textFieldStyleChangeHandler); ... ... addChild(DisplayObject(textField)); }
  • 28. 3 Important Rules 1. Containers must contain only UIComponents 2. UIComponents must go inside other UIComponents. 3. UIComponents can contain anything (Sprites, Shapes, MovieClips, Video, etc).
  • 29. Life
  • 30. Invalidation / Validation cycle   Flex imposes deferred validation on the Flash API • goal: defer screen updates until all properties have been set   3 main method pairs to be aware of: • invalidateProperties() -> commitProperties() • invalidateSize() -> measure() • invalidateDisplayList() -> updateDisplayList()
  • 31. Deferment   Deferment is the central concept to understand in the component Life-cycle   Use private variables and boolean flags to defer setting any render-related properties until the proper validation method
  • 32. bad example public function set text(value:String):void { myLabel.text = value; }
  • 33. good example private var _text:String = ""; private var textChanged:Boolean = false; public function set text(value:String):void { _text = value; textChanged = true; invalidateProperties(); invalidateSize(); invalidateDisplayList(); } override protected function commitProperties():void{ { if(textChanged){ myLabel.text = _text; textChanged = false; } super.commitProperties(); }
  • 35. Interaction   Flex is an Event Driven Interaction Model.
  • 36. Death
  • 38. Detachment   “Detachment” refers to the process of removing a child from the display list   These children can be re-parented (brought back to life) or abandoned to die   Abandoned components don’t get validation calls and aren’t drawn   If an abandoned component has no more active references, it *should* be garbage- collected
  • 40. Garbage Collection   The process by which memory is returned to the system   Only objects with no remaining references to them will be gc’d • Set references to detached children to “null” to mark them for GC   Consider using weak references on event listeners
  • 41. Conclusion   Defer, Defer, DEFER!   Use validation methods correctly
  • 42. Conclusion   Defer, Defer, DEFER!   Use validation methods correctly
  • 43. References   Ely Greenfield: “Building a Flex Component” •http://www.onflex.org/ACDS/BuildingAFlexCo mponent.pdf   RJ Owen: “Flex 3 Component Life-cycle” •http://rjria.blogspot.com/2009/04/cf-united- express-denver-presentation.html   Mrinal Wadhwa: “Flex 4 Component Lifecycle” •http://weblog.mrinalwadhwa.com/2009/06/21/ flex-4-component-lifecycle/
  • 44. QA