Flex 4 Component Development

28
Component Development in the Flex 4 Model Michael Labriola Digital Primates Twitter: mlabriola

description

Presentation at Flash Camp Chicago regarding Flex 4 component changes

Transcript of Flex 4 Component Development

Page 1: Flex 4 Component Development

Component Development in the Flex 4 Model

Michael LabriolaDigital Primates

Twitter: mlabriola

Page 2: Flex 4 Component Development

Who are you?Michael LabriolaSenior Consultant at Digital Primates

Flex GeekTeam MentorProject Lead for FlexUnit 4

Page 3: Flex 4 Component Development

What is this session about?

Component Development

Components are the root of everything in Flex. Know how to make them work and know Flex

Page 4: Flex 4 Component Development

What are we doing?

• Implement and create a layout class• Implement and create a skin• Create a custom component using the Flex

4 component framework

Page 5: Flex 4 Component Development

What are Flex Components?

Page 6: Flex 4 Component Development

Why do you care?

• Flex is a component framework• Everything is a component in Flex• Understand components and understand

Flex• When you want something new, that does

something different, you want to create a component

Page 7: Flex 4 Component Development

Important things to understand

• In Flex 4 components are composed of two pieces– The form– The function

Page 8: Flex 4 Component Development

The Function

• What the component does• How it does it• When it does it• Defines what the component is– Buttons are about being clicked– List is about selection and virtualization

Page 9: Flex 4 Component Development

The Form

A list doesn’t have to be horizontal or vertical to be a list

Buttons don’t need to be rectangles

What makes a list a list? What makes a button a button?

Page 10: Flex 4 Component Development

Separation

Separating these pieces favors composition over inheritance

By separating form and function we gain and we lose.

Page 11: Flex 4 Component Development

We Gain

The capability of having one set of functionality look many different ways

Back to the list example, a list can be horizontal, vertical, circular, etc. but we only have to maintain the code in one list class

Page 12: Flex 4 Component Development

We Lose

We lose a lot of dead weight

We lose a lot of extra classes

Example of layout objects embedded in a class

Page 13: Flex 4 Component Development

There are two types of UI Components in Flex

• Controls– Interact with a user– Present data– Accept gestures

• Containers– Hold other containers and controls– Control positioning of children

Page 14: Flex 4 Component Development

On the topic of losing weight

• There are two types of things in the Flex world, those that can be skinned and those that cannot– Roughly corresponding to those that have their

own visual appearance and those that simply influence the visualization of others

• Why? Because we don’t want to burden everything in the world with functionality it doesn’t need

Page 15: Flex 4 Component Development

Groups are the Base Type of Container

• Groups don’t have a visual identity of their own

• Groups can accept a layout object to handle the layout of children

Page 16: Flex 4 Component Development

Layout TypesLayout types built into flex

BasicLayoutHorizontalLayoutVerticalLayout

The important part about this is creating your own layouts

Circle LayoutAdvanced Circle Layout

Page 17: Flex 4 Component Development

Create a Circle Layout

Page 18: Flex 4 Component Development

Controls and Some Containers can be Skinned

Controls can also have their visual appearance modified and quite easily by skinning

Page 19: Flex 4 Component Development

SkinsSkins are classes defined in MXML

They are based on the Skin class

They are applied to components usingThe skinClassOr by CSS

Page 20: Flex 4 Component Development

Definitions• Think about the list class• No visual elements can exist inside the list

or it reduces skin-ability• All visuals exist in the skin• That means the component provides the

functionality and controls aspects of the skin

• That could get ugly

Page 21: Flex 4 Component Development

Contracts• That means we must have some sort of

contract between a skin and a component.• This contract defines the minimum things

that must be present inside of the skin to be considered valid

• This contract is fulfilled in two ways

Page 22: Flex 4 Component Development

Components• Declare skin parts (required or not)• Declare skin states• HELP!

Page 23: Flex 4 Component Development

Skins• Specify a HostComponent

<fx:Metadata> [HostComponent("spark.components.Button")]</fx:Metadata>

• Declare states<s:states> <s:State name="up" /> <s:State name="over" /></s:states>

• Establish visuals

Page 24: Flex 4 Component Development

Visuals

• What type of visuals?

Page 25: Flex 4 Component Development

CODE

Page 26: Flex 4 Component Development

Q & A

Seriously? You must have some questions by now?

Page 27: Flex 4 Component Development

Play and Vote

Take a look at the latest beta bits:

http://labs.adobe.com/technologies/flashbuilder4/

Page 28: Flex 4 Component Development

ResourcesLabriola’s Bloghttp://blogs.digitalprimates.net/codeSlinger/

Tapper’s Bloghttp://blogs.digitalprimates.net/jefftapper/

Follow us on twittermlabriola and jefftapper