Tuesday, November 18, 2008

Deep Dive into the Flex 3 Framework

A deep dive particularly into data binding, styles, collections and the system manager.



Data binding
Mark object and properties as bindable
In the background, events are wired to update the object when the value object changes
In MXML, it will be bindable if it has the id set
Two formats:
[Bindable]
[Bindable(event=”eventtype”)]
If not specified, the event type is PropertyChangedEvent
More efficient to use custom event types, but you have to dispatch it yourself
You can bind a function, but you have to create a custom event and dispatch it yourself
If bound, the function is recalled any time any of the bound arguments to it changes
You can bind to expressions, and you can have chained bindings
If you have a lot of bindable properties, the custom event types ensure that the object only gets the messages it cares about

Styles
Styles are inheritable
StyleManger class manages this
Managed through proto-chaining
getStyle (cheap) / setStyle (expensive)
getStyleDeclaration/setStyleDeclaration (used to manipulate styles on the fly)
clearStyleDeclaration
registerColorName (used to assign aliases to hexadecimal color values, e.g., “red”)
load styles from SWF file at runtime

Collections
Used to get data in a variety of formats into a variety of view controls
Provide sort, filter operations
IList (list) / ICollectionView (hierarchical)
Sort < - takes a sortObject
FilterFunction
Contains
CreateCursor
Abstracts the data format
Use getitemat rather that [] because of Flash Player bug
Set sort objects (a series of sortFields) and then call refresh
Call validateNow after changing dataProvider if you need to work with data right away
This is an expensive operation
Mark as bindable and call itemchanged

SystemManager
Owns the root of the SWF
First class instantiated
SWF compiled by Flex is 2 frame

Frame 1
System Manager
Preloader
DownloadProgressBar
Helper Classes

Frame 2
Flex Framework
Application Code
Assets
Runtime Shared Libraries (RSL)

System Manager
Browser resize events
Detects if assets are embedded
Overload preloader
Get reference to root and manipulate

No comments: