Term Paper of Component Based Software
Term Paper of Component Based Software
ACKNOWLEDGEMENT
A very big thanks to my teacher Preeti Sikka Madan,who taught me how to work for this term paper.She was very helpful,as she cleared all the concepts of a term paper to me.A special thanks to my colleages who helped me out in doing hard work in making this term paper,without their support this couldnt be possible.
What is it?
Sequence of steps that occur when you create a component object from a component class. As part of this process, Flex automatically calls component methods, dispatches events, and makes the component visible.
Creation
Construction Configuration Attachment Initialization
Life
Invalidation Validation
Creation Construction
Purpose
Create an instance of a component class Configure the object by setting its initial properties
Examples
In Actionscript:
var b:Button = new Button(); b.label = test; b.addEventListener(MouseEvent.CLICK, onClick);
Creation Configuration
In MXML
Purpose
Creation Configuration
Creation Configuration
public function set label (value:String):void { if (_label != value) { _label = value; } }
Creation Configuration
_labelChanged = true; } }
public function set label (value:String):void { if (_label != value) { _label = value; _labelChanged = true; invalidateProperties(); invalidateSize(); invalidateDisplayList();
Creation Configuration
} }
Creation Configuration
} }
Creation Attachment
Purpose
Attach the component to the display list.
Component life-cycle is stalled after configuration until attachment occurs In Actionscript: panel.addChild(button); In MXML:
Creation
Don't need to do anything, the child is automatically added according to how it is nested. <mx:Panel
id=panel > <mx:Button id=button /> </mx:Panel>
Initialization
Creation
Component is in a very raw state. Its children have not yet been added (including internal children) Use this event in rare circumstances (set the properties on a parent before the children are created)
override this method from UIComponent Add child components that make up your custom component Construct component, set properties, add to display list
Creation Initialization
Creation
If the parent is also being initialized, its initialize event is dispatched when all of its children are added.
Life Invalidation
Deferred Validation
Flex uses a deferred validation for rendering components in their various states Central concept in the component life-cycle
Life
Use private variables and boolean flags to defer setting any render-related properties until the proper validation method is reached
Invalidation
Deferred Validation
3 methods that trigger validation methods
Life Validation
Purpose
Apply the changes deferred until validation
Life
commitProperties() measure() updateDisplayList()
Life Validation
commitProperties()
Purpose
Commit any changes to component properties Synchronize changes to occur at the same time or ensure that they are set in a specific order When is it called? Immediately after the initialize event during component creation Whenever invalidateProperties() is called
Life Validation
called
before
measure()
or
This allows you to set property values that influence size or position
commitProperties()
Example
Life Validation
measure()
Purpose
Calculate the component's preferred width and height and its preferred minimum width and height When is it called? After commitProperties() during initialization When the invalidateSize() method is called NOTE: measure() will never be called if the component is given an explicit width or height What is its phase order? After commitProperties() and before updateDisplayList()
Life Validation
measure()
Caveats
Only 4 properties should normally be set in measure()
measuredHeight The default height of the component measuredWidth The default width of the component measuredMinHeight The default minimum height of the component measuredMinWidth
Life Validation
and child
measure() Example
Life Validation
updateDisplayList()
Purpose
To position and size children Allow use of the Drawing API to draw on the component After measure() during the initialization process When invalidateDisplayList() is called What is it's After measure()
When is it called?
order?
Life Validation
updateDisplayList()
Caveats
Position children using move(x, y), size them using setActualSize(width, height) instead of using the x, y, width, height properties
Adobe recommends these methods because they work better with Container layouts. These methods are said to be quirky at times, so if they don't work for some reason just set the properties manually.
updateDisplayList()
Life Validation
unscaledWidth, unscaledHeight
Arguments for updateDisplayList() Indicate the width and height of the component as dictated by its parent. They do not take scaleX and scaleY properties into account, so you will have to calculate scaling manually if needs be.
Life Validation
Use this event for actions that must be performed each time a component's characteristics change, not just when it is created.
updateDisplayList()
Example
Reference
http://www.iamdeepa.com/ http://opensource.adobe.com/wiki/display/flexsdk/Gumbo http://opensource.adobe.com/wiki/display/flexsdk/Gumbo+Component+Architecture